【问题标题】:Optimize a Combinations of Combinations优化组合的组合
【发布时间】:2019-08-16 19:27:16
【问题描述】:

我需要关于这在 Python 中是否可行以及如何实现的指导。我正在尝试优化游戏中的玩家阵容。根据对手的技能,每个玩家都有一个与之相关的整数值。我想找到一种方法来为 2v2 游戏中的玩家找到 2 种不同的最佳匹配,以最大化他们的价值。例如:

这代表了玩家对抗不同对手等级的价值观。

Opponent Level     Elite    Middle     Low
Player Name         
A                   4.2      -3.7      2.6
B                  -5.8      -4.3      1.2
C                   0.6       2.8      9.2      
D                  -7.0       2.3      1.2   
E                   8.0       5.5     -0.6
F                   3.3       4.4      6.6

我希望实现的是这样的:

Match Ups Version 1:
Round 1
Elite   Player A and Player B
Middle  Player C and Player D
Low     Player E and Player F
Round 2:
Elite   Player F and Player C
Middle  Player E and Player B
Low     Player A and Player D

比赛在哪里使他们的价值之和最大化。唯一的限制是一个玩家每轮只能使用一次,并且不能在下一轮对抗相同级别的对手。

我在理论上如何在 Python 中做到这一点真的很挣扎,所以任何指导都将不胜感激!

【问题讨论】:

    标签: python-3.x combinations mathematical-optimization


    【解决方案1】:

    我不太明白

    比赛在哪里使他们的价值之和最大化。

    但我会开始组合,然后你对每个排列进行数学运算以得出每一轮。

    from itertools import combinations
    
    df = read_clipboard()
    df
    

    输出[65]:

       Elite  Middle  Low
    0
    A    4.2    -3.7  2.6
    B   -5.8    -4.3  1.2
    C    0.6     2.8  9.2
    D   -7.0     2.3  1.2
    E    8.0     5.5 -0.6
    F    3.3     4.4  6.6
    

    设置后

    # Get all the combinations of the players (limit it to two players)
    matches = combinations(df.index, 2) 
    

    然后通过元组计算值。 (这里不清楚sum of values 是如何最大化的,所以我猜你的意思是将匹配中的所有6 个值加在一起,然后按从大到小排序)。是的,它可以作为一种理解来完成,但我试图明确。

    match = {}
    for team1, team2 in matchups:
        match[f'{team1}_{team2}'] = [df.loc[team1].sum() + df.loc[team2].sum()]
    
    
    df_matches = pd.DataFrame(match).T
    df_matches
    
    Out[93]:
            0
    A_B  -5.8
    A_C  15.7
    A_D  -0.4
    A_E  16.0
    A_F  17.4
    B_C   3.7
    B_D -12.4
    B_E   4.0
    B_F   5.4
    C_D   9.1
    C_E  25.5
    C_F  26.9
    D_E   9.4
    D_F  10.8
    E_F  27.2
    

    这能让你开始吗?

    【讨论】:

    • 你可以这样做matchups = list(combinations(df.index, 2))
    • 已更新以完全删除列表并将输出添加为 df。
    • 嗨@MichaelD,很抱歉我所说的“比赛在哪里使他们的价值之和最大化”的意思混淆了。我的意思是,我的最终目标是最大化球队的最终得分,其中最终得分是根据球员的比赛方式与球员相关的每个整数值的总和。例如,第 1 轮比赛 1 的得分为:9.5,第 1 轮比赛 2 的得分为:8.8。第 1 轮的总分是 18.3,我想最大化第 1 轮的总分
    • @KevinClark 确切的数学计算可能取决于您。为什么首轮首战是9.5?
    • @MichaelD 所以对于第一轮第一场比赛,球员 A 精英值 + 球员 B 中场 + 球员 C 中场 + 球员 D 中场 + 球员 E 低 + 球员 F 低 = 4.2 + -5.8 + 2.8 + 2.3 + -0.6 + 6.0 = 9.5
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    相关资源
    最近更新 更多