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
518 stars 92 forks source link

Segmentation fault when adding lazy constaints to CBC #175

Open rschwarz opened 3 years ago

rschwarz commented 3 years ago

Describe the bug I create a small MIP model, using CBC. I also create a ConstrsGenerator and add it via model.lazy_constrs_generator. When I call model.optimize(), Python crashes with a segmentation faul.

To Reproduce See script and output in gist.

Desktop (please complete the following information):

Additional context I believe that the generate_constrs method of the ConstrsGenerator is not even called. Also, when adding it via model.cuts_generator, there is no crash (but it's also never called?).

Maybe this has to do with the limited preprocessing in CBC that the documentation hints at?

rschwarz commented 3 years ago

I found that the script to reproduce the problem can be simplified to:

import mip

class CutGen(mip.ConstrsGenerator):
    pass

model = mip.Model(solver_name="CBC")
x = model.add_var("x", var_type=mip.BINARY)
model.lazy_constrs_generator = CutGen()
status = model.optimize()

For what it's worth, I also checked all released versions of python-mip from 1.8 to 1.13, to see whether the crash is related to an updated version of the CBC library.

sebheger commented 2 years ago

If you just add an "obsolete" constraint, it works.

model += x <= 1

Seems to be an issue related to adding a lazy constraint generator if the model itself has no constraints. No issue with this for gurobi, only for CBC.