15 #include "CbcModel.hpp"
16 #include "CbcBranchActual.hpp"
17 #include "CbcCutGenerator.hpp"
18 #include "CbcCompareActual.hpp"
19 #include "CbcCompareObjective.hpp"
20 #include "CbcCompareEstimate.hpp"
31 #define CUTOFF_TOL 1e-6
41 #include "CoinSignal.hpp"
48 if (BonminInteruptedOnce) {
49 std::cerr<<
"User forced interuption"<<std::endl;
60 BonminInteruptedOnce =
true;
75 continuousRelaxation_(-COIN_DBL_MAX),
77 mipIterationCount_(0),
110 OsiBabSolver * babInfo =
dynamic_cast<OsiBabSolver *
>(s.
continuousSolver()->getAuxiliaryInfo());
113 if (bonBabInfoPtr == NULL) {
116 delete bonBabInfoPtr;
126 model_.assignSolver(solver,
true);
136 model_.setSpecialOptions(specOpt);
141 model_.setStrategy(strat);
149 for (BabSetupBase::CuttingMethods::iterator i = s.
cutGenerators().begin() ;
155 model_.addCutGenerator(i->cgl,i->frequency,i->id.c_str(), i->normal,
159 ->setMustCallAgain(
true);
163 for (BabSetupBase::HeuristicMethods::iterator i = s.
heuristics().begin() ;
165 CbcHeuristic * heu = i->heuristic;
167 model_.addHeuristic(heu, i->id.c_str());
178 model_.solver()->messageHandler()->setLogLevel(logLevel);
191 bool hasPseudo = (upPsCosts!=NULL);
192 model_.findIntegers(
true,hasPseudo);
193 OsiObject ** simpleIntegerObjects =
model_.objects();
194 int numberObjects =
model_.numberObjects();
195 if (priorities != NULL || directions != NULL || hasPseudo) {
196 for (
int i = 0 ; i < numberObjects ; i++) {
197 CbcObject *
object =
dynamic_cast<CbcObject *
>
198 (simpleIntegerObjects[i]);
199 int iCol =
object->columnNumber();
201 object->setPriority(priorities[iCol]);
203 object->setPreferredWay(directions[iCol]);
205 CbcSimpleIntegerPseudoCost * pscObject =
206 dynamic_cast<CbcSimpleIntegerPseudoCost*
> (object);
207 pscObject->setUpPseudoCost(upPsCosts[iCol]);
208 pscObject->setDownPseudoCost(downPsCosts[iCol]);
220 const int & numSos = sos->
num;
221 (*nlpSolver->messageHandler())<<
"Adding "<<sos->
num<<
" sos constraints."
224 CbcObject ** objects =
new CbcObject*[numSos];
225 const int * starts = sos->
starts;
226 const int * indices = sos->
indices;
227 const char * types = sos->
types;
228 const double * weights = sos->
weights;
230 bool hasPriorities =
false;
232 int numberObjects =
model_.numberObjects();
235 for (
int i = 0 ; i < numberObjects ; i++) {
236 if (varPriorities[i]) {
237 hasPriorities =
true;
245 for (
int i = 0 ; i < numSos ; i++) {
246 if (sosPriorities[i]) {
247 hasPriorities =
true;
252 for (
int i = 0 ; i < numSos ; i++)
254 int start = starts[i];
255 int length = starts[i + 1] - start;
257 printf(
"setting nway object\n"),
258 objects[i] =
new CbcNWay(&
model_, length, &indices[start],
260 objects[i]->setPriority(1);
262 objects[i] =
new CbcSOS(&
model_, length, &indices[start],
263 &weights[start], i, types[i]);
264 objects[i]->setPriority(10);
266 if (hasPriorities && sosPriorities && sosPriorities[i]) {
267 objects[i]->setPriority(sosPriorities[i]);
270 model_.addObjects(numSos, objects);
271 for (
int i = 0 ; i < numSos ; i++)
278 CbcObject ** objects =
new CbcObject *[s.
objects().size()];
279 for (
unsigned int i = 0 ; i < s.
objects().size() ; i++) {
280 objects[i] =
dynamic_cast<CbcObject *
> (s.
objects()[i]);
282 objects[i]->setModel(&
model_);
297 CbcBranchDefaultDecision branch;
304 model_.setBranchingMethod(&branch);
306 model_.solver()->deleteObjects();
319 CbcCompareObjective compare;
320 model_.setNodeComparison(compare);
323 CbcCompareDepth compare;
324 model_.setNodeComparison(compare);
327 CbcCompareDefault compare;
328 compare.setWeight(0.0);
329 model_.setNodeComparison(compare);
332 CbcCompareDefault compare;
333 model_.setNodeComparison(compare);
338 CbcCompareEstimate compare;
339 model_.setNodeComparison(compare);
341 model_.addHeuristic(guessHeu);
351 model_.passInTreeHandler(treeTraversal);
356 model_.passInTreeHandler(treeTraversal);
361 model_.passInTreeHandler(treeTraversal);
366 model_.passInTreeHandler(treeTraversal);
374 model_.setNodeComparison(compare);
379 model_.setNumberPenalties(8);
395 OsiObject ** objects =
model_.objects();
396 if (specOpt!=16 && objects) {
397 int numberObjects =
model_.numberObjects();
403 objects_ =
new OsiObject*[numberObjects];
405 for (
int i = 0 ; i < numberObjects; i++) {
406 OsiObject * obj = objects[i];
407 CbcSimpleInteger * intObj =
dynamic_cast<CbcSimpleInteger *
> (obj);
412 CbcSOS * sosObj =
dynamic_cast<CbcSOS *
>(obj);
415 CbcObject * cbcObj =
dynamic_cast<CbcObject *
>(obj);
417 std::cerr<<
"Unsupported CbcObject appears in the code"<<std::endl;
426 CbcCutGenerator ** gen =
model_.cutGenerators();
427 int numGen =
model_.numberCutGenerators();
428 for (
int i = 0 ; i < numGen ; i++) {
460 s.
options()->GetEnumValue(
"enable_dynamic_nlp", ival,
"bonmin.");
463 if(!
model_.solver()->isProvenOptimal() ){
475 std::vector<OsiRowCut *> mycuts(cuts.sizeRowCuts());
476 for(
int i = 0 ; i < cuts.sizeRowCuts() ; i++){
477 mycuts[i] = cuts.rowCutPtr(i);
479 model_.solver()->applyRowCuts((
int)mycuts.size(),
const_cast<const OsiRowCut **
>(&mycuts[0]));
487 model_.solver()->resolve();
495 const double * colsol =
model_.solver()->getColSolution();
496 const double * duals =
model_.solver()->getRowPrice();
502 model_.solver()->setColSolution(colsol);
504 model_.solver()->setRowPrice(duals);
513 #if 0 // Sometimes primal dual point is problematic in the context of Cut-and-branch
514 model_.solver()->resolve();
515 if(!
model_.solver()->isProvenOptimal())
516 model_.solver()->setColSolution(NULL);
522 remaining_time -= CoinCpuTime();
523 model_.setDblParam(CbcModel::CbcMaximumSeconds, remaining_time);
524 if(remaining_time > 0.)
541 bool hasFailed =
false;
548 throw CoinError(
"BonCbc",
"Bab",
"Inconsistent construction of model_ strategy is"
549 " not the right type.");
560 int numberGenerators =
model_.numberCutGenerators();
561 for (
int iGenerator=0;iGenerator<numberGenerators;iGenerator++) {
562 CbcCutGenerator * generator =
model_.cutGenerator(iGenerator);
564 if (
true&&!(generator->numberCutsInTotal() || generator->numberColumnCuts()))
568 <<
"was tried" << generator->numberTimesEntered()
569 <<
"times and created" << generator->numberCutsInTotal()+generator->numberColumnCuts()
570 <<
"cuts of which" << generator->numberCutsActive()
571 <<
"were active after adding rounds of cuts";
572 if (generator->timing()) {
574 sprintf(timebuf,
"(%.3fs)", generator->timeInCutGenerator());
585 <<
"************************************************************" << CoinMessageEol
586 <<
"WARNING : Optimization failed on an NLP during optimization" << CoinMessageEol
587 <<
" (no optimal value found within tolerances)." << CoinMessageEol
588 <<
" Optimization was not stopped because option" << CoinMessageEol
589 <<
"\"nlp_failure_behavior\" has been set to fathom but" << CoinMessageEol
590 <<
" beware that reported solution may not be optimal" << CoinMessageEol
591 <<
"************************************************************" << CoinMessageEol;
596 if (
model_.numberObjects()==0) {
599 OsiSolverInterface * solver =
602 if(! solver->isProvenOptimal()){
604 if ( solver->isProvenPrimalInfeasible () ) {
610 else if ( solver->isProvenDualInfeasible () ) {
624 CoinCopyN(solver->getColSolution(), solver->getNumCols(),
640 (*s.
nonlinearSolver()->messageHandler())<<
"\nReal objective function: "
641 <<bestObj_<<CoinMessageEol;
643 else if (
model_.bestSolution()) {
649 if(remaining_time <= 0.){
658 else if (
model_.status() == 0) {
659 if(
model_.isContinuousUnbounded()){
673 else if (
model_.status() == 1 ||
model_.status() == 5) {
682 else if (
model_.status()==2) {
int getIntParameter(const IntParameter &p) const
Return value of integer parameter.
Behavior of the algorithm in the case of a failure.
int nObjects_
number of objects.
double bestObj_
objValue of MIP
Max number of failures in a branch.
void initialize(BabSetupBase &b)
Initialize the method (get options)
Ipopt::SmartPtr< TMINLP > tminlp()
return pointer to tminlp_.
void setCbcModel(CbcModel *cbc_model)
Method for setting CbcModel, which is used to get statusOfSearch.
const vector< OsiObject * > & objects() const
Access to extra objects.
double getNewCutoffDecr()
Are there a numerical difficulties?
void setObjects(OsiObject **objects, int nObjects)
Set objects.
void initialize(BabSetupBase &b)
Initialize the method (get options)
static bool BonminInteruptedOnce
int mipIterationCount_
get total number of iterations in last mip solved.
const double * getDownPsCosts() const
Get number of columns.
This class chooses a variable to branch on.
int num
Number of SOS constraints.
CoinMessageHandler * modelHandler_
Message handler for CbcModel.
MipStatuses mipStatus_
Status of the mip solved.
const TMINLP2TNLP * problem() const
get pointer to the TMINLP2TNLP adapter
const double * getUpPsCosts() const
Get number of columns.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
Stop if relative gap is less than this.
virtual const SosInfo * sosConstraints() const =0
double maxLocalSearchTime_
maximum time for local searches
int has_x_init()
xInit has been set?
Spetial option in particular for Cbc.
Same as DfsDiveFromBest, but after a prescribed number of integer solution are found switch to best-b...
There is a CbcObject in the model which is not understood by Bonmin.
void setComparisonBound(const CbcCompareBase &val)
Set comparison method when closing bound.
void initialize(BabSetupBase &b)
Initialize the method (get options)
double * bestSolution_
Stores the solution of MIP.
Number of candidates for strong branching.
CbcModel model_
CbcModel used to solve problem.
Class to store sos constraints for model.
double continuousRelaxation_
Continuous relaxation of the problem.
void generateCuts(const OsiSolverInterface &solver, OsiCuts &cs, const CglTreeInfo info=CglTreeInfo())
int numNodes_
Number of nodes enumerated.
const int * getBranchingDirections() const
get prefered branching directions
const std::vector< double > & bestSolution2() const
get the best solution computed with alternative objective function.
virtual int getNumCols() const
Get number of columns.
void setup_global_time_limit(double time_limit)
Setup for a global time limit for solver.
const int * getPriorities() const
Get priorities on integer variables.
void setDiver(CbcDfsDiver *diver)
Set the dfs diver to use.
virtual void operator()(BabSetupBase &s)
operator() performs the branchAndBound
Dynamic strategy, see CbcBranchActual.hpp for explanations.
Minimum reliability before trust pseudo-costs.
From a TMINLP, this class adapts to another TMINLP where the original objective is transformed into a...
const Bonmin::TNLPSolver * solver() const
TreeTraversal treeTraversalMethod()
Method used to traverse tree.
virtual void replaceIntegers(OsiObject **objects, int numberObjects)
virtual callback function to eventually modify objects for integer variable (replace with user set)...
Class to perform OA in its classical form.
int * starts
For 0 <= i < nums, start[i] gives the indice of indices and weights arrays at which the description o...
void assignLpInterface(OsiSolverInterface *si)
Assign an OsiTMINLPInterface.
static CbcModel * currentBranchModel
A class to have all elements necessary to setup a branch-and-bound.
limit on number of integer feasible solution.
virtual void finalize_solution(TMINLP::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, Ipopt::Number obj_value)=0
This method is called when the algorithm is complete so the TNLP can store/write the solution...
SolverReturn
Return statuses of algorithm.
virtual bool setWarmStart(const CoinWarmStart *warm, Ipopt::SmartPtr< TMINLP2TNLP > tnlp)=0
Set the warm start in the solver.
static void signal_handler(int whichSignal)
Problem has been proven to be infeasible.
bool hasContinuedOnAFailure()
Did we continue on a failure.
A more elaborate diving class.
OsiChooseVariable * branchingMethod()
branching method to use.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
int * priorities
priorities of sos constraints.
double bestObj2() const
return objective value of the best solution computed with alternative objective function.
Display information every logIntervval nodes.
Max number of consecutive infeasible problem in a branch before fathoming.
dive from top node of the heap untill it gets to a leaf of the tree.
void forceSolverOutput(int log_level)
Bonmin::OACutGenerator2 * currentOA
Consider or not SOS constraints.
Log level for root relaxation.
NodeComparison & nodeComparisonMethod()
Method used to compare nodes.
double bestBound_
best known (lower) bound.
void setModel(Ipopt::SmartPtr< TMINLP > tminlp)
Set the model to be solved by interface.
void setBabPtr(Bab *babPtr)
Set pointer to the branch-and-bound algorithm (to access CbcModel).
Number of cut passes at nodes.
int * indices
indices of elements belonging to the SOS.
virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr< TMINLP2TNLP > tnlp) const =0
Get the warm start form the solver.
const TMINLP * model() const
void initialize(BabSetupBase &s)
virtual ~Bab()
destructor.
We will throw this error when a problem is not solved.
An integer solution to the problem has been found.
OsiTMINLPInterface * nonlinearSolver()
Pointer to the non-linear solver used.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
double getDoubleParameter(const DoubleParameter &p) const
Return value of double parameter.
No feasible solution to the problem is known.
Optimum solution has been found and its optimality proved.
OsiSolverInterface * continuousSolver()
Pointer to the continuous solver to use for relaxations.
Base class for OA algorithms.
HeuristicMethods & heuristics()
list of Heuristic methods to use.
dive from top node of the heap with more elaborate strategy (see options doc).
virtual void branchAndBound(BabSetupBase &s)
Perform a branch-and-bound using given setup.
double bestBound()
return the best known lower bound on the objective value
Eplore two kids before following on dive.
Number of cut passes at nodes.
Class to do probed diving in the tree.
void setComparisonDive(const CbcCompareBase &val)
Set comparison method when diving.
OsiObject ** objects_
OsiObjects of the model.
CuttingMethods & cutGenerators()
list of cutting planes methods to apply with their frequencies.
Class to do diving in the tree.
void setSolverOutputToDefault()
Stop if absolute gap is less than this.
Best guessed integer solution is subtree below, based on pseudo costs.
Bonmin class for passing info between components of branch-and-cuts.
double * weights
weights of the elements of the SOS.