问题描述
我的目标是:
- 查找每周比赛中最简单的球队
- 从解决方案中选择最多2支球队(通过每个游戏周从这2支球队的得分进行置换)
我的数据集如下所示:
事件(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
当前输出如下:
预期结果将是仅看到2个团队,例如利物浦和曼城,而不是切尔西等。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)