source: trunk/Cbc/src/CbcCompareBase.hpp @ 354

Last change on this file since 354 was 354, checked in by ladanyi, 13 years ago

finished switch to subversion

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 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  /// Create C++ lines to get to current state
48  virtual void generateCpp( FILE * fp) {};
49
50  // Copy constructor
51  CbcCompareBase ( const CbcCompareBase & rhs)
52  {test_=rhs.test_;};
53   
54  // Assignment operator
55  CbcCompareBase & operator=( const CbcCompareBase& rhs)
56  {  if (this!=&rhs) {test_=rhs.test_;}
57  return *this;
58  };
59
60  /// Clone
61  virtual CbcCompareBase * clone() const=0;
62
63  /// This is test function
64  virtual bool test (CbcNode * x, CbcNode * y) {return true;};
65
66  /// This is alternate test function
67  virtual bool alternateTest (CbcNode * x, CbcNode * y) {return test(x,y);};
68
69  bool operator() (CbcNode * x, CbcNode * y) {
70    return test(x,y);
71  }
72protected:
73  CbcCompareBase * test_;
74};
75class CbcCompare {
76public:
77  CbcCompareBase * test_;
78  // Default Constructor
79  CbcCompare () {test_=NULL;};
80
81  virtual ~CbcCompare() {};
82
83  bool operator() (CbcNode * x, CbcNode * y) {
84    return test_->test(x,y);
85  }
86  /// This is alternate test function
87  inline bool alternateTest (CbcNode * x, CbcNode * y) {return test_->alternateTest(x,y);};
88
89  /// return comparison object
90  inline CbcCompareBase * comparisonObject() const
91  { return test_;};
92};
93//#############################################################################
94/*  These can be alternative strategies for choosing variables
95    Any descendant can be passed in by setVariableChoice
96*/
97
98class CbcChooseVariable {
99public:
100  // Default Constructor
101  CbcChooseVariable () {};
102
103  virtual ~CbcChooseVariable() {};
104  /** If strong branching, then only those passed in (and movement is that length)
105      .  If not strong
106      branching then all passed in and ignore movement.
107      Returns which one chosen (or -1 if none).  way should be +1
108      if branching up, -1 if down */
109  virtual int chosen (const CbcModel * model,int numberToLookAt,
110                      const int * which, const double * downMovement,
111                      const double * upMovement, const double * solution,
112                      int & way, double & value)=0;
113
114};
115#endif
Note: See TracBrowser for help on using the repository browser.