Last active
February 17, 2021 15:56
-
-
Save rschwarz/7ed3135a19d7ecd24307d6f56e475732 to your computer and use it in GitHub Desktop.
python-mip SEGFAULT when adding lazy constraint generator to simple model in CBC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to the CBC MILP Solver | |
Version: devel | |
Build Date: Nov 15 2020 | |
Starting solution of the Linear programming relaxation problem using Primal Simplex | |
Clp0000I Optimal - objective value 20 | |
Clp0032I Optimal objective 20 - 0 iterations time 0.002, Idiot 0.00 | |
Starting MIP optimization | |
ERROR while running Cbc. Signal SIGSEGV caught. Getting stack trace. | |
/home/rs/in/env/lib/python3.7/site-packages/mip/libraries/lin64/libCbcSolver.so(_Z15CbcCrashHandleri+0x14c) [0x7fd62b6fa83c] | |
/lib/x86_64-linux-gnu/libc.so.6(+0x37840) [0x7fd62c726840] | |
./libClp.so.0(_ZN8ClpModel12emptyProblemEPiPdb+0x226) [0x7fd62aaab466] | |
./libClp.so.0(_ZN10ClpSimplex7startupEii+0x231) [0x7fd62ab272e1] | |
./libClp.so.0(_ZN14ClpSimplexDual12startupSolveEiPdi+0x2d) [0x7fd62ab3d6dd] | |
./libClp.so.0(_ZN14ClpSimplexDual4dualEii+0x1d8) [0x7fd62ab41378] | |
./libClp.so.0(_ZN10ClpSimplex4dualEii+0x65) [0x7fd62ab18c05] | |
./libOsiClp.so.0(_ZN21OsiClpSolverInterface6crunchEv+0x637) [0x7fd62adff097] | |
./libOsiClp.so.0(_ZN21OsiClpSolverInterface7resolveEv+0x13a3) [0x7fd62ae0e723] | |
./libCbc.so.0(_ZN8CbcModel7resolveEP18OsiSolverInterface+0xbd) [0x7fd62b3db64d] | |
./libCbc.so.0(_ZN8CbcModel7resolveEP11CbcNodeInfoiPdS2_S2_+0x14c) [0x7fd62b3dbb3c] | |
./libCbc.so.0(_ZN8CbcModel14branchAndBoundEi+0x840) [0x7fd62b3f8a50] | |
/home/rs/in/env/lib/python3.7/site-packages/mip/libraries/lin64/libCbcSolver.so(_Z8CbcMain1iPPKcR8CbcModelPFiPS2_iER19CbcSolverUsefulData+0xbb31) [0x7fd62b710321] | |
/home/rs/in/env/lib/python3.7/site-packages/mip/libraries/lin64/libCbcSolver.so(Cbc_solve+0x11e3) [0x7fd62b6a6333] | |
/home/rs/in/env/lib/python3.7/site-packages/cffi.libs/libffi-806b1a9d.so.6.0.4(ffi_call_unix64+0x4c) [0x7fd62bdcadec] | |
/home/rs/in/env/lib/python3.7/site-packages/cffi.libs/libffi-806b1a9d.so.6.0.4(ffi_call+0x165) [0x7fd62bdc9f55] | |
/home/rs/in/env/lib/python3.7/site-packages/_cffi_backend.cpython-37m-x86_64-linux-gnu.so(+0x1edf6) [0x7fd62bfecdf6] | |
python(_PyObject_FastCallKeywords+0x4eb) [0x5ce4ab] | |
python() [0x53ed81] | |
python(_PyEval_EvalFrameDefault+0x49ba) [0x54653a] | |
python(_PyEval_EvalCodeWithName+0x252) [0x53f732] | |
python(_PyFunction_FastCallKeywords+0x482) [0x5cd982] | |
python(_PyEval_EvalFrameDefault+0x732) [0x5422b2] | |
python(_PyEval_EvalCodeWithName+0x252) [0x53f732] | |
python(_PyFunction_FastCallKeywords+0x482) [0x5cd982] | |
python(_PyEval_EvalFrameDefault+0x732) [0x5422b2] | |
python(_PyEval_EvalCodeWithName+0x252) [0x53f732] | |
python(PyEval_EvalCode+0x23) [0x541b73] | |
python() [0x62d09e] | |
python(PyRun_FileExFlags+0x97) [0x62d157] | |
python(PyRun_SimpleFileExFlags+0x17f) [0x62dfcf] | |
python() [0x6525ae] | |
python(_Py_UnixMain+0x2e) [0x65290e] | |
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xeb) [0x7fd62c71309b] | |
python(_start+0x2a) [0x5d531a] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# maximize x + y | |
# s.t. (x-4)^2 + (y-2)^2 - 9 <= 0 | |
# 0 <= x, y <= 10 | |
# y integer | |
# | |
# using a lazy constraint callback to generate gradient cuts | |
# | |
import mip | |
def g(x, y): | |
return (x - 4)**2 + (y - 2)**2 - 3**2 | |
def gradient_cut(x0, y0, x, y): | |
dg = 2 * x0 - 8, 2 * y0 - 4 | |
return g(x0, y0) + dg[0] * (x - x0) + dg[1] * (y - y0) <= 0 | |
class GradientCutGenerator(mip.ConstrsGenerator): | |
def __init__(self, x, y, TOL=1e-3): | |
self.x = x | |
self.y = y | |
self.TOL = TOL | |
def generate_constrs(self, model: mip.Model, depth: int = 0, npass: int = 0): | |
x = model.translate(self.x) | |
y = model.translate(self.y) | |
violation = g(x.x, y.x) | |
print(f'### sol = ({x.x:.2f}, {y.x:.2f}), viol = {violation:.2f}') | |
if violation < self.TOL: | |
return | |
# Generate cut | |
model.add_lazy_constr(gradient_cut(x.x, y.x, x, y)) | |
model = mip.Model(solver_name="CBC") | |
model.verbose = 1 | |
x = model.add_var("x", var_type=mip.CONTINUOUS, lb=0, ub=10) | |
y = model.add_var("y", var_type=mip.INTEGER, lb=0, ub=10) | |
model.objective = mip.maximize(x + y) | |
model.lazy_constrs_generator = GradientCutGenerator(x, y) | |
status = model.optimize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 3.7.3 | |
mip 1.13.0 | |
Linux t440p 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment