[Cbc] How to obtain all solutions from the solver

John Forrest john.forrest at fastercoin.com
Mon Oct 8 09:56:48 EDT 2018


Vasily,

If you are using trunk look at Cbc/examples/inc.cpp

John Forrest
On 08/10/18 13:38, Luís Borges de Oliveira wrote:
> 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
>
>
>
> _______________________________________________
> Cbc mailing list
> Cbc at list.coin-or.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__list.coin-2Dor.org_mailman_listinfo_cbc&d=DwICAg&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=js2M0T-3OIMIVDvokcKjokJbk0F8QOCd0mT4FsVFE88&m=vzcNR6TllSgtHyt1Ti-Z95HcMZKWZl6XU6i5wRniABw&s=-dUD0KXsukaZPQ5NQ_nUHv8HtkUnM2IN70f6h4UBzEk&e=


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


More information about the Cbc mailing list