我正在尝试使用 Python 中的 Pulp 模块找到问题的最佳解决方案。我的问题出在照片上。我在 Pulp 中写了这个问题,但我发现这个问题是不可行的(状态 -1)。我知道这个问题有解决方案,但我必须在代码中犯一些错误(当我改变变量是连续的问题有连续的解决方案时)。 感谢您的帮助。
import numpy as np
# Import PuLP modeler functions
from pulp import *
# Creates the 'prob' variable to contain the problem data
prob = LpProblem("Computer company service problem", LpMinimize )
demand = {1: 6000, 2: 7000, 3: 8000, 4: 9500, 5: 11500}
# A dictionary called 'Vars' is created to contain the referenced variables(the routes)
vars_x = LpVariable.dicts("x", range(1,6), 0, None, LpInteger)
vars_y = LpVariable.dicts("y", range(1,6), 0, None, LpInteger)
# The objective function is added to 'prob' first
prob += lpSum([15000*vars_y[i] + 7500*vars_x[i] for i in range(1,6)]), "Sum_of_employee_cost"
# The demand minimum constraints are added to prob for each demand
for i in range(1,6):
prob += 160*vars_y[i]-50*vars_x[i]>=demand[i], f"Reach demand in month {i}"
# The demand minimum constraints are added to prob for each demand node (bar)
prob += vars_y[1]==50, f"Workers in month {1}"
for i in range(2,6):
prob += 0.95*vars_y[i-1]+vars_x[i-1]==vars_y[i], f"Workers in month {i}"
prob.solve()