I'm using CPLEX 12.9 with Python to solve a MILP (Mixed-Integer Linear Problem). I tried two approaches; I expected the same results, but while the first approach works, the second doesn't.
1) First approach:
This approach works successfully. In the generated ".lp" file (a text file which contains a human-readable formulation of the problem: there's an objective function which has to be minimized and some constraints) it can be seen that x6, x7, x8, x9, x10, x11
are continuous
variables and all of them are equal to 500
(I defined both their upper
and lower
bounds equal to 500
; so they're effectively constants).
2) Second approach:
It returns CPLEX Error 1217: No solution exists
, so CPLEX isn't able to find a solution, but I can't understand why.
The only things that I changed are:
x6, x7, x8, x9, x10, x11
as binary
variables;lower
bound equal to 0
and the upper
bound equal to 500
.So, the generated ".lp" file is very similar to the one generated by using the first approach; the only different things are that:
x6, x7, x8, x9, x10, x11
are defined as ranges (instead of constants), so they are:
0 <= x6 <= 500
0 <= x7 <= 500
0 <= x8 <= 500
0 <= x9 <= 500
0 <= x10 <= 500
0 <= x11 <= 500
the Binaries
section (at the end of the ".lp" file) now contains x6, x7, x8, x9, x10, x11
variables, too.
Note:
Even if (in the second approach) I set both lower
and upper
bounds equal to 500
, the problem would persists.
If you use binary that means the decision variable will either be 0 or 1 even if you later add some constraint that this should be less than 500.
If you want your decision variable to allow 500 as a value you should either use float or integer as type.
If I use the zoo example and change integer to binary:
from docplex.mp.model import Model
mdl = Model(name='buses')
nbbus40 = mdl.binary_var(name='nbBus40')
nbbus30 = mdl.binary_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)
mdl.solve()
print(mdl.solve_details.status)
gives:
integer infeasible