Cbc  2.10.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CbcTree.hpp
Go to the documentation of this file.
1 /* $Id: CbcTree.hpp 2467 2019-01-03 21:26:29Z unxusr $ */
2 // Copyright (C) 2004, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 #ifndef CbcTree_H
7 #define CbcTree_H
8 
9 #include <vector>
10 #include <algorithm>
11 #include <cmath>
12 
13 #include "CoinHelperFunctions.hpp"
14 #include "CbcCompare.hpp"
15 
29 //#define CBC_DUBIOUS_HEAP
30 #if defined(_MSC_VER) || defined(__MNO_CYGWIN)
31 //#define CBC_DUBIOUS_HEAP
32 #endif
33 #if 1 //ndef CBC_DUBIOUS_HEAP
34 
52 class CbcTree {
53 
54 public:
57  CbcTree();
59 
61  CbcTree(const CbcTree &rhs);
62 
64  CbcTree &operator=(const CbcTree &rhs);
65 
67  virtual ~CbcTree();
68 
70  virtual CbcTree *clone() const;
71 
73  virtual void generateCpp(FILE *) {}
75 
78  void setComparison(CbcCompareBase &compare);
80 
82  virtual CbcNode *top() const;
83 
85  virtual void push(CbcNode *x);
86 
88  virtual void pop();
89 
96  virtual CbcNode *bestNode(double cutoff);
97 
99  virtual void rebuild();
101 
104  virtual bool empty();
106 
108  virtual int size() const { return static_cast< int >(nodes_.size()); }
109 
111  inline CbcNode *operator[](int i) const { return nodes_[i]; }
112 
114  inline CbcNode *nodePointer(int i) const { return nodes_[i]; }
115  void realpop();
117  void fixTop();
118  void realpush(CbcNode *node);
120 
129  virtual void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective);
130 
133 
135  virtual void endSearch() {}
136 
138  virtual double getBestPossibleObjective();
139 
141  inline void resetNodeNumbers() { maximumNodeNumber_ = 0; }
142 
144  inline int maximumNodeNumber() const { return maximumNodeNumber_; }
145 
147  inline void setNumberBranching(int value) { numberBranching_ = value; }
148 
150  inline int getNumberBranching() const { return numberBranching_; }
151 
153  inline void setMaximumBranching(int value) { maximumBranching_ = value; }
154 
156  inline int getMaximumBranching() const { return maximumBranching_; }
157 
159  inline unsigned int *branched() const { return branched_; }
160 
162  inline int *newBounds() const { return newBound_; }
163 
165  inline double lastObjective() const
166  {
167  return lastObjective_;
168  }
170  inline int lastDepth() const
171  {
172  return lastDepth_;
173  }
175  inline int lastUnsatisfied() const
176  {
177  return lastUnsatisfied_;
178  }
180  void addBranchingInformation(const CbcModel *model, const CbcNodeInfo *nodeInfo,
181  const double *currentLower,
182  const double *currentUpper);
184  void increaseSpace();
186 
187 #if CBC_DEBUG_HEAP > 0
188 
191  void validateHeap();
193 #endif
194 
195 protected:
197  std::vector< CbcNode * > nodes_;
216  unsigned int *branched_;
218  int *newBound_;
219 };
220 
221 #ifdef JJF_ZERO // not used
222 
226 class CbcTreeArray : public CbcTree {
227 
228 public:
229  // Default Constructor
230  CbcTreeArray();
231 
232  // Copy constructor
233  CbcTreeArray(const CbcTreeArray &rhs);
234  // = operator
235  CbcTreeArray &operator=(const CbcTreeArray &rhs);
236 
237  virtual ~CbcTreeArray();
238 
240  virtual CbcTree *clone() const;
242  virtual void generateCpp(FILE *) {}
243 
246 
248  void setComparison(CbcCompareBase &compare);
249 
251  virtual void push(CbcNode *x);
252 
254  virtual CbcNode *bestNode(double cutoff);
255 
257 
259 
261  virtual bool empty();
262 
264 
267 
276  void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective);
278  virtual double getBestPossibleObjective();
280 protected:
283  CbcNode *lastNode_;
285  CbcNode *lastNodePopped_;
287  int switches_;
288 };
289 
291 #include "CoinSearchTree.hpp"
298 class CbcNewTree : public CbcTree, public CoinSearchTreeManager {
299 
300 public:
301  // Default Constructor
302  CbcNewTree();
303 
304  // Copy constructor
305  CbcNewTree(const CbcNewTree &rhs);
306  // = operator
307  CbcNewTree &operator=(const CbcNewTree &rhs);
308 
309  virtual ~CbcNewTree();
310 
312  virtual CbcNewTree *clone() const;
314  virtual void generateCpp(FILE *) {}
315 
318 
320  void setComparison(CbcCompareBase &compare);
321 
323  virtual CbcNode *top() const;
324 
326  virtual void push(CbcNode *x);
327 
329  virtual void pop();
331  virtual CbcNode *bestNode(double cutoff);
332 
334 
336 
338  virtual bool empty();
339 
341  inline int size() const
342  {
343  return nodes_.size();
344  }
345 
347  inline CbcNode *operator[](int i) const
348  {
349  return nodes_[i];
350  }
351 
353  inline CbcNode *nodePointer(int i) const
354  {
355  return nodes_[i];
356  }
357 
359 
362 
371  void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective);
372 
375 
377  virtual void endSearch() {}
379 protected:
380 };
381 #endif
382 #else
383 /* CBC_DUBIOUS_HEAP is defined
384 
385  See note at top of file. This code is highly suspect.
386  -- lh, 100921 --
387 */
388 class CbcTree {
389 
390 public:
391  // Default Constructor
392  CbcTree();
393 
394  // Copy constructor
395  CbcTree(const CbcTree &rhs);
396  // = operator
397  CbcTree &operator=(const CbcTree &rhs);
398 
399  virtual ~CbcTree();
400 
402  virtual CbcTree *clone() const;
404  virtual void generateCpp(FILE *fp) {}
405 
408 
410  void setComparison(CbcCompareBase &compare);
411 
413  virtual CbcNode *top() const;
414 
416  virtual void push(CbcNode *x);
417 
419  virtual void pop();
421  virtual CbcNode *bestNode(double cutoff);
422 
424 
426 
428  //virtual bool empty() ;
429 
431  inline int size() const
432  {
433  return nodes_.size();
434  }
435 
437  inline CbcNode *operator[](int i) const
438  {
439  return nodes_[i];
440  }
441 
443  inline CbcNode *nodePointer(int i) const
444  {
445  return nodes_[i];
446  }
447 
448  virtual bool empty();
449  //inline int size() const { return size_; }
450  void realpop();
452  void fixTop();
453  void realpush(CbcNode *node);
455 
458 
467  void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective);
468 
471 
473  virtual void endSearch() {}
475  inline void resetNodeNumbers()
476  {
477  maximumNodeNumber_ = 0;
478  }
479 
481  inline int maximumNodeNumber() const { return maximumNodeNumber_; }
483 protected:
484  std::vector< CbcNode * > nodes_;
486  int maximumNodeNumber_;
488 };
489 #endif
490 #endif
491 
492 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
493 */
virtual bool empty()
Test for an empty tree.
int * newBound_
New bound.
Definition: CbcTree.hpp:218
int getNumberBranching() const
Get number of branches.
Definition: CbcTree.hpp:150
CbcNode * bestAlternate()
Get best on list using alternate method.
std::vector< CbcNode * > nodes_
Storage vector for the heap.
Definition: CbcTree.hpp:197
double lastObjective_
Objective of last node pushed on tree.
Definition: CbcTree.hpp:207
virtual int size() const
Return size.
Definition: CbcTree.hpp:108
CbcTree()
Default Constructor.
virtual void push(CbcNode *x)
Add a node to the heap.
double lastObjective() const
Last objective in branch-and-cut search tree.
Definition: CbcTree.hpp:165
int maximumBranching_
Maximum size of variable list.
Definition: CbcTree.hpp:205
void fixTop()
After changing data in the top node, fix the heap.
void realpush(CbcNode *node)
unsigned int * branched_
Integer variables branched or bounded top bit set if new upper bound next bit set if a branch...
Definition: CbcTree.hpp:216
void setNumberBranching(int value)
Set number of branches.
Definition: CbcTree.hpp:147
void increaseSpace()
Increase space for data.
CbcTree & operator=(const CbcTree &rhs)
= operator
virtual void rebuild()
Rebuild the heap.
int maximumNodeNumber_
Maximum &quot;node&quot; number so far to split ties.
Definition: CbcTree.hpp:201
void realpop()
virtual CbcNode * bestNode(double cutoff)
Gets best node and takes off heap.
int lastDepth_
Depth of last node pushed on tree.
Definition: CbcTree.hpp:209
CbcNode * nodePointer(int i) const
Return a node pointer.
Definition: CbcTree.hpp:114
CbcNode * operator[](int i) const
Return a node pointer.
Definition: CbcTree.hpp:111
Using MS heap implementation.
Definition: CbcTree.hpp:52
virtual CbcTree * clone() const
Clone.
virtual void endSearch()
We may have got an intelligent tree so give it one more chance.
Definition: CbcTree.hpp:135
virtual void pop()
Remove the top node from the heap.
int lastUnsatisfied_
Number unsatisfied of last node pushed on tree.
Definition: CbcTree.hpp:211
int lastUnsatisfied() const
Last number of objects unsatisfied.
Definition: CbcTree.hpp:175
virtual CbcNode * top() const
Return the top node of the heap.
Information required while the node is live.
Definition: CbcNode.hpp:49
int getMaximumBranching() const
Get maximum branches.
Definition: CbcTree.hpp:156
virtual void cleanTree(CbcModel *model, double cutoff, double &bestPossibleObjective)
Prune the tree using an objective function cutoff.
void addBranchingInformation(const CbcModel *model, const CbcNodeInfo *nodeInfo, const double *currentLower, const double *currentUpper)
Adds branching information to complete state.
virtual void generateCpp(FILE *)
Create C++ lines to get to current state.
Definition: CbcTree.hpp:73
Information required to recreate the subproblem at this node.
Definition: CbcNodeInfo.hpp:68
void resetNodeNumbers()
Reset maximum node number.
Definition: CbcTree.hpp:141
int numberBranching_
Size of variable list.
Definition: CbcTree.hpp:203
CbcCompare comparison_
Sort predicate for heap ordering.
Definition: CbcTree.hpp:199
virtual ~CbcTree()
Destructor.
unsigned int * branched() const
Get branched variables.
Definition: CbcTree.hpp:159
void setComparison(CbcCompareBase &compare)
Set comparison function and resort heap.
int * newBounds() const
Get bounds.
Definition: CbcTree.hpp:162
int maximumNodeNumber() const
Get maximum node number.
Definition: CbcTree.hpp:144
virtual double getBestPossibleObjective()
Get best possible objective function in the tree.
Simple Branch and bound class.
Definition: CbcModel.hpp:100
void setMaximumBranching(int value)
Set maximum branches.
Definition: CbcTree.hpp:153
int lastDepth() const
Last depth in branch-and-cut search tree.
Definition: CbcTree.hpp:170