source: stable/2.4/Cbc/src/CbcCompareBase.hpp @ 1271

Last change on this file since 1271 was 1271, checked in by forrest, 10 years ago

Creating new stable branch 2.4 from trunk (rev 1270)

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