我在使用模块纸浆时遇到了一些问题。我想创建一个混合整数线性规划问题并将其写为 LP 文件。在此之后,我用 cplex 解决它。
问题是,当我添加第二个约束时,目标函数变为 false(添加了虚拟),并且仅添加了第一个约束,仅包含决策变量 x。
这是我的代码:我希望你能帮助我!
bay_model = pulp.LpProblem('Bay Problem', pulp.LpMinimize)
y = pulp.LpVariable.dicts(name = "y",indexs = (flight, flight, gates),
lowBound = 0, upBound = 1,cat = pulp.LpInteger)
x = pulp.LpVariable.dicts(name = "x",indexs = (flight,gates),lowBound = 0,
upBound = 1, cat=pulp.LpInteger)
bay_model += pulp.lpSum([x[i][j]*g.distance[j] for i in flight for j in gates])
for i in flight:
bay_model += pulp.lpSum([x[i][j] for j in gates]) == 1
print "flight must be assigned" + str(i)
for k in gates:
bay_model += [y[i][j][k] * f.time_matrix[i][j] for i in flight for j in flight if f.time_matrix[i][j] == 1] <= g.capacity[k]
bay_model += [(2 * y[i][j][k] - x[i][k] - x[j][k]) for i in flight for j in flight] == 0
print "time constraint" + str(k)