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

Last change on this file since 1424 was 1400, checked in by lou, 10 years ago

Add a final blank line; hudson test server seems to want it.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: CbcCompareBase.hpp 1400 2009-12-11 14:14:06Z 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 () {
29        test_ = NULL;
30        threaded_ = false;
31    }
32
33    // This allows any method to change behavior as it is called
34    // after each solution
35    virtual void newSolution(CbcModel * ) {}
36
37    // This Also allows any method to change behavior as it is called
38    // after each solution
39    virtual void newSolution(CbcModel * ,
40                             double ,
41                             int ) {}
42
43    // This allows any method to change behavior as it is called
44    // after every 1000 nodes.
45    // Return true if want tree re-sorted
46    virtual bool every1000Nodes(CbcModel * , int ) {
47        return false;
48    }
49
50    /** Returns true if wants code to do scan with alternate criterion
51        NOTE - this is temporarily disabled
52    */
53    virtual bool fullScan() const {
54        return false;
55    }
56
57    virtual ~CbcCompareBase() {}
58    /// Create C++ lines to get to current state
59    virtual void generateCpp( FILE * ) {}
60
61    // Copy constructor
62    CbcCompareBase ( const CbcCompareBase & rhs) {
63        test_ = rhs.test_;
64        threaded_ = rhs.threaded_;
65    }
66
67    // Assignment operator
68    CbcCompareBase & operator=( const CbcCompareBase& rhs) {
69        if (this != &rhs) {
70            test_ = rhs.test_;
71            threaded_ = rhs.threaded_;
72        }
73        return *this;
74    }
75
76    /// Clone
77    virtual CbcCompareBase * clone() const {
78        abort();
79        return NULL;
80    }
81
82    /// This is test function
83    virtual bool test (CbcNode * , CbcNode * ) {
84        return true;
85    }
86
87    /// This is alternate test function
88    virtual bool alternateTest (CbcNode * x, CbcNode * y) {
89        return test(x, y);
90    }
91
92    bool operator() (CbcNode * x, CbcNode * y) {
93        return test(x, y);
94    }
95    /// Further test if everything else equal
96    inline bool equalityTest (CbcNode * x, CbcNode * y) const {
97        assert (x);
98        assert (y);
99        if (!threaded_) {
100            CbcNodeInfo * infoX = x->nodeInfo();
101            assert (infoX);
102            int nodeNumberX = infoX->nodeNumber();
103            CbcNodeInfo * infoY = y->nodeInfo();
104            assert (infoY);
105            int nodeNumberY = infoY->nodeNumber();
106            assert (nodeNumberX != nodeNumberY);
107            return (nodeNumberX > nodeNumberY);
108        } else {
109            assert (x->nodeNumber() != y->nodeNumber());
110            return (x->nodeNumber() > y->nodeNumber());
111        }
112    }
113    /// Say threaded
114    inline void sayThreaded() {
115        threaded_ = true;
116    }
117protected:
118    CbcCompareBase * test_;
119    // If not threaded we can use better way to break ties
120    bool threaded_;
121};
122
123#endif
124
Note: See TracBrowser for help on using the repository browser.