source: stable/2.7/Cbc/src/CbcStrategy.hpp @ 2081

Last change on this file since 2081 was 1573, checked in by lou, 9 years ago

Change to EPL license notice.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: CbcStrategy.hpp 1573 2011-01-05 01:12:36Z forrest $ */
2// Copyright (C) 2005, 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 CbcStrategy_H
7#define CbcStrategy_H
8
9#include "CbcModel.hpp"
10class CglPreProcess;
11class CbcNodeInfo;
12class CbcNode;
13class CoinWarmStartDiff;
14
15//#############################################################################
16/** Strategy base class */
17
18class CbcStrategy {
19public:
20    // Default Constructor
21    CbcStrategy ();
22
23    virtual ~CbcStrategy();
24
25    /// Clone
26    virtual CbcStrategy * clone() const = 0;
27
28    /// Setup cut generators
29    virtual void setupCutGenerators(CbcModel & model) = 0;
30    /// Setup heuristics
31    virtual void setupHeuristics(CbcModel & model) = 0;
32    /// Do printing stuff
33    virtual void setupPrinting(CbcModel & model, int modelLogLevel) = 0;
34    /// Other stuff e.g. strong branching and preprocessing
35    virtual void setupOther(CbcModel & model) = 0;
36    /// Set model depth (i.e. how nested)
37    inline void setNested(int depth) {
38        depth_ = depth;
39    }
40    /// Get model depth (i.e. how nested)
41    inline int getNested() const {
42        return depth_;
43    }
44    /// Say preProcessing done
45    inline void setPreProcessState(int state) {
46        preProcessState_ = state;
47    }
48    /// See what sort of preprocessing was done
49    inline int preProcessState() const {
50        return preProcessState_;
51    }
52    /// Pre-processing object
53    inline CglPreProcess * process() const {
54        return process_;
55    }
56    /// Delete pre-processing object to save memory
57    void deletePreProcess();
58    /// Return a new Full node information pointer (descendant of CbcFullNodeInfo)
59    virtual CbcNodeInfo * fullNodeInfo(CbcModel * model, int numberRowsAtContinuous) const;
60    /// Return a new Partial node information pointer (descendant of CbcPartialNodeInfo)
61    virtual CbcNodeInfo * partialNodeInfo(CbcModel * model, CbcNodeInfo * parent, CbcNode * owner,
62                                          int numberChangedBounds, const int * variables,
63                                          const double * boundChanges,
64                                          const CoinWarmStartDiff *basisDiff) const;
65    /// Create C++ lines to get to current state
66    virtual void generateCpp( FILE * ) {}
67    /** After a CbcModel::resolve this can return a status
68        -1 no effect
69        0 treat as optimal
70        1 as 0 but do not do any more resolves (i.e. no more cuts)
71        2 treat as infeasible
72    */
73    virtual int status(CbcModel * model, CbcNodeInfo * parent, int whereFrom);
74private:
75
76    /// Illegal Assignment operator
77    CbcStrategy & operator=(const CbcStrategy& rhs);
78protected:
79    // Data
80    /// Model depth
81    int depth_;
82    /** PreProcessing state -
83        -1 infeasible
84        0 off
85        1 was done (so need post-processing)
86    */
87    int preProcessState_;
88    /// If preprocessing then this is object
89    CglPreProcess * process_;
90};
91
92/** Null class
93 */
94
95class CbcStrategyNull : public CbcStrategy {
96public:
97
98    // Default Constructor
99    CbcStrategyNull () {}
100
101    // Copy constructor
102    CbcStrategyNull ( const CbcStrategyNull & rhs) : CbcStrategy(rhs) {}
103
104    // Destructor
105    ~CbcStrategyNull () {}
106
107    /// Clone
108    virtual CbcStrategy * clone() const {
109        return new CbcStrategyNull(*this);
110    }
111
112    /// Setup cut generators
113    virtual void setupCutGenerators(CbcModel & ) {}
114    /// Setup heuristics
115    virtual void setupHeuristics(CbcModel & ) {}
116    /// Do printing stuff
117    virtual void setupPrinting(CbcModel & , int ) {}
118    /// Other stuff e.g. strong branching
119    virtual void setupOther(CbcModel & ) {}
120
121protected:
122    // Data
123private:
124    /// Illegal Assignment operator
125    CbcStrategyNull & operator=(const CbcStrategyNull& rhs);
126};
127
128/** Default class
129 */
130
131class CbcStrategyDefault : public CbcStrategy {
132public:
133
134    // Default Constructor
135    CbcStrategyDefault (int cutsOnlyAtRoot = 1,
136                        int numberStrong = 5,
137                        int numberBeforeTrust = 0,
138                        int printLevel = 0);
139
140    // Copy constructor
141    CbcStrategyDefault ( const CbcStrategyDefault &);
142
143    // Destructor
144    ~CbcStrategyDefault ();
145
146    /// Clone
147    virtual CbcStrategy * clone() const;
148
149    /// Setup cut generators
150    virtual void setupCutGenerators(CbcModel & model);
151    /// Setup heuristics
152    virtual void setupHeuristics(CbcModel & model);
153    /// Do printing stuff
154    virtual void setupPrinting(CbcModel & model, int modelLogLevel) ;
155    /// Other stuff e.g. strong branching
156    virtual void setupOther(CbcModel & model);
157    /// Set up preProcessing - see below
158    inline void setupPreProcessing(int desired = 1, int passes = 10) {
159        desiredPreProcess_ = desired;
160        preProcessPasses_ = passes;
161    }
162    /// See what sort of preprocessing wanted
163    inline int desiredPreProcess() const {
164        return desiredPreProcess_;
165    }
166    /// See how many passes wanted
167    inline int preProcessPasses() const {
168        return preProcessPasses_;
169    }
170    /// Create C++ lines to get to current state
171    virtual void generateCpp( FILE * fp) ;
172
173protected:
174    // Data
175
176    // Whether to do cuts only at root (-1 -> switch off totally)
177    int cutsOnlyAtRoot_;
178
179    // How much strong branching to do
180    int numberStrong_;
181
182    // Number branches needed to trust with dynamic pseudo costs
183    int numberBeforeTrust_;
184
185    // Print level 0 little, 1 medium
186    int printLevel_;
187
188    /** Desired pre-processing
189        0 - none
190        1 - ordinary
191        2 - find sos
192        3 - find cliques
193        4 - more aggressive sos
194        5 - add integer slacks
195    */
196    int desiredPreProcess_;
197    /// Number of pre-processing passes
198    int preProcessPasses_;
199
200private:
201    /// Illegal Assignment operator
202    CbcStrategyDefault & operator=(const CbcStrategyDefault& rhs);
203};
204
205
206/** Default class for sub trees
207 */
208
209class CbcStrategyDefaultSubTree : public CbcStrategy {
210public:
211
212    // Default Constructor
213    CbcStrategyDefaultSubTree (CbcModel * parent = NULL, int cutsOnlyAtRoot = 1,
214                               int numberStrong = 5,
215                               int numberBeforeTrust = 0,
216                               int printLevel = 0);
217
218    // Copy constructor
219    CbcStrategyDefaultSubTree ( const CbcStrategyDefaultSubTree &);
220
221    // Destructor
222    ~CbcStrategyDefaultSubTree ();
223
224    /// Clone
225    virtual CbcStrategy * clone() const;
226
227    /// Setup cut generators
228    virtual void setupCutGenerators(CbcModel & model);
229    /// Setup heuristics
230    virtual void setupHeuristics(CbcModel & model);
231    /// Do printing stuff
232    virtual void setupPrinting(CbcModel & model, int modelLogLevel) ;
233    /// Other stuff e.g. strong branching
234    virtual void setupOther(CbcModel & model);
235protected:
236    // Data
237    // Parent model
238    CbcModel * parentModel_;
239    // Whether to do cuts only at root (-1 -> switch off totally)
240    int cutsOnlyAtRoot_;
241
242    // How much strong branching to do
243    int numberStrong_;
244
245    // Number branches needed to trust with dynamic pseudo costs
246    int numberBeforeTrust_;
247
248    // Print level 0 little, 1 medium
249    int printLevel_;
250
251private:
252    /// Illegal Assignment operator
253    CbcStrategyDefaultSubTree & operator=(const CbcStrategyDefaultSubTree& rhs);
254};
255
256
257#endif
258
Note: See TracBrowser for help on using the repository browser.