summaryrefslogtreecommitdiff
path: root/thirdparty/linux/include/coin/CbcCompareDefault.hpp
blob: 2d1ce8e604296b16fc5162130e8bee7289aa3c0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// $Id: CbcCompareDefault.hpp 1899 2013-04-09 18:12:08Z stefan $
// Copyright (C) 2002, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

//Edwin 11/25/09 carved out of CbcCompareActual

#ifndef CbcCompareDefault_H
#define CbcCompareDefault_H


//#############################################################################
/*  These are alternative strategies for node traversal.
    They can take data etc for fine tuning

    At present the node list is stored as a heap and the "test"
    comparison function returns true if node y is better than node x.

*/
#include "CbcNode.hpp"
#include "CbcCompareBase.hpp"
#include "CbcCompare.hpp"

class CbcModel;

/* This is an example of a more complex rule with data
   It is default after first solution
   If weight is 0.0 then it is computed to hit first solution
   less 5%
*/
class CbcCompareDefault  : public CbcCompareBase {
public:
    /// Default Constructor
    CbcCompareDefault () ;
    /// Constructor with weight
    CbcCompareDefault (double weight);

    /// Copy constructor
    CbcCompareDefault ( const CbcCompareDefault &rhs);

    /// Assignment operator
    CbcCompareDefault & operator=( const CbcCompareDefault& rhs);

    /// Clone
    virtual CbcCompareBase * clone() const;
    /// Create C++ lines to get to current state
    virtual void generateCpp( FILE * fp);

    ~CbcCompareDefault() ;
    /* This returns true if weighted value of node y is less than
       weighted value of node x */
    virtual bool test (CbcNode * x, CbcNode * y) ;

    using CbcCompareBase::newSolution ;
    /// This allows method to change behavior as it is called
    /// after each solution
    virtual bool newSolution(CbcModel * model,
                             double objectiveAtContinuous,
                             int numberInfeasibilitiesAtContinuous) ;
    /// This allows method to change behavior
    /// Return true if want tree re-sorted
    virtual bool every1000Nodes(CbcModel * model, int numberNodes);

    /* if weight == -1.0 then fewest infeasibilities (before solution)
       if -2.0 then do breadth first just for first 1000 nodes
       if -3.0 then depth first before solution
    */
    inline double getWeight() const {
        return weight_;
    }
    inline void setWeight(double weight) {
        weight_ = weight;
    }
    /// Cutoff
    inline double getCutoff() const {
        return cutoff_;
    }
    inline void setCutoff(double cutoff) {
        cutoff_ = cutoff;
    }
    /// Best possible solution
    inline double getBestPossible() const {
        return bestPossible_;
    }
    inline void setBestPossible(double bestPossible) {
        bestPossible_ = bestPossible;
    }
    /// Depth above which want to explore first
    inline void setBreadthDepth(int value) {
        breadthDepth_ = value;
    }
    /// Start dive
    void startDive(CbcModel * model);
    /// Clean up diving (i.e. switch off or prepare)
    void cleanDive();
protected:
    /// Weight for each infeasibility
    double weight_;
    /// Weight for each infeasibility - computed from solution
    double saveWeight_;
    /// Cutoff
    double cutoff_;
    /// Best possible solution
    double bestPossible_;
    /// Number of solutions
    int numberSolutions_;
    /// Tree size (at last check)
    int treeSize_;
    /// Depth above which want to explore first
    int breadthDepth_;
    /// Chosen node from estimated (-1 is off)
    int startNodeNumber_;
    /// Node number when dive started
    int afterNodeNumber_;
    /// Indicates doing setup for diving
    bool setupForDiving_ ;
};

#endif //CbcCompareDefault_H