[Cbc] Segfault / memory corruption after "assignSolver" in "CbcModel"
Dirk Eßer
essdir at web.de
Wed May 7 06:18:27 EDT 2014
Hello,
I have a little problem adding a preprocessing step to program doing MIP
solving using the CBC library. The problem is, that the program fails
with more or less random memory corruption (and in the better cases:
with a segfault) some of the time.
The CbcModel instance is created programmatically
OsiClpSolverInterface iface;
CoinPackedMatrix pmx(false, num_columns, num_rows, num_elements,
matrix, columns, starts, lengths);
iface.setObjSense(-1.0);
iface.loadProblem(pmx, 0, 0, objective, senses, rights, 0);
iface.passInMessageHandler(&printer);
model_ptr LP(new CbcModel(iface));
... adding stuff via LP->addObjects(...) to declare integer
constraints on variables and a few SOSes ...
Things work fine, if we directly compute a solution without further
preprocessing via
LP->initialSolve();
LP->branchAndBound();
We now try to add a pre-processing step to the solution process. As a
starting point, we used the driver code generated by the CBC command
line tool ("-cpp 0", which doesn't compile).
OsiSolverInterface* original_solver = LP->solver();
OsiSolverInterface* cloned_solver = original_solver->clone();
OsiSolverInterface* configured_solver = 0;
cloned_solver->passInMessageHandler(LP->messageHandler());
cloned_solver->setHintParam(OsiDoInBranchAndCut, true, OsiHintDo);
CglPreProcess processor;
{
CglProbing prober;
prober.setUsingObjective(1);
prober.setMaxPass(3);
prober.setMaxProbeRoot(cloned_solver->getNumCols());
prober.setMaxElements(100);
prober.setMaxLookRoot(50);
prober.setRowCuts(3);
processor.addCutGenerator(&prober);
}
configured_solver = processor.preProcessNonDefault(*cloned_solver,
2, 10);
cloned_solver->setHintParam(OsiDoInBranchAndCut, false, OsiHintDo);
if (!configured_solver)
{
delete cloned_solver;
return status::infeasible;
}
configured_solver->setHintParam(OsiDoInBranchAndCut, false, OsiHintDo);
OsiSolverInterface* configured_clone = configured_solver->clone();
LP->assignSolver(configured_clone, true /* Kill previous solver */);
/*-- XXX --*/
LP->initialSolve();
LP->branchAndBound();
int n_cols = cloned_solver->getNumCols();
processor.postProcess(*LP->solver());
LP->assignSolver(cloned_solver, true /* Kill previous solver */);
memcpy(LP->bestSolution(), LP->solver()->getColSolution(), n_cols *
sizeof(double));
It seems, that we are violating one or two unwritten laws of memory
management with CBC, but I am at loss as what we are doing wrong here.
Any help, hints, pointer to documentation, etc. is highly appreciated.
Cheers,
Dirk Eßer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20140507/0e1eee2b/attachment.html>
More information about the Cbc
mailing list