Python Pulp does not add all variables constraints and forgets objective function -
i running in problems using module pulp. want create mixed integer linear programming problem , write lp file. after solve cplex.
the problem when add second constraints, objective function becomes false(dummy added) , first constraint added decision variable x.
this code: hope can 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] in flight j in gates]) in flight: bay_model += pulp.lpsum([x[i][j] j in gates]) == 1 print "flight must assigned" + str(i) k in gates: bay_model += [y[i][j][k] * f.time_matrix[i][j] in flight 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]) in flight j in flight] == 0 print "time constraint" + str(k)
i don't think list comprehensions [x[i] in ...] can added bay_model this. if want constraint hold on each element in list can define elements beforehand:
for in flights: j in flights: if f.time_matrix[i][j] == 1: k in gates: bay_model += y[i][j][k] * f.time_matrix[i][j] <= g.capacity[k]
Comments
Post a Comment