没有 RoundRobin 的联赛调度
League Scheduling without RoundRobin
目前我正在寻找一个专门针对我的问题的术语:
我创建了超过 4 支球队的联盟
联赛持续 3 轮(数字为简单起见)
比赛将从尚未交手过的球队中随机分配。
我正在努力获取我当前的代码 运行 每个边缘案例所以我想查找 'standard' 为此类案例开发的算法,但我想不出我是寻找。
一个时间表示例是:
TeamA: C,E,B
TeamB: F,H,A
TeamC: A,D,H
TeamD: G,C,F
TeamE: H,A,G
TeamF: B,G,D
TeamG: D,F,G
TeamH: E,B,C
在这方面我找不到任何东西,因为它似乎是非常非常不可能在 leagues/tournaments 中使用的东西 - 但这是我的要求。
这是我当前创建一轮的代码。可能会发生,此代码不会在第 3 轮中为每支球队提供一个对手,因为他们可能的对手在本轮已经分配了一场比赛(测试了 6 支球队,可能在第 3 轮中发生)
public function CalculateDivision()
{
$teams = Division::find(1)->teams()->get();
$diffs = array();
foreach($teams as $team)
{
//Get possible Opponents
$opp = Division::find(1)->teams()->where('id','!=',$team->id)->lists('id');
$matches = $team->matches()->get();
$plyd = array();
foreach($matches as $match)
{
//Find Opponents a team already has played against
$plyd[] = $match->teams()->where('id','!=',$team->id)->pluck('id');
}
//Substract Opponents already played against from possible Opponents
$TBP = array_diff($opp,$plyd);
$diffs[$team->id] = $TBP;
}
//Order By Least possible Opponents possible
asort($diffs);
$this->CalculateMatches($diffs);
}
private function CalculateMatches($teams)
{
//$teams equals $teams[teamID] = [Opponent1ID,Opponent2ID ...]
$setTeams = array();
foreach($teams as $key => $team)
{
//If Team hasn't already a new matchup find opponent from their possible opponent array
if(!in_array($key,$setTeams))
{
shuffle($team);
foreach($team as $opponent)
{
//If possible opponent hasn't already a matchup create one, add both teams to 'has already a match' so the loop doesn't evaluate them again
if(!in_array($opponent,$setTeams))
{
$this->CreateMatch($key,$opponent);
$setTeams[] = $key;
$setTeams[] = $opponent;
break;
}
}
}
}
}
如有任何帮助,我将不胜感激google
A Swiss system "is a non-eliminating tournament format which features a predetermined number of rounds of competition, but considerably fewer than in a round-robin tournament".
广泛应用于国际象棋等游戏中。根据维基百科:
Swiss systems are commonly used in chess, bridge, eSports, Morabaraba, Scrabble, Backgammon, squash, Pétanque (boules), Quiz bowl, Magic: The Gathering, Policy Debate, Warhammer, eight-ball, Reversi, Dominion, Pokémon TCG, Yu-Gi-Oh, Blood Bowl, Guild Wars 2, Star Wars: X-Wing Miniatures Game, Path of Exile and Android: Netrunner.
它可能符合您的需要,您可以找到一些现成的实现。
目前我正在寻找一个专门针对我的问题的术语:
我创建了超过 4 支球队的联盟 联赛持续 3 轮(数字为简单起见) 比赛将从尚未交手过的球队中随机分配。
我正在努力获取我当前的代码 运行 每个边缘案例所以我想查找 'standard' 为此类案例开发的算法,但我想不出我是寻找。
一个时间表示例是:
TeamA: C,E,B
TeamB: F,H,A
TeamC: A,D,H
TeamD: G,C,F
TeamE: H,A,G
TeamF: B,G,D
TeamG: D,F,G
TeamH: E,B,C
在这方面我找不到任何东西,因为它似乎是非常非常不可能在 leagues/tournaments 中使用的东西 - 但这是我的要求。
这是我当前创建一轮的代码。可能会发生,此代码不会在第 3 轮中为每支球队提供一个对手,因为他们可能的对手在本轮已经分配了一场比赛(测试了 6 支球队,可能在第 3 轮中发生)
public function CalculateDivision()
{
$teams = Division::find(1)->teams()->get();
$diffs = array();
foreach($teams as $team)
{
//Get possible Opponents
$opp = Division::find(1)->teams()->where('id','!=',$team->id)->lists('id');
$matches = $team->matches()->get();
$plyd = array();
foreach($matches as $match)
{
//Find Opponents a team already has played against
$plyd[] = $match->teams()->where('id','!=',$team->id)->pluck('id');
}
//Substract Opponents already played against from possible Opponents
$TBP = array_diff($opp,$plyd);
$diffs[$team->id] = $TBP;
}
//Order By Least possible Opponents possible
asort($diffs);
$this->CalculateMatches($diffs);
}
private function CalculateMatches($teams)
{
//$teams equals $teams[teamID] = [Opponent1ID,Opponent2ID ...]
$setTeams = array();
foreach($teams as $key => $team)
{
//If Team hasn't already a new matchup find opponent from their possible opponent array
if(!in_array($key,$setTeams))
{
shuffle($team);
foreach($team as $opponent)
{
//If possible opponent hasn't already a matchup create one, add both teams to 'has already a match' so the loop doesn't evaluate them again
if(!in_array($opponent,$setTeams))
{
$this->CreateMatch($key,$opponent);
$setTeams[] = $key;
$setTeams[] = $opponent;
break;
}
}
}
}
}
如有任何帮助,我将不胜感激google
A Swiss system "is a non-eliminating tournament format which features a predetermined number of rounds of competition, but considerably fewer than in a round-robin tournament".
广泛应用于国际象棋等游戏中。根据维基百科:
Swiss systems are commonly used in chess, bridge, eSports, Morabaraba, Scrabble, Backgammon, squash, Pétanque (boules), Quiz bowl, Magic: The Gathering, Policy Debate, Warhammer, eight-ball, Reversi, Dominion, Pokémon TCG, Yu-Gi-Oh, Blood Bowl, Guild Wars 2, Star Wars: X-Wing Miniatures Game, Path of Exile and Android: Netrunner.
它可能符合您的需要,您可以找到一些现成的实现。