算法:从一组游戏中选择成对的球队
我正在尝试为体育联盟创建一个调度程序,我想将球队分组,以便每个球队每组进行一场比赛。我认为我想做的事情是计算机科学中现有的问题,但我不知道它叫什么,而且我很难找到有关它的信息。无论哪种方式,情况如下:
假设我有一组团队 A = {1,2,3,...,n}
和一组这些团队对 B = {(1,2),(1,3),(2,4),(6,9),...}
。 B 并不拥有 A 中所有可能的球队组合。假设 A 有偶数个球队。我的程序正在尝试创建 B 的子集(我们称其为 S 子集),以便 A 中的每个团队在 S 中恰好出现一次。它通过将这些对从 B 移动到 S 来实现这一点,一次一个。假设它已经将几对放入 S 中。如何确定在当前情况下是否可以成功创建 S?
示例:
A = {1,2,3,4}, B = {(1,2), (1,3), (1,4), (3,4)}
If after one move, S = {(1,2)}, then it can be completed by moving (3,4).
If after one move, S = {(1,3)}, then it cannot be completed.
更新: 该算法将是我在日程生成器中使用的启发式算法之一。目标是隐式地将赛程分成“波”,其中每支球队每波有一场比赛。假设我有 16 支球队的池子,每支球队将与池子里的其他球队进行 5 场比赛。理想的赛程表应确保在每支球队都至少打一场比赛之前,没有球队进行第二场比赛。调度程序一次选择一场比赛并为其分配一个日期。因此,我们的想法是让调度程序跟踪此“波”中安排的比赛,并且永远不要选择会阻止每个团队在当前波中只玩一次的比赛。调度程序还使用了许多其他启发式方法,因此我无法明确对游戏进行排序并使其按顺序进行。
如果这不清楚或不是很严格,我很抱歉。请随时要求澄清,我会尽力进一步解释。
I'm trying to create a scheduler for a sports league and I'd like to schedule the teams in groups so every team gets one game per group. I think the thing I'm trying to do is an existing problem in computer science, but I don't know what it's called and I'm having trouble finding information about it. Either way, here's the situation:
Let's say I have a set of teams A = {1,2,3,...,n}
and a set of pairs of those teams B = {(1,2), (1,3), (2,4), (6,9),...}
. B does not have every possible combination of teams from A. Assume that A has an even number of teams. My program is trying to create a subset of B (lets call that subset S) such that every team from A appears in S exactly once. It does this by moving the pairs from B to S, one at a time. Let's say that it has already placed several pairs into S. How can I find out whether it is possible to successfully create S given the current situation?
Example:
A = {1,2,3,4}, B = {(1,2), (1,3), (1,4), (3,4)}
If after one move, S = {(1,2)}, then it can be completed by moving (3,4).
If after one move, S = {(1,3)}, then it cannot be completed.
Update:
This algorithm will be one of the heuristics I use in my schedule generator. The goal is to implicitly split the schedule into "waves" where each team has one game per wave. So let's say that I have a pool of 16 teams and each team will have 5 games against other teams in the pool. An ideal schedule would make sure that no team has their second game before every team has had at least one game. The scheduler picks games one at a time and assigns them a date. So the idea is to have the scheduler keep track of the games scheduled in this "wave" and to never pick a game that would prevent each team from playing exactly once in the current wave. The scheduler also uses a bunch of other heuristics, so I can't explicitly order the games and have it go in order.
I'm sorry if this is unclear or not very rigorous. Feel free to ask for clarification and I'll do my best to explain further.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是图论中的最大匹配问题。有一些已知的算法可以解决这个问题。
在您的问题图中 G(V - 顶点集,E - 边集),其中 V = A,E = B。还要向图中添加相反的边。每条边的权重为1。
我建议您使用匈牙利算法< /a> 用于二分图和 Edmond 的算法供其他人使用。
It's Maximum matching problem in graph theory. There are some known algorithms to solve it.
In your problem graph G (V - set of vertexes, E - set of edges) where V = A, E = B. Also add opposite edges to graph. Weight of each edge is 1.
I suggest you to use Hungarian Algorithm for bipartite graphs and Edmond's algorithm for others.
做出一些假设来澄清下面的内容非常重要。
首先,假设我们正在讨论乒乓球联赛中的 16 支球队,并且您希望制定一个赛程表,其中所有球队都进行五场比赛,并且不重复任何对手。
第二,您希望所有 16 支球队在任何球队再次比赛之前完成每盘比赛。
第三,您希望所有球队都分布在 8 张桌子上比赛,而不是总是安排一支球队在同一张桌子上比赛。
如果我的假设正确,那么您需要的是平衡的 16 支球队循环赛赛程中的前 5 个“组”(您将每组称为一波)比赛。这将为您提供锦标赛类型的团队比赛,其中每支球队与 5 支不同的球队进行 5 场比赛。每盘(或波)有 8 场比赛,并且没有球队总是被安排在同一张桌子上比赛,并且在所有球队都打完当前盘之前,球队不会进行下一场比赛。
以下是我为您创建的 16 支球队的平衡赛程表中的前 5 个“组”。一探究竟。
It is important to make some assumptions to clarify what is presented below.
First, assume we are talking about 16 teams in a table tennis league, and you want a schedule where all teams play five games without duplicating any opponents.
Second, you want all 16 teams to complete playing in each set before any team plays again.
Third, you want all teams to be distributed to play on the 8 tables and not have one team always scheduled to play at the same table.
If I got the assumptions correct, what you need is the first 5 "sets" (you call each set a wave) of games from a balanced 16 team round robin schedule. This would give you a tournament type of team match-ups where each team plays 5 games against 5 different teams. Each set (or wave) has 8 games and no team is always scheduled to play on the same table, and teams do not play games in their next set until all teams have finished playing the current set.
Below are the first 5 "sets" from a balanced 16 team schedule I created for you. Check it out.