I am modeling a large linear program using the Python CyLP package to access the COIN-OR CLP solver, and would like to create a copy of the model to facilitate a future warm start. Simply assigning the model to a new variable creates a shallow copy (copy by reference), and does not preserve the benefits of saving a snapshot (I am modifying the original model, and want to come back to warm start from the copy point). If I use copy.deepcopy()
, I get exceptions when modifying the copy model. Attempting to solve the copy kills my python kernel with a Segmentation 11 fault.
E.g.:
from copy import deepcopy
from cylp.cy import CyClpSimplex
model1 = CyClpSimplex()
x = model1.addVariable('x',1)
y = model1.addVariable('y',1)
# Add constraints to model:
model1 += 2*x + y >= 4
model1 += x + 2*y >= 5
model1.objective = x + y
model1.primal()
# Produces correct solution, accessed through
# Save a copy for reference:
model2 = deepcopy(model1)
# Do a bunch of stuff to model1, and now come back to work with model2:
model2.objective = 2*x + y
>> Exception: To set the objective function of CyClpSimplex set cylpSimplex.cyLPModel first
model2.primal()
kills my Python instance, with a Segmentation 11 fault.
Does anyone know what could be causing the exception and/or the fatal error?