summaryrefslogtreecommitdiff
path: root/newstructure/thirdparty/linux/include/coin/CbcStrategy.hpp
blob: a9c8d24a1a9b21e133cc439799528be98dfc5463 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* $Id: CbcStrategy.hpp 1573 2011-01-05 01:12:36Z lou $ */
// Copyright (C) 2005, International Business Machines
// Corporation and others.  All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).

#ifndef CbcStrategy_H
#define CbcStrategy_H

#include "CbcModel.hpp"
class CglPreProcess;
class CbcNodeInfo;
class CbcNode;
class CoinWarmStartDiff;

//#############################################################################
/** Strategy base class */

class CbcStrategy {
public:
    // Default Constructor
    CbcStrategy ();

    virtual ~CbcStrategy();

    /// Clone
    virtual CbcStrategy * clone() const = 0;

    /// Setup cut generators
    virtual void setupCutGenerators(CbcModel & model) = 0;
    /// Setup heuristics
    virtual void setupHeuristics(CbcModel & model) = 0;
    /// Do printing stuff
    virtual void setupPrinting(CbcModel & model, int modelLogLevel) = 0;
    /// Other stuff e.g. strong branching and preprocessing
    virtual void setupOther(CbcModel & model) = 0;
    /// Set model depth (i.e. how nested)
    inline void setNested(int depth) {
        depth_ = depth;
    }
    /// Get model depth (i.e. how nested)
    inline int getNested() const {
        return depth_;
    }
    /// Say preProcessing done
    inline void setPreProcessState(int state) {
        preProcessState_ = state;
    }
    /// See what sort of preprocessing was done
    inline int preProcessState() const {
        return preProcessState_;
    }
    /// Pre-processing object
    inline CglPreProcess * process() const {
        return process_;
    }
    /// Delete pre-processing object to save memory
    void deletePreProcess();
    /// Return a new Full node information pointer (descendant of CbcFullNodeInfo)
    virtual CbcNodeInfo * fullNodeInfo(CbcModel * model, int numberRowsAtContinuous) const;
    /// Return a new Partial node information pointer (descendant of CbcPartialNodeInfo)
    virtual CbcNodeInfo * partialNodeInfo(CbcModel * model, CbcNodeInfo * parent, CbcNode * owner,
                                          int numberChangedBounds, const int * variables,
                                          const double * boundChanges,
                                          const CoinWarmStartDiff *basisDiff) const;
    /// Create C++ lines to get to current state
    virtual void generateCpp( FILE * ) {}
    /** After a CbcModel::resolve this can return a status
        -1 no effect
        0 treat as optimal
        1 as 0 but do not do any more resolves (i.e. no more cuts)
        2 treat as infeasible
    */
    virtual int status(CbcModel * model, CbcNodeInfo * parent, int whereFrom);
private:

    /// Illegal Assignment operator
    CbcStrategy & operator=(const CbcStrategy& rhs);
protected:
    // Data
    /// Model depth
    int depth_;
    /** PreProcessing state -
        -1 infeasible
        0 off
        1 was done (so need post-processing)
    */
    int preProcessState_;
    /// If preprocessing then this is object
    CglPreProcess * process_;
};

/** Null class
 */

class CbcStrategyNull : public CbcStrategy {
public:

    // Default Constructor
    CbcStrategyNull () {}

    // Copy constructor
    CbcStrategyNull ( const CbcStrategyNull & rhs) : CbcStrategy(rhs) {}

    // Destructor
    ~CbcStrategyNull () {}

    /// Clone
    virtual CbcStrategy * clone() const {
        return new CbcStrategyNull(*this);
    }

    /// Setup cut generators
    virtual void setupCutGenerators(CbcModel & ) {}
    /// Setup heuristics
    virtual void setupHeuristics(CbcModel & ) {}
    /// Do printing stuff
    virtual void setupPrinting(CbcModel & , int ) {}
    /// Other stuff e.g. strong branching
    virtual void setupOther(CbcModel & ) {}

protected:
    // Data
private:
    /// Illegal Assignment operator
    CbcStrategyNull & operator=(const CbcStrategyNull& rhs);
};

