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

Last change on this file since 2464 was 2464, checked in by unxusr, 7 months ago

.clang-format with proposal for formatting code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: CbcCompareBase.hpp 2464 2019-01-03 19:03:23Z unxusr $ */
2// Copyright (C) 2002, 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 CbcCompareBase_H
7#define CbcCompareBase_H
8
9//#############################################################################
10/*  These are alternative strategies for node traversal.
11    They can take data etc for fine tuning
12
13    At present the node list is stored as a heap and the "test"
14    comparison function returns true if node y is better than node x.
15
16    This is rather inflexible so if the comparison functions wants
17    it can signal to use alternative criterion on a complete pass
18    throgh tree.
19
20*/
21#include "CbcNode.hpp"
22#include "CbcConfig.h"
23
24class CbcModel;
25class CbcTree;
26class CbcCompareBase {
27public:
28  // Default Constructor
29  CbcCompareBase()
30  {
31    test_ = NULL;
32    threaded_ = false;
33  }
34
35  /*! \brief Reconsider behaviour after discovering a new solution.
36   
37      This allows any method to change its behaviour. It is called
38      after each solution.
39
40      The method should return true if changes are made which will
41      alter the evaluation criteria applied to a node. (So that in
42      cases where the search tree is sorted, it can be properly
43      rebuilt.)
44    */
45  virtual bool newSolution(CbcModel *) { return (false); }
46
47  /*! \brief Reconsider behaviour after discovering a new solution.
48   
49      This allows any method to change its behaviour. It is called
50      after each solution.
51
52      The method should return true if changes are made which will
53      alter the evaluation criteria applied to a node. (So that in
54      cases where the search tree is sorted, it can be properly
55      rebuilt.)
56    */
57  virtual bool newSolution(CbcModel *,
58    double,
59    int) { return (false); }
60
61  // This allows any method to change behavior as it is called
62  // after every 1000 nodes.
63  // Return true if want tree re-sorted
64  virtual bool every1000Nodes(CbcModel *, int)
65  {
66    return false;
67  }
68
69  /** Returns true if wants code to do scan with alternate criterion
70        NOTE - this is temporarily disabled
71    */
72  virtual bool fullScan() const
73  {
74    return false;
75  }
76
77  virtual ~CbcCompareBase() {}
78  /// Create C++ lines to get to current state
79  virtual void generateCpp(FILE *) {}
80
81  // Copy constructor
82  CbcCompareBase(const CbcCompareBase &rhs)
83  {
84    test_ = rhs.test_;
85    threaded_ = rhs.threaded_;
86  }
87
88  // Assignment operator
89  CbcCompareBase &operator=(const CbcCompareBase &rhs)
90  {
91    if (this != &rhs) {
92      test_ = rhs.test_;
93      threaded_ = rhs.threaded_;
94    }
95    return *this;
96  }
97
98  /// Clone
99  virtual CbcCompareBase *clone() const
100  {
101    abort();
102    return NULL;
103  }
104
105  /// This is test function
106  virtual bool test(CbcNode *, CbcNode *)
107  {
108    return true;
109  }
110
111  /// This is alternate test function
112  virtual bool alternateTest(CbcNode *x, CbcNode *y)
113  {
114    return test(x, y);
115  }
116
117  bool operator()(CbcNode *x, CbcNode *y)
118  {
119    return test(x, y);
120  }
121  /// Further test if everything else equal
122  inline bool equalityTest(CbcNode *x, CbcNode *y) const
123  {
124    assert(x);
125    assert(y);
126    if (!threaded_) {
127      CbcNodeInfo *infoX = x->nodeInfo();
128      assert(infoX);
129      int nodeNumberX = infoX->nodeNumber();
130      CbcNodeInfo *infoY = y->nodeInfo();
131      assert(infoY);
132      int nodeNumberY = infoY->nodeNumber();
133      assert(nodeNumberX != nodeNumberY);
134      return (nodeNumberX > nodeNumberY);
135    } else {
136      assert(x->nodeNumber() != y->nodeNumber());
137      return (x->nodeNumber() > y->nodeNumber());
138    }
139  }
140  /// Say threaded
141  inline void sayThreaded()
142  {
143    threaded_ = true;
144  }
145
146protected:
147  CbcCompareBase *test_;
148  // If not threaded we can use better way to break ties
149  bool threaded_;
150};
151
152#endif
Note: See TracBrowser for help on using the repository browser.