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:
- I setted
x6, x7, x8, x9, x10, x11
asbinary
variables; - for each of them, I defined the
lower
bound equal to0
and theupper
bound equal to500
.
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 containsx6, 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:
gives: