source: trunk/include/CbcCompareBase.hpp @ 135

Last change on this file since 135 was 135, checked in by forrest, 14 years ago

starting dynamic pseudo costs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef CbcCompareBase_H
4#define CbcCompareBase_H
5
6
7//#############################################################################
8/*  These are alternative strategies for node traversal. 
9    They can take data etc for fine tuning
10
11    At present the node list is stored as a heap and the "test"
12    comparison function returns true if node y is better than node x.
13
14    This is rather inflexible so if the comparison functions wants
15    it can signal to use alternative criterion on a complete pass
16    throgh tree.
17
18*/
19#include "CbcNode.hpp"
20
21class CbcModel;
22class CbcTree;
23class CbcCompareBase {
24public:
25  // Default Constructor
26  CbcCompareBase () {test_=NULL;};
27
28  // This allows any method to change behavior as it is called
29  // after each solution
30  virtual void newSolution(CbcModel * model) {};
31
32  // This Also allows any method to change behavior as it is called
33  // after each solution
34  virtual void newSolution(CbcModel * model,
35                           double objectiveAtContinuous,
36                           int numberInfeasibilitiesAtContinuous) {};
37
38  // This allows any method to change behavior as it is called
39  // after every 1000 nodes.
40  // Return true if want tree re-sorted
41  virtual bool every1000Nodes(CbcModel * model,int numberNodes) {return false;};
42
43  /// Returns true if wants code to do scan with alternate criterion
44  virtual bool fullScan() const { return false;};
45
46  virtual ~CbcCompareBase() {};
47
48  // Copy constructor
49  CbcCompareBase ( const CbcCompareBase & rhs)
50  {test_=rhs.test_;};
51   
52  // Assignment operator
53  CbcCompareBase & operator=( const CbcCompareBase& rhs)
54  {  if (this!=&rhs) {test_=rhs.test_;}
55  return *this;
56  };
57
58  /// Clone
59  virtual CbcCompareBase * clone() const=0;
60
61  /// This is test function
62  virtual bool test (CbcNode * x, CbcNode * y) {return true;};
63
64  /// This is alternate test function
65  virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);};
66
67  bool operator() (CbcNode * x, CbcNode * y) {
68    return test(x,y);
69  }
70protected:
71  CbcCompareBase * test_;
72};
73class CbcCompare {
74public:
75  CbcCompareBase * test_;
76  // Default Constructor
77  CbcCompare () {test_=NULL;};
78
79  virtual ~CbcCompare() {};
80
81  bool operator() (CbcNode * x, CbcNode * y) {
82    return test_->test(x,y);
83  }
84  /// This is alternate test function
85  inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);};
86
87  /// return comparison object
88  inline CbcCompareBase * comparisonObject() const
89  { return test_;};
90};
91//#############################################################################
92/*  These can be alternative strategies for choosing variables
93    Any descendant can be passed in by setVariableChoice
94*/
95
96class CbcChooseVariable {
97public:
98  // Default Constructor
99  CbcChooseVariable () {};
100
101  virtual ~CbcChooseVariable() {};
102  /** If strong branching, then only those passed in (and movement is that length)
103      .  If not strong
104      branching then all passed in and ignore movement.
105      Returns which one chosen (or -1 if none).  way should be +1
106      if branching up, -1 if down */
107  virtual int chosen (const CbcModel * model,int numberToLookAt,
108                      const int * which, const double * downMovement,
109                      const double * upMovement, const double * solution,
110                      int & way, double & value)=0;
111
112};
113#endif
Note: See TracBrowser for help on using the repository browser.