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. After this I solve it with 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.
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. 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]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.