source: branches/devel/Cbc/src/CbcCutGenerator.hpp @ 400

Last change on this file since 400 was 395, checked in by forrest, 13 years ago

for cut generators

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 KB
Line 
1// Copyright (C) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef CbcCutGenerator_H
4#define CbcCutGenerator_H
5
6#include "OsiSolverInterface.hpp"
7#include "OsiCuts.hpp"
8#include "CglCutGenerator.hpp"
9
10class CbcModel;
11class OsiRowCut;
12class OsiRowCutDebugger;
13
14//#############################################################################
15
16/** Interface between Cbc and Cut Generation Library.
17
18  \c CbcCutGenerator is intended to provide an intelligent interface between
19  Cbc and the cutting plane algorithms in the CGL. A \c CbcCutGenerator is
20  bound to a \c CglCutGenerator and to an \c CbcModel. It contains parameters
21  which control when and how the \c generateCuts method of the
22  \c CglCutGenerator will be called.
23
24  The builtin decision criteria available to use when deciding whether to
25  generate cuts are limited: every <i>X</i> nodes, when a solution is found,
26  and when a subproblem is found to be infeasible. The idea is that the class
27  will grow more intelligent with time.
28
29  \todo Add a pointer to function member which will allow a client to install
30        their own decision algorithm to decide whether or not to call the CGL
31        \p generateCuts method. Create a default decision method that looks
32        at the builtin criteria.
33
34  \todo It strikes me as not good that generateCuts contains code specific to
35        individual CGL algorithms. Another set of pointer to function members,
36        so that the client can specify the cut generation method as well as
37        pre- and post-generation methods? Taken a bit further, should this
38        class contain a bunch of pointer to function members, one for each
39        of the places where the cut generator might be referenced?
40        Initialization, root node, search tree node, discovery of solution,
41        and termination all come to mind. Initialization and termination would
42        also be useful for instrumenting cbc.
43*/
44
45class CbcCutGenerator  {
46 
47public:
48   
49  /** \name Generate Cuts */
50  //@{
51  /** Generate cuts for the client model.
52
53    Evaluate the state of the client model and decide whether to generate cuts.
54    The generated cuts are inserted into and returned in the collection of cuts
55    \p cs.
56
57    If \p fullScan is true, the generator is obliged to call the CGL
58    \c generateCuts routine.  Otherwise, it is free to make a local decision.
59    The current implementation uses \c whenCutGenerator_ to decide.
60
61    The routine returns true if reoptimisation is needed (because the state of
62    the solver interface has been modified).
63
64    If node then can find out depth
65  */
66  bool generateCuts( OsiCuts &cs, bool fullScan,CbcNode * node); 
67  //@}
68
69   
70  /**@name Constructors and destructors */
71  //@{
72  /// Default constructor
73  CbcCutGenerator (); 
74
75  /// Normal constructor
76  CbcCutGenerator(CbcModel * model,CglCutGenerator * generator,
77                  int howOften=1, const char * name=NULL,
78                  bool normal=true, bool atSolution=false, 
79                  bool infeasible=false,int howOftenInsub=-100,
80                  int whatDepth=-1, int whatDepthInSub=-1,int switchOffIfLessThan=0);
81 
82  /// Copy constructor
83  CbcCutGenerator (const CbcCutGenerator &);
84
85  /// Assignment operator
86  CbcCutGenerator & operator=(const CbcCutGenerator& rhs);
87
88  /// Destructor
89  ~CbcCutGenerator ();
90  //@}
91
92  /**@name Gets and sets */
93  //@{
94  /** Set the client model.
95 
96    In addition to setting the client model, refreshModel also calls
97    the \c refreshSolver method of the CglCutGenerator object.
98  */
99  void refreshModel(CbcModel * model);
100
101  /// return name of generator
102  inline const char * cutGeneratorName() const
103  { return generatorName_;};
104
105  /** Set the cut generation interval
106
107    Set the number of nodes evaluated between calls to the Cgl object's
108    \p generateCuts routine.
109
110    If \p value is positive, cuts will always be generated at the specified
111    interval.
112    If \p value is negative, cuts will initially be generated at the specified
113    interval, but Cbc may adjust the value depending on the success of cuts
114    produced by this generator.
115
116    A value of -100 disables the generator, while a value of -99 means
117    just at root.
118  */
119  void setHowOften(int value) ;
120
121  /// Get the cut generation interval.
122  inline int howOften() const
123  { return whenCutGenerator_;};
124  /// Get the cut generation interval.in sub tree
125  inline int howOftenInSub() const
126  { return whenCutGeneratorInSub_;};
127
128  /** Set the cut generation depth
129
130    Set the depth criterion for calls to the Cgl object's
131    \p generateCuts routine.  Only active if > 0.
132
133    If whenCutGenerator is positive and this is positive then this overrides. 
134    If whenCutGenerator is -1 then this is used as criterion if any cuts
135    were generated at root node.
136    If whenCutGenerator is anything else this is ignored.
137  */
138  void setWhatDepth(int value) ;
139  /// Set the cut generation depth in sub tree
140  void setWhatDepthInSub(int value) ;
141  /// Get the cut generation depth criterion.
142  inline int whatDepth() const
143  { return depthCutGenerator_;};
144  /// Get the cut generation depth criterion.in sub tree
145  inline int whatDepthInSub() const
146  { return depthCutGeneratorInSub_;};
147
148  /// Get whether the cut generator should be called in the normal place
149  inline bool normal() const
150  { return normal_;};
151  /// Set whether the cut generator should be called in the normal place
152  inline void setNormal(bool value) 
153  { normal_=value;};
154  /// Get whether the cut generator should be called when a solution is found
155  inline bool atSolution() const
156  { return atSolution_;};
157  /// Set whether the cut generator should be called when a solution is found
158  inline void setAtSolution(bool value) 
159  { atSolution_=value;};
160  /** Get whether the cut generator should be called when the subproblem is
161      found to be infeasible.
162  */
163  inline bool whenInfeasible() const
164  { return whenInfeasible_;};
165  /** Set whether the cut generator should be called when the subproblem is
166      found to be infeasible.
167  */
168  inline void setWhenInfeasible(bool value) 
169  { whenInfeasible_=value;};
170  /// Get whether the cut generator is being timed
171  inline bool timing() const
172  { return timing_;};
173  /// Set whether the cut generator is being timed
174  inline void setTiming(bool value) 
175  { timing_=value; timeInCutGenerator_=0.0;};
176  /// Return time taken in cut generator
177  inline double timeInCutGenerator() const
178  { return timeInCutGenerator_;};
179  /// Get the \c CglCutGenerator corresponding to this \c CbcCutGenerator.
180  inline CglCutGenerator * generator() const
181  { return generator_;};
182  /// Number times cut generator entered
183  inline int numberTimesEntered() const
184  { return numberTimes_;};
185  inline void setNumberTimesEntered(int value)
186  { numberTimes_ = value;};
187  inline void incrementNumberTimesEntered(int value=1)
188  { numberTimes_ += value;};
189  /// Total number of cuts added
190  inline int numberCutsInTotal() const
191  { return numberCuts_;};
192  inline void setNumberCutsInTotal(int value)
193  { numberCuts_ = value;};
194  inline void incrementNumberCutsInTotal(int value=1)
195  { numberCuts_ += value;};
196  /// Total number of column cuts
197  inline int numberColumnCuts() const
198  { return numberColumnCuts_;};
199  inline void setNumberColumnCuts(int value)
200  { numberColumnCuts_ = value;};
201  inline void incrementNumberColumnCuts(int value=1)
202  { numberColumnCuts_ += value;};
203  /// Total number of cuts active after (at end of n cut passes at each node)
204  inline int numberCutsActive() const
205  { return numberCutsActive_;};
206  inline void setNumberCutsActive(int value)
207  { numberCutsActive_ = value;};
208  inline void incrementNumberCutsActive(int value=1)
209  { numberCutsActive_ += value;};
210  inline void setSwitchOffIfLessThan(int value) 
211  { switchOffIfLessThan_ = value;};
212  inline int switchOffIfLessThan() const
213  { return switchOffIfLessThan_;};
214  /// Say if optimal basis needed
215  inline bool needsOptimalBasis() const
216  { return generator_->needsOptimalBasis();};
217  /// Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
218  inline bool mustCallAgain() const
219  { return mustCallAgain_;};
220  /// Set whether generator MUST be called again if any cuts (i.e. ignore break from loop)
221  inline void setMustCallAgain(bool yesNo)
222  { mustCallAgain_=yesNo;};
223  /// Whether generator switched off for moment
224  inline bool switchedOff() const
225  { return switchedOff_;};
226  /// Set whether generator switched off for moment
227  inline void setSwitchedOff(bool yesNo)
228  { switchedOff_=yesNo;};
229  //@}
230 
231private:
232  /// The client model
233  CbcModel *model_;
234
235  // The CglCutGenerator object
236  CglCutGenerator * generator_;
237
238  /** Number of nodes between calls to the CglCutGenerator::generateCuts
239     routine.
240  */
241  int whenCutGenerator_;
242  /** Number of nodes between calls to the CglCutGenerator::generateCuts
243     routine in sub tree.
244  */
245  int whenCutGeneratorInSub_;
246  /** If first pass at root produces fewer than this cuts then switch off
247   */
248  int switchOffIfLessThan_;
249
250  /** Depth at which to call the CglCutGenerator::generateCuts
251     routine (If >0 then overrides when and is called if depth%depthCutGenerator==0).
252  */
253  int depthCutGenerator_;
254
255  /** Depth at which to call the CglCutGenerator::generateCuts
256     routine (If >0 then overrides when and is called if depth%depthCutGenerator==0).
257     In sub tree.
258  */
259  int depthCutGeneratorInSub_;
260
261  /// Name of generator
262  char * generatorName_;
263
264  /// Whether to call the generator in the normal place
265  bool normal_;
266
267  /// Whether to call the generator when a new solution is found
268  bool atSolution_;
269
270  /// Whether to call generator when a subproblem is found to be infeasible
271  bool whenInfeasible_;
272  /// Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
273  bool mustCallAgain_;
274  /// Temporary switch off marker
275  bool switchedOff_;
276  /// Whether call generator being timed
277  bool timing_;
278  /// Time in cut generator
279  double timeInCutGenerator_;
280 
281  /// Number times cut generator entered
282  int numberTimes_;
283  /// Total number of cuts added
284  int numberCuts_;
285  /// Total number of column cuts added
286  int numberColumnCuts_;
287  /// Total number of cuts active after (at end of n cut passes at each node)
288  int numberCutsActive_;
289};
290
291#endif
Note: See TracBrowser for help on using the repository browser.