Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when trying to add PreProcessing for cbcModel #124

Open
RussianImperialScott opened this issue Oct 11, 2021 · 3 comments
Open

Segfault when trying to add PreProcessing for cbcModel #124

RussianImperialScott opened this issue Oct 11, 2021 · 3 comments

Comments

@RussianImperialScott
Copy link

RussianImperialScott commented Oct 11, 2021

I'm trying to run the example given for cbcModel, but adding a PreProcessing cut generator (full context: I was trying to solve a much bigger problem and running into the same issue as below). However, this is causing a segfault, and I have no idea how to start debugging this. I've encountered this with two separate builds of Cbc (one via conda, and one via coinbrew, all on Linux running within WSL). Here's the exact code:

import numpy as np
from cylp.cy import CyCbcModel, CyClpSimplex
from cylp.cy.CyCgl import CyCglPreProcess
from cylp.py.modeling.CyLPModel import CyLPModel, CyLPArray
model = CyLPModel()

x = model.addVariable('x', 3, isInt=True)
y = model.addVariable('y', 2)

A = np.matrix([[1., 2., 0],[1., 0, 1.]])
B = np.matrix([[1., 0, 0], [0, 0, 1.]])
D = np.matrix([[1., 2.],[0, 1]])
a = CyLPArray([5, 2.5])
b = CyLPArray([4.2, 3])
x_u= CyLPArray([2., 3.5])

model += A*x <= a
model += 2 <= B * x + D * y <= b
model += y >= 0
model += 1.1 <= x[1:3] <= x_u

c = CyLPArray([1., -2., 3.])
model.objective = c * x + 2 * y.sum()

s = CyClpSimplex(model)

cbcModel = s.getCbcModel()
cbcModel.addCutGenerator(CyCglPreProcess())

Result:

Segmentation fault (core dumped)

I hope that I'm just doing something really ignorant, but other cut generators don't cause the same issue. And from solving my problem using PuLP previously, I can see that the PreProcessing step substantially reduced the size of the problem before Cbc found the ultimate solution. Just throwing the model at Cbc without preprocessing definitely is not working.

@tkralphs
Copy link
Member

Although it lives in the Cgl package, CglPreprocess is not a standard cut generator, i.e., it is not derived from the CglCutGenerator base class and does not support the same API. I guess the original authors of CyLP threw it in with all the others by mistake. I'm not 100% sure how this actually compiles, but I guess the seg fault occurs when it tries to do something using the base class API, which isn't going to work. This should probably just be removed, as I don't think there's probably any easy way to use this preprocessor dynamically like you're trying to do.

However, when you call Cbc from CyLP, it should actually call the preprocessor internally by default, just as when you call it through PuLP. You shouldn't need to do anything special. So I'm not sure what you're trying to do exactly. If you can explain a little further, maybe I can make a suggestion.

@RussianImperialScott
Copy link
Author

You are right! Turns out initial model for my specific problem (not the demo model) was not specified correctly, so all sorts of bad things were happening. When I specified it correctly, CBC indeed called the cut generator. The issue with calling cbcModel.addCutGenerator(CyCglPreProcess()) was a red herring. I don't need anything else here - you can close this issue if you wish.

@tkralphs
Copy link
Member

Thanks for confirming. I guess I'll leave this open as a reminder that I should probably just remove CyCglPreprocess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants