瑞士乒乓球联赛赛程系统

问题描述 投票:0回答:1

瑞士计划。帮助!请

我正在计划今年安排 8 个展示会。我有每个展示的数据框,其中包含每个玩家来自的排名和会议。每个展示柜都有不同数量的注册玩家,但玩家数量始终不同。前任。 48、20名球员。可能有一些玩家参加多个展示会或全部 8 个。

排名永远不会改变。它们是在年初设定的。

每个展示会分为 3 轮,所有玩家每轮必须玩一场游戏。球员在一年中不能多次比赛,也不能与同一联盟的其他球员比赛。选手的比赛按照相似的排名来决定。

我一直在尝试使用瑞士系统在Python中安排比赛,我能够生成结果,但它并不一致,因为并非所有对手在每轮中都匹配。我相信这是因为我们有一个额外的限制,即“会议”,而在常规的瑞士系统中,它仅受“等级”的限制。该系统必须受到“级别”和“会议”的约束。

有人对我可以使用的任何软件包或算法类型有任何建议吗?或者如果您认为有更好的方法来解决这个问题。

谢谢!!!

++++ 编辑++++

好吧,说实话,我不确定问题出在哪里,所以我只想包括第一部分:

这就是我所做的:

class Player:
     def __init__(self, name, rating, area):
         self.name = name
         self.rating = rating
         self.area = area
         self.games_played = 0
def optimize_pairings(players, pairings_history, round_num):
     # Ensure players list contains only Player objects
     if not all(isinstance(player, Player) for player in players):
         raise ValueError("Invalid player objects in the players list.")

     # Create a binary variable for each pair of players
     pair_vars = pulp.LpVariable.dicts("Pair", ((p1, p2) for p1 in players for p2 in players if p1 != p2), cat='Binary')

     # Create a PuLP minimization problem
     prob = pulp.LpProblem("Pairing Optimization", pulp.LpMinimize)

     # Objective: minimize the total rating difference between paired players
     prob += pulp.lpSum(pair_vars[(p1, p2)] * abs(p1.rating - p2.rating) for p1 in players for p2 in players if p1 != p2)

     # Add constraints
     for p1 in players:
         prob += pulp.lpSum(pair_vars[(p1, p2)] for p2 in players if p1 != p2) == 1  # Each player is paired with exactly one opponent

     for p1 in players:
         for p2 in players:
             if p1 != p2:
                 prob += pair_vars[(p1, p2)] + pair_vars[(p2, p1)] <= 1  # No rematches between tournaments

     for p1 in players:
         for p2 in players:
             if p1 != p2:
                 if p1.area == p2.area:
                    prob += pair_vars[(p1, p2)] == 0  # No player can play an opponent from the same conference

     # Exclude pairings already used in previous tournaments
     for (p1, p2) in pair_vars.keys():
         if (p1, p2) in pairings_history or (p2, p1) in pairings_history:
             prob += pair_vars[(p1, p2)] == 0

     # Solve the ILP problem
     prob.solve()

     # Extract pairings from the solution
     paired_players = [(p1, p2) for (p1, p2), var in pair_vars.items() if pulp.value(var) == 1]

     # Update pairings history for the current round
     pairings_history.update({(p1, p2) for (p1, p2) in paired_players})

     return paired_players

这也是结果/数据示例的链接。

python query-optimization scheduler scheduling sports-league-scheduling-problem
1个回答
0
投票

您应该使用循环系统而不是瑞士系统。对于未注册参加某些锦标赛的玩家,您可以享受再见周。

© www.soinside.com 2019 - 2024. All rights reserved.