예제 #1
0
 private function makeMatchSchedule(Tournament $tournament, MatchPlan $match)
 {
     // for QMatchPlan, group and team are undefined - use classification and litra instead
     if ($match instanceof QMatchPlan) {
         /* @var $match QMatchPlan */
         $ms = new QMatchSchedule();
         $ms->setTournament($tournament);
         $ms->setCategory($this->em->merge($match->getCategory()));
         $ms->setBranch('');
         $ms->setClassification($match->getClassification());
         $ms->setLitra($match->getLitra());
         $hr = new QMatchScheduleRelation();
         $hr->setBranch($match->getRelA()->getBranch());
         $hr->setClassification($match->getRelA()->getClassification());
         $hr->setLitra($match->getRelA()->getLitra());
         $hr->setRank($match->getRelA()->getRank());
         $hr->setAwayteam(false);
         $ms->addQMatchRelation($hr);
         $ar = new QMatchScheduleRelation();
         $ar->setBranch($match->getRelB()->getBranch());
         $ar->setClassification($match->getRelB()->getClassification());
         $ar->setLitra($match->getRelB()->getLitra());
         $ar->setRank($match->getRelB()->getRank());
         $ar->setAwayteam(true);
         $ms->addQMatchRelation($ar);
     } else {
         $ms = new MatchSchedule();
         $ms->setTournament($tournament);
         $ms->setGroup($this->em->merge($match->getGroup()));
         $hr = new MatchScheduleRelation();
         $hr->setTeam($this->em->merge($match->getTeamA()));
         $hr->setAwayteam(false);
         $ms->addMatchRelation($hr);
         $ar = new MatchScheduleRelation();
         $ar->setTeam($this->em->merge($match->getTeamB()));
         $ar->setAwayteam(true);
         $ms->addMatchRelation($ar);
     }
     return $ms;
 }
예제 #2
0
 /**
  * Replace match schedule with other matches with same match time
  * @param PlanningResults $result
  * @param MatchPlan $match
  * @return MatchPlan|null
  */
 private function replanMatch_2run(PlanningResults $result, MatchPlan $match)
 {
     $result->mark(function (PlaygroundAttribute $ats1, PlaygroundAttribute $ats2) {
         $test = $ats2->getTimeleft() - $ats1->getTimeleft();
         return min(1, max(-1, $test));
     });
     while ($pa = $result->cycleTimeslot()) {
         /* Find a candidate for replacement */
         $matchlist = $pa->getMatchlist();
         /* @var $replan_match MatchPlan */
         foreach ($matchlist as $idx => $replan_match) {
             /* Both teams must be allowed to play now */
             if ($replan_match->getCategory()->getMatchtime() == $match->getCategory()->getMatchtime() && $result->getTeamCheck()->isCapacity($match, $replan_match->getSchedule(), $replan_match->getPlayground(), $pa->getTimeslot())) {
                 $match->setDate($replan_match->getDate());
                 $match->setTime($replan_match->getTime());
                 $match->setPlayground($replan_match->getPlayground());
                 $matchlist[$idx] = $match;
                 $pa->setMatchlist($matchlist);
                 $result->getTeamCheck()->reserveCapacity($match, $pa->getTimeslot());
                 $result->getTeamCheck()->freeCapacity($replan_match, $pa->getTimeslot());
                 $result->rewind();
                 return $replan_match;
             }
         }
     }
     return null;
 }
예제 #3
0
 private function prepareUnassignedMatch(MatchPlan $match, $msid, &$ts, &$catcnt)
 {
     $match->setTime('');
     $match->setPlayground(null);
     $match->setDate('');
     $match->setFixed(false);
     $category = $match->getCategory();
     if (isset($catcnt[$category->getId()])) {
         $catcnt[$category->getId()]['matchcount']++;
     } else {
         $catcnt[$category->getId()] = array('category' => $category, 'matchcount' => 1);
     }
     $malts = array();
     /* @var $ma MatchAlternative */
     foreach ($this->logic->listMatchAlternatives($msid) as $ma) {
         $pattr = $ma->getPlaygroundAttribute();
         if (isset($ts[$pattr->getId()])) {
             $malts[] = $ts[$pattr->getId()];
         }
     }
     usort($malts, function (PA $ats1, PA $ats2) {
         $p1 = $ats2->getTimeleft() - $ats1->getTimeleft();
         $p2 = $ats1->getPlayground()->getNo() - $ats2->getPlayground()->getNo();
         $p3 = $ats1->getTimeslot()->getId() - $ats2->getTimeslot()->getId();
         $test = min(1, max(-1, $p1)) * 4 + min(1, max(-1, $p2)) * 2 + min(1, max(-1, $p3));
         return min(1, max(-1, $test));
     });
     $alternatives = array();
     /* @var $alt PA */
     foreach ($malts as $alt) {
         $alternatives[date_format($alt->getSchedule(), "Y/m/d")][] = $alt;
     }
     return array('id' => $msid, 'match' => $match, 'alternatives' => $alternatives);
 }