Bonmin  1.8.8
BonDiver.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 09/01/2007
9 
10 #ifndef BonDiver_H
11 #define BonDiver_H
12 
13 #include "BonminConfig.h"
14 #include "CbcCompareBase.hpp"
15 #include "CbcTree.hpp"
16 #include "IpRegOptions.hpp"
17 #include "IpOptionsList.hpp"
18 #include "CbcCompareActual.hpp"
19 #include "BonRegisteredOptions.hpp"
20 #include <list>
21 namespace Bonmin
22 {
23  class BabSetupBase;
26  class CbcDiver : public CbcTree
27  {
28  public:
30  CbcDiver();
31 
33  CbcDiver(const CbcDiver &rhs);
34 
36  CbcDiver & operator=(const CbcDiver &rhs);
37 
39  virtual ~CbcDiver();
40 
42  virtual CbcTree * clone() const;
43 
46  virtual CbcNode * top() const;
48 
50  virtual void push(CbcNode * x);
52  virtual void pop();
54  virtual CbcNode * bestNode(double cutoff);
57 
60  virtual bool empty();
62  virtual int size()
63  {
64  return (static_cast<int>(nodes_.size()) + (nextOnBranch_ != NULL) );
65  }
75  virtual void cleanTree(CbcModel * model, double cutoff, double & bestPossibleObjective);
76 
78  virtual double getBestPossibleObjective();
79 
80 
82  virtual void endSearch()
83  {
84  nextOnBranch_ = NULL;
85  }
86 
88  static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
89 
91  void initialize(BabSetupBase &b);
92 
93  private:
97  CbcNode * nextOnBranch_;
101  };
102 
103 
108  class CbcProbedDiver : public CbcTree
109  {
110  public:
112  CbcProbedDiver();
113 
115  CbcProbedDiver(const CbcProbedDiver &rhs);
116 
119 
121  virtual ~CbcProbedDiver();
122 
124  virtual CbcTree * clone() const;
125 
128  virtual CbcNode * top() const;
130 
132  virtual void push(CbcNode * x);
134  virtual void pop();
136  virtual CbcNode * bestNode(double cutoff);
139 
142  virtual bool empty();
144  virtual int size()
145  {
146  return (static_cast<int>(nodes_.size()) + (nextOnBranch_ != NULL) + (candidateChild_ != NULL) );
147  }
157  virtual void cleanTree(CbcModel * model, double cutoff, double & bestPossibleObjective);
158 
160  virtual double getBestPossibleObjective();
161 
162 
164  virtual void endSearch()
165  {
166  nextOnBranch_ = NULL;
167  }
168 
170  void initialize(BabSetupBase &b);
171 
172  private:
176  CbcNode * nextOnBranch_;
178  CbcNode * candidateChild_;
182  };
183 
184 
199  class CbcDfsDiver :public CbcTree
200  {
201  public:
208  CbcDfsDiver();
209 
211  CbcDfsDiver(const CbcDfsDiver &rhs);
212 
214  CbcDfsDiver & operator=(const CbcDfsDiver &rhs);
215 
217  virtual ~CbcDfsDiver();
218 
220  virtual CbcTree * clone() const;
221 
224  virtual CbcNode * top() const;
226 
228  virtual void push(CbcNode * x);
230  virtual void pop();
232  virtual CbcNode * bestNode(double cutoff);
235 
238  virtual bool empty();
240  virtual int size()
241  {
242  return static_cast<int>(nodes_.size()) + diveListSize_;
243  }
254  virtual void cleanTree(CbcModel * model, double cutoff, double & bestPossibleObjective);
255 
257  virtual double getBestPossibleObjective();
258 
259 //#ifdef COIN_HAS_BONMIN
261  static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
262 
264  void initialize(BabSetupBase &b);
265 //#endif
267  virtual void endSearch()
268  {}
269 
272  void setComparisonMode(ComparisonModes newMode);
275  {
276  return mode_;
277  }
278  protected:
283  std::list<CbcNode *> dive_;
289  double cutoff_;
303  private:
305  void pushDiveOntoHeap(double cutoff);
306 
307  };
308 
309  class DiverCompare : public CbcCompareBase
310  {
311  public:
312  // Default Constructor
314  CbcCompareBase(),
315  diver_(NULL),
318  comparisonDive_(NULL),
319  comparisonBound_(NULL)
320  {}
321 
322 
323  virtual ~DiverCompare()
324  {
325  delete comparisonDive_;
326  delete comparisonBound_;
327  }
328 
329  // Copy constructor
330  DiverCompare ( const DiverCompare & rhs):
331  CbcCompareBase(rhs),
332  diver_(rhs.diver_),
337  {}
338 
339  // Assignment operator
341  {
342  if (this != &rhs) {
343  CbcCompareBase::operator=(rhs);
344  diver_ = rhs.diver_;
347  delete comparisonDive_;
348  delete comparisonBound_;
349  comparisonDive_ = NULL;
350  comparisonBound_ = NULL;
351  if (rhs.comparisonDive_) comparisonDive_ = rhs.comparisonDive_->clone();
352  if (rhs.comparisonBound_) comparisonBound_ = rhs.comparisonBound_->clone();
353  }
354  return *this;
355  }
356 
358  virtual CbcCompareBase * clone() const
359  {
360  return new DiverCompare(*this);
361  }
362 
364  virtual bool test (CbcNode * x, CbcNode * y);
365 
367  virtual bool newSolution(CbcModel * model);
368 
370  virtual bool newSolution(CbcModel * model,
371  double objectiveAtContinuous,
372  int numberInfeasibilitiesAtContinuous);
373 
376  virtual bool every1000Nodes(CbcModel * model,int numberNodes);
377 
379  void setDiver(CbcDfsDiver * diver)
380  {
381  diver_ = diver;
382  }
383 
386  {
387  numberSolToStopDive_ = val;
388  }
389 
392  {
394  }
395 
397  void setComparisonDive(const CbcCompareBase & val)
398  {
399  comparisonDive_ = val.clone();
400  }
402  void setComparisonBound(const CbcCompareBase & val)
403  {
404  comparisonBound_ = val.clone();
405  }
406  private:
414  CbcCompareBase * comparisonDive_;
416  CbcCompareBase * comparisonBound_;
418  CbcCompareDepth comparisonDepth_;
419  };
420 
421 }/* Ends bonmin namespace.*/
422 
423 #endif
424 
virtual void pop()
Remove the top node of the heap.
void initialize(BabSetupBase &b)
Initialize the method (get options)
void setComparisonMode(ComparisonModes newMode)
Changes the mode of comparison of the tree for &quot;safety reasons&quot; if the mode really changes we always ...
bool treeCleaning_
Say if we are cleaning the tree (then only call CbcTree functions).
Definition: BonDiver.hpp:174
CbcDiver()
Default constructor.
virtual void pop()
Remove the top node of the heap.
void initialize(BabSetupBase &b)
Initialize the method (get options)
virtual CbcNode * top() const
Return top node (next node to process.*/.
CbcNode * candidateChild_
Candidate child explored.
Definition: BonDiver.hpp:178
virtual double getBestPossibleObjective()
Get best possible objective function in the tree.
virtual ~CbcDfsDiver()
Destructor.
virtual CbcCompareBase * clone() const
Clone.
Definition: BonDiver.hpp:358
virtual void push(CbcNode *x)
Add node to the heap.
virtual bool empty()
Test if empty.
double cutoff_
Last reported cutoff.
Definition: BonDiver.hpp:289
virtual void pop()
Remove the top node of the heap.
std::list< CbcNode * > dive_
List of the nodes in the current dive.
Definition: BonDiver.hpp:283
CbcCompareBase * comparisonDive_
Comparison method used in diving mode.
Definition: BonDiver.hpp:414
void setComparisonBound(const CbcCompareBase &val)
Set comparison method when closing bound.
Definition: BonDiver.hpp:402
void initialize(BabSetupBase &b)
Initialize the method (get options)
virtual CbcNode * bestNode(double cutoff)
Remove the best node from the heap and return it.
bool treeCleaning_
Say if we are cleaning the tree (then only call CbcTree functions).
Definition: BonDiver.hpp:95
DiverCompare(const DiverCompare &rhs)
Definition: BonDiver.hpp:330
int nBacktracks_
number of backtracks done in current dive.
Definition: BonDiver.hpp:291
virtual bool every1000Nodes(CbcModel *model, int numberNodes)
Called 1000 nodes.
int treeCleaning_
Flag to say that we are currently cleaning the tree and should work only on the heap.
Definition: BonDiver.hpp:281
CbcNode * nextOnBranch_
Noext node on the branch.
Definition: BonDiver.hpp:97
void setDiver(CbcDfsDiver *diver)
Set the dfs diver to use.
Definition: BonDiver.hpp:379
virtual bool test(CbcNode *x, CbcNode *y)
This is test function.
virtual CbcTree * clone() const
Virtual copy constructor.
A class to have all elements necessary to setup a branch-and-bound.
DiverCompare & operator=(const DiverCompare &rhs)
Definition: BonDiver.hpp:340
virtual void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective)
Prune the tree using an objective function cutoff.
CbcDfsDiver * diver_
Pointer to the CbcDfsDiver handling the tree.
Definition: BonDiver.hpp:408
int maxDiveBacktracks_
Maximum number of backtrack in one dive.
Definition: BonDiver.hpp:297
bool stop_diving_on_cutoff_
Flag indicating if we want to stop diving based on the guessed objective value and the cutoff value ...
Definition: BonDiver.hpp:181
int maxDepthBFS_
Maximum depth until which we&#39;ll do a bredth-first-search.
Definition: BonDiver.hpp:295
virtual CbcNode * bestNode(double cutoff)
Remove the best node from the heap and return it.
virtual ~CbcProbedDiver()
Destructor.
virtual CbcTree * clone() const
Virtual copy constructor.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options of the method.
virtual ~DiverCompare()
Definition: BonDiver.hpp:323
CbcProbedDiver & operator=(const CbcProbedDiver &rhs)
Assignment operator.
A more elaborate diving class.
Definition: BonDiver.hpp:199
CbcDfsDiver()
Default constructor.
ComparisonModes getComparisonMode()
get the mode of comparison of the tree.
Definition: BonDiver.hpp:274
virtual int size()
Give size of the tree.
Definition: BonDiver.hpp:62
void setNumberNodesToLimitTreeSize(int val)
Set numberNodesToLimitTreeSize_.
Definition: BonDiver.hpp:391
ComparisonModes mode_
Current mode of the diving strategy.
Definition: BonDiver.hpp:301
CbcDiver & operator=(const CbcDiver &rhs)
Assignment operator.
virtual bool empty()
Test if empty.
virtual void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective)
Prune the tree using an objective function cutoff.
int numberNodesToLimitTreeSize_
Number of nodes before we command diver_ to limit the tree size.
Definition: BonDiver.hpp:412
virtual void endSearch()
Don&#39;t know what this is yet?
Definition: BonDiver.hpp:82
At the very beginning we might want to enlarge the tree just a bit.
Definition: BonDiver.hpp:203
CbcProbedDiver()
Default constructor.
virtual CbcNode * top() const
Return top node (next node to process.*/.
bool stop_diving_on_cutoff_
Flag indicating if we want to stop diving based on the guessed objective value and the cutoff value ...
Definition: BonDiver.hpp:100
virtual void endSearch()
Don&#39;t know what this is yet?
Definition: BonDiver.hpp:267
virtual CbcNode * bestNode(double cutoff)
Remove the best node from the heap and return it.
virtual bool empty()
Test if empty.
virtual void endSearch()
Don&#39;t know what this is yet?
Definition: BonDiver.hpp:164
int divingBoardDepth_
Depth of the node from which diving was started (we call this node the diving board).
Definition: BonDiver.hpp:287
virtual void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective)
Prune the tree using an objective function cutoff.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options of the method.
CbcCompareBase * comparisonBound_
Comparison method used bound mode.
Definition: BonDiver.hpp:416
void setNumberSolToStopDive(int val)
Set numberSolToStopDive_.
Definition: BonDiver.hpp:385
virtual double getBestPossibleObjective()
Get best possible objective function in the tree.
CbcCompareDepth comparisonDepth_
Comparison method used when limit tree size.
Definition: BonDiver.hpp:418
virtual CbcNode * top() const
Return top node (next node to process.*/.
CbcDfsDiver & operator=(const CbcDfsDiver &rhs)
Assignment operator.
virtual double getBestPossibleObjective()
Get best possible objective function in the tree.
int numberSolToStopDive_
Number of solution before we command diver_ to stop diving.
Definition: BonDiver.hpp:410
virtual int size()
Give size of the tree.
Definition: BonDiver.hpp:144
void pushDiveOntoHeap(double cutoff)
Pushes onto heap all the nodes with objective value &gt; cutoff.
virtual void push(CbcNode *x)
Add node to the heap.
Class to do probed diving in the tree.
Definition: BonDiver.hpp:108
void setComparisonDive(const CbcCompareBase &val)
Set comparison method when diving.
Definition: BonDiver.hpp:397
CbcNode * nextOnBranch_
Next node on the branch.
Definition: BonDiver.hpp:176
virtual int size()
Give size of the tree.
Definition: BonDiver.hpp:240
virtual bool newSolution(CbcModel *model)
Called after each new solution.
Class to do diving in the tree.
Definition: BonDiver.hpp:26
virtual CbcTree * clone() const
Virtual copy constructor.
int diveListSize_
Record dive list size for constant time access.
Definition: BonDiver.hpp:285
virtual void push(CbcNode *x)
Add node to the heap.
int maxDiveDepth_
Maximum depth to go from divingBoard.
Definition: BonDiver.hpp:299
virtual ~CbcDiver()
Destructor.