source: branches/devel/Cbc/src/CbcStrategy.hpp @ 602

Last change on this file since 602 was 424, checked in by forrest, 13 years ago

many changes

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