Example #1
0
 /**
  * Replace match schedule with other matches with same team
  * @param PlanningResults $result
  * @param MatchPlan $match
  * @return MatchPlan|null
  */
 private function findAngel(PlanningResults $result, MatchPlan $match)
 {
     $result->mark();
     while ($pa = $result->cycleTimeslot()) {
         /* Find a candidate for replacement */
         $matchlist = $pa->getMatchlist();
         /* @var $replan_match MatchPlan */
         foreach ($matchlist as $idx => $replan_match) {
             // search for matches that are not yet tried to swap and share the same team
             if (!$replan_match->isFixed() && $this->teamsMatch($match, $replan_match)) {
                 // another match with same team was found - try release the match schedule and see if that makes some space
                 $result->getTeamCheck()->freeCapacity($replan_match, $pa->getTimeslot());
                 // does this make room for assignment?
                 if ($result->getTeamCheck()->isCapacity($match, $replan_match->getSchedule(), $replan_match->getPlayground(), $pa->getTimeslot())) {
                     // yes - try this schedule and see if puzzle is solved...
                     $match->setDate($replan_match->getDate());
                     $match->setTime($replan_match->getTime());
                     $match->setPlayground($replan_match->getPlayground());
                     $match->setFixed(true);
                     $matchlist[$idx] = $match;
                     $pa->setMatchlist($matchlist);
                     $result->getTeamCheck()->reserveCapacity($match, $pa->getTimeslot());
                     $result->rewind();
                     return $replan_match;
                 } else {
                     // nope - redo the release and try another match schedule
                     $result->getTeamCheck()->reserveCapacity($replan_match, $pa->getTimeslot());
                 }
             }
         }
     }
     return null;
 }
 /**
  * Replace match schedule with other matches with same match time
  * @param PlanningResults $result
  * @param QMatchPlan $match
  * @return MatchPlan|null
  */
 private function replanMatch_2run(PlanningResults $result, QMatchPlan $match)
 {
     $result->mark();
     while ($pa = $result->cycleTimeslot()) {
         /* Find a candidate for replacement */
         $matchlist = $pa->getMatchlist();
         /* @var $replan_match QMatchPlan */
         foreach ($matchlist as $idx => $replan_match) {
             /* Both teams must be allowed to play now */
             if ($replan_match->getCategory()->getMatchtime() == $match->getCategory()->getMatchtime() && $result->isQScheduleAvailable($match, $replan_match->getSchedule(), $pa->getTimeslot())) {
                 $match->setDate($replan_match->getDate());
                 $match->setTime($replan_match->getTime());
                 $match->setPlayground($replan_match->getPlayground());
                 $matchlist[$idx] = $match;
                 $pa->setMatchlist($matchlist);
                 $result->setQSchedule($match, $replan_match->getSchedule());
                 $result->resetQSchedule($replan_match);
                 $result->rewind();
                 return $replan_match;
             }
         }
     }
     return null;
 }