[Cbc] Cbc changes solver pointer after solving a problem [c++ API]

John Forrest john.forrest at fastercoin.com
Sun Jan 6 04:41:10 EST 2019


You raise an interesting point.

The solver used inside branch and bound is continually being messed up 
as cuts are added etc.  On entry a copy continuousSolver_ is cloned.  At 
the end this copy has variables fixed to give best solution and that is 
returned.

The code in CbcModel.cpp is

   delete continuousSolver_;
   continuousSolver_ = solver_->clone();

It would probably be cleaner to change this to something like

   delete continuousSolver_;
   OsiSolverInterface * tempSolver = solver_->clone();
   continuousSolver_ = solver_;
   solver_ = tempSolver;

However that fails.

I will look into it.

John Forrest


On 05/01/2019 23:12, Wendel Melo wrote:
> Dear friends
>
> I am giving my first steps with CBC to Mixed Integer Linear 
> Programming (MILP) by means of the C++ API. My current goal is to turn 
> Cbc one of the MILP solvers supported in Muriqui Optimizer, a free 
> MINLP solver (www.wendelmelo.net/software 
> <http://www.wendelmelo.net/software>).
>
> Due to design questions, I have been constructing an object of the 
> CbcModel class using an empty OsiSolverInterface object:
>
> OsiClpSolverInterface   clp ;
> CbcModel   *model = new (std::nothrow) CbcModel(clp);
>
> After that, I have been set the coefficients of my MILP problem by 
> means of the pointer returned by the method CbcModel::solver, for example:
>
> OsiSolverInterface *solver = model->solver()
>
> solver->addCol(0, NULL, NULL,   0.0,  1000.0,   1.0);
>
> I am performing in this way to avoid delay copping the 
> OsiSolverInterface object in the CbcModel constructor since I need to 
> solve a sequence where the same MILP problem has to be solved several 
> times just changing some parameters.
>
> But I have been getting some problems. After calling method 
> CbcModel::branchAndBound by the second time, the pointer returned by 
> CbcModel::solver is getting a different value of the previous call, 
> for example:
>
> std::cout << "before BB solver pointer: " << model->solver() << std::endl;
> model->branchAndBound()
> std::cout << "after BB solver pointer: " << model->solver() << std::endl;
>
> The code above prints:
>
> before BB solver pointer:  0x1455a628
> after BB solver pointer:  0x14887f88
>
> So, we can see the solver pointer in CbcModel object was changed. Why 
> is it happening? I believe creating new solver objects is bad because 
> increase the computations. Is there a way to avoid the changing of 
> solver object pointer? Are there other methods in CbcModel that can 
> provoke the changing of the solver pointer?
>
> Thanks in advanced
>
> Best regards
>
>
> Wendel Melo
> www.wendeldelo.net <http://www.wendeldelo.net>
>
> _______________________________________________
> 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/20190106/ac5c4084/attachment.html>


More information about the Cbc mailing list