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

Windows fatal exception: integer overflow - using MIP and CBC #306

Open simonhoerdumbonde opened 1 year ago

simonhoerdumbonde commented 1 year ago

I run a model optimization using CBC which terminates with exit code -1073741675, and when running the model as a test case using pytest it returns Windows fatal exception: integer overflow. By refactoring the first constraint of the model (divide by 123 to make the comp4 coefficient 1) the solver returns an optimal solution.

I have created a reduced version of my model which also produces the error. The .LP file I use looks like this:

\Problem name: CBC

Minimize
OBJROW: abs_disp_comp1 + abs_disp_comp2 + abs_disp_comp3 + abs_turn_comp3 + abs_disp_comp4 + abs_disp_comp5 + abs_turn_comp5
Subject To
constr(1):  123 comp4 -14595000000 minInd_comp4 <= 2166172585
constr(2):  109 comp1 - abs_disp_comp1 <= 4932154
constr(3):  -109 comp1 - abs_disp_comp1 <= -4932154
constr(4):  109 comp2 - abs_disp_comp2 <= -15299006
constr(5):  -109 comp2 - abs_disp_comp2 <= 15299006
constr(6):  98 comp3 - abs_disp_comp3 <= -12877413
constr(7):  -98 comp3 - abs_disp_comp3 <= 12877413
constr(8):  98 comp3 - abs_turn_comp3 <= -0
constr(9):  -98 comp3 - abs_turn_comp3 <= 0
constr(10):  123 comp4 - abs_disp_comp4 <= 79205599
constr(11):  -123 comp4 - abs_disp_comp4 <= -79205599
constr(12):  comp5 - abs_disp_comp5 <= -30819408
constr(13):  - comp5 - abs_disp_comp5 <= 30819408
constr(14):  comp5 - abs_turn_comp5 <= -0
constr(15):  - comp5 - abs_turn_comp5 <= 0
Bounds
 comp1 Free
 comp2 Free
 comp3 Free
 comp4 Free
 comp5 Free
 0 <= minInd_comp4 <= 1
 abs_disp_comp1 Free
 abs_disp_comp2 Free
 abs_disp_comp3 Free
 abs_turn_comp3 Free
 abs_disp_comp4 Free
 abs_disp_comp5 Free
 abs_turn_comp5 Free
Integers
comp1 comp2 comp3 comp4 comp5 minInd_comp4  
End

I run it using pytest with the above model_overflow.lp input:

import mip
class TestOverflow:
    def test_overflow(self):
        m = mip.Model(solver_name="CBC")
        m.read('model_overflow.lp')
        optimization_status = m.optimize()
        assert optimization_status == mip.OptimizationStatus.OPTIMAL

I would expect the model to be solvable, which it also is if I refactor the constraints. I also tried giving the solver an initial feasible solution with all integer variables set to zero, which didn't change the behavior.

I have tried to run the model on linux mint with python 3.10 and that works as expected.

sebheger commented 1 year ago

Thanks @simonhoerdumbonde for reporting the issue. Looks like an issue with CBC. We need to check first if this is also a bug when using standalone cbc solver