Debian Codegraph @

Bonmin/src/CbcBonmin/BonCbcNode.cpp

raw
1 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // John J. Forrest, International Business Machines Corporation
7 // P. Bonami, Carnegie Mellon University,
8 //
9 // Date : 03/15/2006
10
11
12 #include <string>
13 #include <cassert>
14 #include <cfloat>
15 #include "CoinPragma.hpp"
16 #include "OsiSolverInterface.hpp"
17 #include "CoinWarmStartBasis.hpp"
18 #include "CbcModel.hpp"
19 #include "BonCbcNode.hpp"
20 #include "BonOsiTMINLPInterface.hpp"
21 #include "BonIpoptWarmStart.hpp"
22 #include "BonOsiTMINLPInterface.hpp"
23
24 using namespace std;
25
26
27 namespace Bonmin
28 {
29 //Default constructor
30 BonCbcFullNodeInfo::BonCbcFullNodeInfo()
31 :
32 CbcFullNodeInfo(),
33 sequenceOfInfeasiblesSize_(0),
34 sequenceOfUnsolvedSize_(0)
35 {}
36
37 BonCbcFullNodeInfo::BonCbcFullNodeInfo(CbcModel * model,
38 int numberRowsAtContinuous) :
39 CbcFullNodeInfo(model, numberRowsAtContinuous),
40 sequenceOfInfeasiblesSize_(0),
41 sequenceOfUnsolvedSize_(0)
42 {}
43
44 // Copy constructor
45 BonCbcFullNodeInfo::BonCbcFullNodeInfo ( const BonCbcFullNodeInfo &other):
46 CbcFullNodeInfo(other),
47 sequenceOfInfeasiblesSize_(other.sequenceOfInfeasiblesSize_),
48 sequenceOfUnsolvedSize_(other.sequenceOfUnsolvedSize_)
49
50 {}
51
52
53 void
54 BonCbcFullNodeInfo::allBranchesGone()
55 {
56 IpoptWarmStart * ipws = dynamic_cast<IpoptWarmStart *>(basis_);
57 if (ipws)
58 ipws->flushPoint();
59 }
60
61 BonCbcFullNodeInfo::~BonCbcFullNodeInfo()
62 {}
63
64 CbcNodeInfo *
65 BonCbcFullNodeInfo::clone() const
66 {
67 return new BonCbcFullNodeInfo(*this);
68 }
69
70 void
71 BonCbcFullNodeInfo::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
72 {
73
74
75 roptions->SetRegisteringCategory("Nonconvex problems", RegisteredOptions::BonminCategory);
76 roptions->AddLowerBoundedIntegerOption("max_consecutive_infeasible",
77 "Number of consecutive infeasible subproblems before aborting a"
78 " branch.",
79 0,0,
80 "Will continue exploring a branch of the tree until \"max_consecutive_infeasible\""
81 "consecutive problems are locally infeasible by the NLP sub-solver.");
82 roptions->setOptionExtraInfo("max_consecutive_infeasible",8);
83
84 roptions->SetRegisteringCategory("NLP solution robustness", RegisteredOptions::BonminCategory);
85 roptions->AddLowerBoundedIntegerOption
86 ("max_consecutive_failures",
87 "(temporarily removed) Number $n$ of consecutive unsolved problems before aborting a branch of the tree.",
88 0,10,
89 "When $n > 0$, continue exploring a branch of the tree until $n$ "
90 "consecutive problems in the branch are unsolved (we call unsolved a problem for which Ipopt can not "
91 "guarantee optimality within the specified tolerances).");
92 roptions->setOptionExtraInfo("max_consecutive_failures",8);
93
94 }
95
96
97 /****************************************************************************************************/
98
99 // Default constructor
100 BonCbcPartialNodeInfo::BonCbcPartialNodeInfo ()
101 : CbcPartialNodeInfo(),
102 sequenceOfInfeasiblesSize_(0),
103 sequenceOfUnsolvedSize_(0)
104 {}
105 // Constructor from current state
106 BonCbcPartialNodeInfo::BonCbcPartialNodeInfo (CbcModel * model,CbcNodeInfo *parent, CbcNode *owner,
107 int numberChangedBounds,
108 const int *variables,
109 const double *boundChanges,
110 const CoinWarmStartDiff *basisDiff)
111 : CbcPartialNodeInfo(parent,owner,numberChangedBounds,variables,
112 boundChanges,basisDiff),
113 sequenceOfInfeasiblesSize_(0),
114 sequenceOfUnsolvedSize_(0)
115 {
116 BonCbcPartialNodeInfo * nlpParent = dynamic_cast<BonCbcPartialNodeInfo *> (parent);
117 int numberInfeasible = 0;
118 int numberUnsolved = 0;
119 if (nlpParent)//father is not root
120 {
121 numberInfeasible = nlpParent->getSequenceOfInfeasiblesSize();
122 numberUnsolved = nlpParent->getSequenceOfUnsolvedSize();
123 // if(!nlpParent->numberBranchesLeft_){
124 // IpoptWarmStartDiff * ipws = dynamic_cast<IpoptWarmStartDiff *>(nlpParent->basisDiff_);
125 // ipws->flushPoint();
126 // }
127 }
128 else {
129 BonCbcFullNodeInfo * nlpRoot = dynamic_cast<BonCbcFullNodeInfo *> (parent);
130 if (nlpRoot) {
131 numberInfeasible = nlpRoot->getSequenceOfInfeasiblesSize();
132 numberUnsolved = nlpRoot->getSequenceOfUnsolvedSize();
133 }
134 }
135 if (model->solver()->isAbandoned() ||
136 model->solver()->isIterationLimitReached())
137 sequenceOfUnsolvedSize_ = numberUnsolved + 1;
138
139 if (model->solver()->isProvenPrimalInfeasible())
140 sequenceOfInfeasiblesSize_ = numberInfeasible + 1;
141 }
142
143 BonCbcPartialNodeInfo::BonCbcPartialNodeInfo (const BonCbcPartialNodeInfo & rhs)
144
145 : CbcPartialNodeInfo(rhs),
146 sequenceOfInfeasiblesSize_(rhs.sequenceOfInfeasiblesSize_),
147 sequenceOfUnsolvedSize_(rhs.sequenceOfUnsolvedSize_)
148
149 {}
150
151 CbcNodeInfo *
152 BonCbcPartialNodeInfo::clone() const
153 {
154 return (new BonCbcPartialNodeInfo(*this));
155 }
156
157 void
158 BonCbcPartialNodeInfo::allBranchesGone()
159 {
160 IpoptWarmStartDiff * ipws = dynamic_cast<IpoptWarmStartDiff *>(basisDiff_);
161 if (ipws)
162 ipws->flushPoint();
163 }
164
165 BonCbcPartialNodeInfo::~BonCbcPartialNodeInfo ()
166 {}
167 }