[Cbc] How to obtain all solutions from the solver

Luís Borges de Oliveira lbo at siscog.pt
Mon Oct 8 08:38:19 EDT 2018


Hello Vasily,

John gave us some hints on how to do this a few years ago, including the
post-processing bits that you're having trouble with. Here's the e-mail
thread: https://list.coin-or.org/pipermail/cbc/2016-August/002029.html

HTH,
Luís

On 06-10-2018 19:19, Vasily Stepanov wrote:
> 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
>
>
> _______________________________________________
> Cbc mailing list
> Cbc at list.coin-or.org
> https://list.coin-or.org/mailman/listinfo/cbc

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20181008/ab7c4e7e/attachment.html>


More information about the Cbc mailing list