Open gewesp opened 2 years ago
Update: I can narrow it down to iterating over model.constrs
. It happens also before calling optimize()
. It appears that Python-MIPs idea of the number of constraints does not agree with Cbc's. Something fishy
with cbclib.Cbc_getNumRows()
.
Interestingly, I now get an Abort without a stack trace and in a different location in the C++ code:
BOPOPT:INFO: Model has 220 constraint(s)
BOPOPT:INFO: Solver has 219 constraint(s)
Invalid row index (219), valid range is [0,219). At .../cbc/cbc/Cbc/src/Cbc_C_Interface.cpp:1599
Abort trap: 6
With the following code:
assert n_constr == model.num_rows
logger.info(f"Model has {n_constr} constraint(s)")
logger.info(f"Solver has {model.solver.num_rows()} constraint(s)")
logger.debug("All constraints:")
for c in model.constrs:
logger.debug(f"{c}")
Before that, I call nothing special, just calls to add_var()
and add_constr()
.
@gewesp Thanks for your investigations. We are already aware of the problem that handling of so-called "empty" constraints at python-mip as well at CBC interface is not correct. See https://github.com/coin-or/python-mip/pull/237 where I proposed a fix on python-mip side, that is still "pending" as handling of this cases by the cbc api is not 100% clear.
Describe the bug
check_optimization_result()
crashes CBC on some models. From the error message, it looks like an off-by-one error.I'm calling the function after verifying that an optimal solution was found:
Apart from that, my solutions look perfectly fine; although I noticed today that occasionally the progress log is nondeterministic---Are any randomized algorithms involved?
Edit: Repro steps added. I had some constraints in my model that evaluated to something like
0 <= 1
. Cbc probably decides to discard those, but Python-MIP doesn't notice.Workaround: Don't add tautological constraints like in the repro steps below.
Error message and stack trace:
To Reproduce
Minimal example:
Expected behavior
Function doesn't crash CBC.
Laptop:
../coinbrew --ssh -j8 build Cbc@master
on Mar 15, 2022: