[Cbc] How to obtain all solutions from the solver
Vasily Stepanov
vasily.stepanov at gmail.com
Sat Oct 6 14:19:16 EDT 2018
I'm using callCbc() function, and I would like to obtain every new solution
during the solving process.
Here are some minimal example
OsiClpSolverInterface osi;
CbcModel model(osi);
CoinModel build;
// ... setting up the model.
osi.loadFromCoinModel(build);
MyEventHandler eventHandler;
model.passInEventHandler(&eventHandler);
callCbc(args, model);
And later the event method:
CbcEventHandler::CbcAction MyEventHandler::event(CbcEvent whichEvent) {
const CbcModel *model = getModel();
// Here I can filter out sub trees.
if (model->parentModel()) {
return CbcEventHandler::CbcAction::noAction;
}
if (whichEvent == CbcEventHandler::CbcEvent::solution || whichEvent
== CbcEventHandler::CbcEvent::heuristicSolution) {
const double *best_solution = model->bestSolution();
// And here is the best solution found so far.
// But still this is not the solution for my problem, but for
the optimised one,
// with reduced number of columns.
std::vector<double> original_solution(original_columns_count,
0);
const int* original_columns = model->originalColumns();
for (int i = 0; i < model->getNumCols(); ++i) {
original_solution[original_columns[i]] = best_solution[i];
}
// original_solution will have zeroes where it should not be.
}
}
The question is: How to restore the solution from the one which has reduced
number of columns.
And more general question: How to obtain every new solution during the
solving process in callCbc() method.
Thanks,
// Vasily
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20181006/e1d62f55/attachment.html>
More information about the Cbc
mailing list