我是混合整数优化问题的新手。目前,我正在使用带有默认CBC求解器的纸浆python接口来解决该问题。 问题是要提高癌症诊所模型中的资源利用率,以下是具有目标功能和约束的代码。当我使用prob.solve()时,我有3个不同的问题: 1.我为BeginTreatment变量获得了值1.0,但是没有为ContinueTreatment变量获得了值1.0? 2.根据主席的连续性约束,不应将编号大于29的插槽分配给pat_type 8,因为最多只能有40个插槽。但是我仍然看到吗? (不仅对于pat_type为8,其他类型也是如此) 3.是否应该尝试使用其他求解器而不是默认的纸浆CBC求解器?如果是,该怎么办?
import pulp
# Indices and Parameters
chair = list(range(1,24))
pat_type = list(range(1,9))
slot = list(range(1,41))
type_and_demand = {1:24,2:10,3:13,4:9,5:7,6:6,7:2,8:1}
type_and_slots = {1:1,2:4,3:8,4:12,5:16,6:20,7:24,8:28}
# Decision Variables
Y = pulp.LpVariable.dicts("BeginTreatment",
(chair,pat_type,slot),0,1,pulp.LpBinary)
X = pulp.LpVariable.dicts("ContinueTreatment",
(chair,pat_type,slot),0,1,pulp.LpBinary)
# Objective Function
prob = pulp.LpProblem("ChairUtilization", pulp.LpMaximize)
prob += pulp.lpSum([Y[i][j][t] for i in chair for j in pat_type for t in
slot])
# Constraints
# Patient Type 1 Continuity constraint
for i in chair:
for t in slot:
for j in range(1,2):
prob += X[i][j][t] == 0
# Chair Continuity Constraint
for i in chair:
for j in range(2,9):
for t in range(1,(len(slot)-type_and_slots[j]+1)+1):
prob += pulp.lpSum([X[i][j][u] for u in range(t+1,t+type_and_slots[j])])
== (type_and_slots[j] - 1)*Y[i][j][t]
# No more than one patient per chair
for t in slot:
for i in chair:
prob += pulp.lpSum([X[i][j][t] for j in pat_type]) + pulp.lpSum([Y[i][j]
[t] for j in pat_type]) <= 1
# No new arrivals during lunch time period
prob += pulp.lpSum([Y[i][j][t] for i in chair for j in pat_type for t in
range(19,23)]) == 0
# Patient Mix
for j in pat_type:
prob += pulp.lpSum([Y[i][j][t] for i in chair for t in slot]) ==
type_and_demand[j]
prob.solve()