/** Default class
 */

class CbcStrategyDefault : public CbcStrategy {
public:

    // Default Constructor
    CbcStrategyDefault (int cutsOnlyAtRoot = 1,
                        int numberStrong = 5,
                        int numberBeforeTrust = 0,
                        int printLevel = 0);

    // Copy constructor
    CbcStrategyDefault ( const CbcStrategyDefault &);

    // Destructor
    ~CbcStrategyDefault ();

    /// Clone
    virtual CbcStrategy * clone() const;

    /// Setup cut generators
    virtual void setupCutGenerators(CbcModel & model);
    /// Setup heuristics
    virtual void setupHeuristics(CbcModel & model);
    /// Do printing stuff
    virtual void setupPrinting(CbcModel & model, int modelLogLevel) ;
    /// Other stuff e.g. strong branching
    virtual void setupOther(CbcModel & model);
    /// Set up preProcessing - see below
    inline void setupPreProcessing(int desired = 1, int passes = 10) {
        desiredPreProcess_ = desired;
        preProcessPasses_ = passes;
    }
    /// See what sort of preprocessing wanted
    inline int desiredPreProcess() const {
        return desiredPreProcess_;
    }
    /// See how many passes wanted
    inline int preProcessPasses() const {
        return preProcessPasses_;
    }
    /// Create C++ lines to get to current state
    virtual void generateCpp( FILE * fp) ;

protected:
    // Data

    // Whether to do cuts only at root (-1 -> switch off totally)
    int cutsOnlyAtRoot_;

    // How much strong branching to do
    int numberStrong_;

    // Number branches needed to trust with dynamic pseudo costs
    int numberBeforeTrust_;

    // Print level 0 little, 1 medium
    int printLevel_;

    /** Desired pre-processing
        0 - none
        1 - ordinary
        2 - find sos
        3 - find cliques
        4 - more aggressive sos
        5 - add integer slacks
    */
    int desiredPreProcess_;
    /// Number of pre-processing passes
    int preProcessPasses_;

private:
    /// Illegal Assignment operator
    CbcStrategyDefault & operator=(const CbcStrategyDefault& rhs);
};


/** Default class for sub trees
 */

class CbcStrategyDefaultSubTree : public CbcStrategy {
public:

    // Default Constructor
    CbcStrategyDefaultSubTree (CbcModel * parent = NULL, int cutsOnlyAtRoot = 1,
                               int numberStrong = 5,
                               int numberBeforeTrust = 0,
                               int printLevel = 0);

    // Copy constructor
    CbcStrategyDefaultSubTree ( const CbcStrategyDefaultSubTree &);

    // Destructor
    ~CbcStrategyDefaultSubTree ();

    /// Clone
    virtual CbcStrategy * clone() const;

    /// Setup cut generators
    virtual void setupCutGenerators(CbcModel & model);
    /// Setup heuristics
    virtual void setupHeuristics(CbcModel & model);
    /// Do printing stuff
    virtual void setupPrinting(CbcModel & model, int modelLogLevel) ;
    /// Other stuff e.g. strong branching
    virtual void setupOther(CbcModel & model);
protected:
    // Data
    // Parent model
    CbcModel * parentModel_;
    // Whether to do cuts only at root (-1 -> switch off totally)
    int cutsOnlyAtRoot_;

    // How much strong branching to do
    int numberStrong_;

    // Number branches needed to trust with dynamic pseudo costs
    int numberBeforeTrust_;

    // Print level 0 little, 1 medium
    int printLevel_;

private:
    /// Illegal Assignment operator
    CbcStrategyDefaultSubTree & operator=(const CbcStrategyDefaultSubTree& rhs);
};


#endif