import pulp
# 构建问题
prob = pulp.LpProblem("Team Assignment Problem", pulp.LpMaximize)
# 创建变量
teams = range(198)
timeslots = range(8)
x = pulp.LpVariable.dicts("x", [(i, j) for i in teams for j in timeslots], cat="Binary")
# 创建约束条件
for i in teams:
prob += pulp.lpSum([x[(i, j)] for j in timeslots]) == 1 # 每个队伍只能分配到一个时间段
for j in timeslots:
prob += pulp.lpSum([x[(i, j)] for i in teams]) <= 25 # 每个时间段只能分配到25个队伍
# 定义目标函数
prob += pulp.lpSum([x[(i, j)] for i in teams for j in timeslots])
# 求解问题
prob.solve()
# 输出结果
print("Total number of teams assigned: ", int(pulp.value(prob.objective)))
for j in timeslots:
assigned_teams = [i for i in teams if x[(i, j)].value() == 1]
print(f"Time slot {j}: {len(assigned_teams)} teams assigned: {assigned_teams}")