IBMDecisionOptimization / docplex-examples

These samples demonstrate how to use the DOcplex library to model and solve optimization problems.
https://ibmdecisionoptimization.github.io/
Apache License 2.0
396 stars 228 forks source link

CPLEX MIP Limit Solutions returning bad solver status = error #36

Closed bhimabi closed 4 years ago

bhimabi commented 4 years ago

Code: Python CPLEX Version: CPLEX Studio 12.10

I wanted my MIP solver to exit when it finds its first non-zero solution (i.e. 2nd solution).

So i set option 'mip_limit_solutions' = 2 to run my code. It does run and find a solution but when it tries to returns the output it gives the error. I tried to increase the limit to 999(i.e. solver exits due to finding optimal instead of this limit) and it finds the global optimal and returns the solution. Hence, I suspect the error related to the solution limit. I have included the terminal output and a code snippet below. I have not included the entire model as it solves perfectly if that option is not used.

In case the formatting below is bad, here is a screenshot of the terminal output.Terminal Error Output

Detecting symmetries...

  0     2     2466.7967    37     1475.9071     2465.8441      280   67.07%

Elapsed time = 0.50 sec. (218.90 ticks, tree = 0.01 MB, solutions = 1)

  • 228 155 integral 0 1476.1593 2315.5068 3073 56.86%

Implied bound cuts applied: 1

Flow cuts applied: 4

Mixed integer rounding cuts applied: 19

Gomory fractional cuts applied: 1

Root node processing (before b&c):

Real time = 0.50 sec. (218.93 ticks)

Sequential b&c:

Real time = 0.16 sec. (71.10 ticks) ------------ Total (root+branch&cut) = 0.66 sec. (290.03 ticks)

    0.67 seconds required for solver

Traceback (most recent call last):

File "Castro MILP.py", line 324, in

X.solve(report_timing=True, tee=True, warmstart=True)

File "\venv\lib\site-packages\pyomo\solvers\plugins\solvers\persistent_solver.py", line 527, in solve default_variable_value=self._default_variable_value)

File "\venv\lib\site-packages\pyomo\core\base\PyomoModel.py", line 242, in load_from % str(results.solver.status))

ValueError: Cannot load a SolverResults object with bad status: error

X.options['threads'] = 1
X.options['mip_limits_solutions'] = 2
X.options['timelimit'] = 1
X.options['emphasis_mip'] = 1
X.solve(report_timing=True, tee=True, warmstart=True)