[英]Python Pulp does not add all variables constraints and forgets objective function
I am running in some problems using the module pulp. 我在使用模块纸浆时遇到一些问题。 I want to create an mixed integer linear programming problem and write it as a LP file. 我想创建一个混合整数线性编程问题,并将其写为LP文件。 After this I solve it with cplex. 之后,我用cplex解决了它。
The problem is that when I add the second constraints, the objective function becomes false(dummy is added) and only the first constraint is added with only decision variable x. 问题在于,当我添加第二个约束时,目标函数变为false(添加了虚拟对象),并且仅第一个约束与决策变量x一起添加。
This is my code: I hope you can help me out! 这是我的代码:希望您能帮帮我!
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)
I don't think list comprehensions [x[i] for i in ...] can be added to bay_model like this. 我不认为列表推导[x [i] for i in ...]可以像这样添加到bay_model中。 If you want the constraint to hold over each element in the list you can define the elements beforehand: 如果希望约束保留在列表中的每个元素上,则可以预先定义元素:
for i in flights:
for j in flights:
if f.time_matrix[i][j] == 1:
for k in gates:
bay_model += y[i][j][k] * f.time_matrix[i][j] <= g.capacity[k]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.