In this method, we will solve UFL exactly with branch and bound. Some of the solvers have a built-in enumeration scheme. In this case, we can simply call si->branchAndBound(). However, some solvers (e.g., CLP), do not have a built-in branch and bound. So, we will use the SBB (Simple Branch and Bound) module.
In the case of using CLP, we simply construct an instance of SbbModel from the OsiSolver interface and call branchAndBound(). Then, if we have found optimal, we can retrieve the optimal solution using getColSolution().
#ifdef COIN_USE_CLP SbbModel model(*si); model.branchAndBound(); if(model.isProvenOptimal()){ const double * solution = model.getColSolution(); const double * objCoeff = model.getObjCoefficients(); print_solution(solution, objCoeff); } else cerr << "B&B failed to find optimal" << endl; return; #endif
Similarly, if we are using OSL, we can solve and retrieve the solution directly from the solver interface.
#ifdef COIN_USE_OSL si->branchAndBound(); if(si->isProvenOptimal()){ const double * solution = si->getColSolution(); const double * objCoeff = si->getObjCoefficients(); print_solution(solution, objCoeff); } else cerr << "B&B failed to find optimal" << endl; return; #endif
Next, we will show how to simulate the root node of a branch and cut tree by adding cuts to the initial LP.