source: trunk/Cbc/src/CbcStrategy.hpp

Last change on this file was 2465, checked in by unxusr, 6 months ago

script to format sources

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