幻想英超联赛灯具清单上的线性编程问题

问题描述

我的目标是:

  1. 查找每周比赛中最简单的球队
  2. 从解决方案中选择最多2支球队(通过每个游戏周从这2支球队的得分进行置换)

我的数据集如下所示:

data set

事件(1)是第一周的比赛,事件(2)是第二周的比赛,等等...

我目前能够使用以下方法为每个装置选择最佳游戏:

for event_id in np.unique(events):
    model += sum(decisions[i] for i in range(event) if events[i]==event_id) == 1  # pick one fixture for each game week

我不知道如何建立约束条件,要求模型仅选择本赛季的2支球队并管理排列。我尝试了几件事没有成功。

我的LP功能如下:

def fixtures_analyser(team,events,expected_scores):
    
    event = len(events)
    objFunction=pulp.LpMaximize
    model = pulp.LpProblem("Constrained value maximisation",objFunction)
    decisions = [
        pulp.LpVariable("x{}".format(i),lowBound=0,upBound=1,cat='Integer')
        for i in range(event)
    ]
    
     # objective function:
    model += sum((decisions[i]) * (float(expected_scores[i]))
        for i in range(event)),"Objective"

     # event constraint
    for event_id in np.unique(events):
        model += sum(decisions[i] for i in range(event) if events[i]==event_id) == 1  # total cost

    model.solve()
    print("Total expected score = {}".format(model.objective.value()))

    return decisions

当前输出如下:

Current Output

预期结果将是仅看到2个团队,例如利物浦和曼城,而不是切尔西等。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...