coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
514 stars 89 forks source link

Gurobi: `relax=True` is seemingly ignored #291

Closed Markus28 closed 1 year ago

Markus28 commented 1 year ago

If we try to solve an LP relaxation using Gurobi it looks like relax=True is just ignored and the IP is solved instead.

To reproduce:

>>> import mip
>>> model = mip.Model(solver_name="gurobi")
Set parameter Username
Academic license - for non-commercial use only - expires 2023-07-07
>>> x = model.add_var("x", var_type="I", lb=-1.1, ub=1.1)
>>> model.objective = x
>>> model.optimize(relax=True)
Set parameter NodeLimit to value 1073741824
Set parameter SolutionLimit to value 1073741824
Set parameter IntFeasTol to value 1e-06
Set parameter Method to value 3
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Thread count: 48 physical cores, 48 logical processors, using up to 32 threads
Optimize a model with 0 rows, 1 columns and 0 nonzeros
Model fingerprint: 0x0815f9d2
Coefficient statistics:
  Matrix range     [0e+00, 0e+00]
  Objective range  [1e+00, 1e+00]
  Bounds range     [1e+00, 1e+00]
  RHS range        [0e+00, 0e+00]
Presolve removed 0 rows and 1 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0   -1.0000000e+00   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective -1.000000000e+00
<OptimizationStatus.OPTIMAL: 0>
>>> x.x
-1.0

We would expect to get optimal value -1.1 and x.x == -1.1.

Markus28 commented 1 year ago

Nope, this was apparently caused by some pre-processing that set the lower and upper bounds to integers