Cbc  2.9.8
CbcCutGenerator.hpp
Go to the documentation of this file.
1 /* $Id: CbcCutGenerator.hpp 2081 2014-09-25 11:31:17Z forrest $ */
2 // Copyright (C) 2003, 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 CbcCutGenerator_H
7 #define CbcCutGenerator_H
8 
9 #include "OsiSolverInterface.hpp"
10 #include "OsiCuts.hpp"
11 #include "CglCutGenerator.hpp"
12 #include "CbcCutModifier.hpp"
13 
14 class CbcModel;
15 class OsiRowCut;
16 class OsiRowCutDebugger;
17 
18 //#############################################################################
19 
50 
51 public:
52 
71  bool generateCuts( OsiCuts &cs, int fullScan, OsiSolverInterface * solver,
72  CbcNode * node);
74 
75 
78  CbcCutGenerator ();
80 
82  CbcCutGenerator(CbcModel * model, CglCutGenerator * generator,
83  int howOften = 1, const char * name = NULL,
84  bool normal = true, bool atSolution = false,
85  bool infeasible = false, int howOftenInsub = -100,
86  int whatDepth = -1, int whatDepthInSub = -1, int switchOffIfLessThan = 0);
87 
90 
93 
97 
105  void refreshModel(CbcModel * model);
106 
108  inline const char * cutGeneratorName() const {
109  return generatorName_;
110  }
111 
113  void generateTuning( FILE * fp);
128  void setHowOften(int value) ;
129 
131  inline int howOften() const {
132  return whenCutGenerator_;
133  }
135  inline int howOftenInSub() const {
136  return whenCutGeneratorInSub_;
137  }
139  inline int inaccuracy() const {
140  return inaccuracy_;
141  }
143  inline void setInaccuracy(int level) {
144  inaccuracy_ = level;
145  }
146 
157  void setWhatDepth(int value) ;
159  void setWhatDepthInSub(int value) ;
161  inline int whatDepth() const {
162  return depthCutGenerator_;
163  }
165  inline int whatDepthInSub() const {
166  return depthCutGeneratorInSub_;
167  }
169  inline void setMaximumTries(int value)
170  { maximumTries_ = value;}
172  inline int maximumTries() const
173  { return maximumTries_;}
174 
176  inline int switches() const {
177  return switches_;
178  }
180  inline void setSwitches(int value) {
181  switches_ = value;
182  }
184  inline bool normal() const {
185  return (switches_&1) != 0;
186  }
188  inline void setNormal(bool value) {
189  switches_ &= ~1;
190  switches_ |= value ? 1 : 0;
191  }
193  inline bool atSolution() const {
194  return (switches_&2) != 0;
195  }
197  inline void setAtSolution(bool value) {
198  switches_ &= ~2;
199  switches_ |= value ? 2 : 0;
200  }
204  inline bool whenInfeasible() const {
205  return (switches_&4) != 0;
206  }
210  inline void setWhenInfeasible(bool value) {
211  switches_ &= ~4;
212  switches_ |= value ? 4 : 0;
213  }
215  inline bool timing() const {
216  return (switches_&64) != 0;
217  }
219  inline void setTiming(bool value) {
220  switches_ &= ~64;
221  switches_ |= value ? 64 : 0;
222  timeInCutGenerator_ = 0.0;
223  }
225  inline double timeInCutGenerator() const {
226  return timeInCutGenerator_;
227  }
228  inline void incrementTimeInCutGenerator(double value) {
229  timeInCutGenerator_ += value;
230  }
232  inline CglCutGenerator * generator() const {
233  return generator_;
234  }
236  inline int numberTimesEntered() const {
237  return numberTimes_;
238  }
239  inline void setNumberTimesEntered(int value) {
240  numberTimes_ = value;
241  }
242  inline void incrementNumberTimesEntered(int value = 1) {
243  numberTimes_ += value;
244  }
246  inline int numberCutsInTotal() const {
247  return numberCuts_;
248  }
249  inline void setNumberCutsInTotal(int value) {
250  numberCuts_ = value;
251  }
252  inline void incrementNumberCutsInTotal(int value = 1) {
253  numberCuts_ += value;
254  }
256  inline int numberElementsInTotal() const {
257  return numberElements_;
258  }
259  inline void setNumberElementsInTotal(int value) {
260  numberElements_ = value;
261  }
262  inline void incrementNumberElementsInTotal(int value = 1) {
263  numberElements_ += value;
264  }
266  inline int numberColumnCuts() const {
267  return numberColumnCuts_;
268  }
269  inline void setNumberColumnCuts(int value) {
270  numberColumnCuts_ = value;
271  }
272  inline void incrementNumberColumnCuts(int value = 1) {
273  numberColumnCuts_ += value;
274  }
276  inline int numberCutsActive() const {
277  return numberCutsActive_;
278  }
279  inline void setNumberCutsActive(int value) {
280  numberCutsActive_ = value;
281  }
282  inline void incrementNumberCutsActive(int value = 1) {
283  numberCutsActive_ += value;
284  }
285  inline void setSwitchOffIfLessThan(int value) {
286  switchOffIfLessThan_ = value;
287  }
288  inline int switchOffIfLessThan() const {
289  return switchOffIfLessThan_;
290  }
292  inline bool needsOptimalBasis() const {
293  return (switches_&128) != 0;
294  }
296  inline void setNeedsOptimalBasis(bool yesNo) {
297  switches_ &= ~128;
298  switches_ |= yesNo ? 128 : 0;
299  }
301  inline bool mustCallAgain() const {
302  return (switches_&8) != 0;
303  }
305  inline void setMustCallAgain(bool yesNo) {
306  switches_ &= ~8;
307  switches_ |= yesNo ? 8 : 0;
308  }
310  inline bool switchedOff() const {
311  return (switches_&16) != 0;
312  }
314  inline void setSwitchedOff(bool yesNo) {
315  switches_ &= ~16;
316  switches_ |= yesNo ? 16 : 0;
317  }
319  inline bool ineffectualCuts() const {
320  return (switches_&512) != 0;
321  }
323  inline void setIneffectualCuts(bool yesNo) {
324  switches_ &= ~512;
325  switches_ |= yesNo ? 512 : 0;
326  }
328  inline bool whetherToUse() const {
329  return (switches_&1024) != 0;
330  }
332  inline void setWhetherToUse(bool yesNo) {
333  switches_ &= ~1024;
334  switches_ |= yesNo ? 1024 : 0;
335  }
337  inline bool whetherInMustCallAgainMode() const {
338  return (switches_&2048) != 0;
339  }
341  inline void setWhetherInMustCallAgainMode(bool yesNo) {
342  switches_ &= ~2048;
343  switches_ |= yesNo ? 2048 : 0;
344  }
346  inline bool whetherCallAtEnd() const {
347  return (switches_&4096) != 0;
348  }
350  inline void setWhetherCallAtEnd(bool yesNo) {
351  switches_ &= ~4096;
352  switches_ |= yesNo ? 4096 : 0;
353  }
355  inline bool needsRefresh() const {
356  return (switches_&8192) != 0;
357  }
359  inline void setNeedsRefresh(bool yesNo) {
360  switches_ &= ~8192;
361  switches_ |= yesNo ? 8192 : 0;
362  }
364  inline int numberCutsAtRoot() const {
365  return numberCutsAtRoot_;
366  }
367  inline void setNumberCutsAtRoot(int value) {
368  numberCutsAtRoot_ = value;
369  }
371  inline int numberActiveCutsAtRoot() const {
372  return numberActiveCutsAtRoot_;
373  }
374  inline void setNumberActiveCutsAtRoot(int value) {
375  numberActiveCutsAtRoot_ = value;
376  }
378  inline int numberShortCutsAtRoot() const {
379  return numberShortCutsAtRoot_;
380  }
381  inline void setNumberShortCutsAtRoot(int value) {
382  numberShortCutsAtRoot_ = value;
383  }
385  inline void setModel(CbcModel * model) {
386  model_ = model;
387  }
389  inline bool globalCutsAtRoot() const {
390  return (switches_&32) != 0;
391  }
393  inline void setGlobalCutsAtRoot(bool yesNo) {
394  switches_ &= ~32;
395  switches_ |= yesNo ? 32 : 0;
396  }
398  inline bool globalCuts() const {
399  return (switches_&256) != 0;
400  }
402  inline void setGlobalCuts(bool yesNo) {
403  switches_ &= ~256;
404  switches_ |= yesNo ? 256 : 0;
405  }
407  void addStatistics(const CbcCutGenerator * other);
409  void scaleBackStatistics(int factor);
411 
412 private:
415 
416  OsiCuts savedCuts_;
419  double timeInCutGenerator_;
421  CbcModel *model_;
422 
423  // The CglCutGenerator object
424  CglCutGenerator * generator_;
425 
427  char * generatorName_;
428 
432  int whenCutGenerator_;
436  int whenCutGeneratorInSub_;
439  int switchOffIfLessThan_;
440 
444  int depthCutGenerator_;
445 
450  int depthCutGeneratorInSub_;
451 
453  int inaccuracy_;
455  int numberTimes_;
457  int numberCuts_;
459  int numberElements_;
461  int numberColumnCuts_;
463  int numberCutsActive_;
465  int numberCutsAtRoot_;
467  int numberActiveCutsAtRoot_;
469  int numberShortCutsAtRoot_;
471  int switches_;
473  int maximumTries_;
474 };
475 
476 // How often to do if mostly switched off (A)
477 # define SCANCUTS 1000
478 // How often to do if mostly switched off (probing B)
479 # define SCANCUTS_PROBING 1000
480 
481 #endif
482 
int maximumTries() const
Get maximum number of times to enter.
bool globalCuts() const
Whether global cuts.
bool normal() const
Get whether the cut generator should be called in the normal place.
void setSwitches(int value)
Set switches (for copying from virgin state)
bool whenInfeasible() const
Get whether the cut generator should be called when the subproblem is found to be infeasible...
void setNumberColumnCuts(int value)
void setWhatDepth(int value)
Set the cut generation depth.
int switches() const
Get switches.
int numberColumnCuts() const
Total number of column cuts.
void setNormal(bool value)
Set whether the cut generator should be called in the normal place.
void setWhetherToUse(bool yesNo)
Set whether to use if any cuts generated.
void setIneffectualCuts(bool yesNo)
Set whether last round of cuts did little.
void setNumberCutsInTotal(int value)
int numberCutsAtRoot() const
Number of cuts generated at root.
const char * cutGeneratorName() const
return name of generator
void incrementNumberCutsInTotal(int value=1)
int numberCutsInTotal() const
Total number of cuts added.
bool whetherToUse() const
Whether to use if any cuts generated.
int whatDepthInSub() const
Get the cut generation depth criterion.in sub tree.
void setWhenInfeasible(bool value)
Set whether the cut generator should be called when the subproblem is found to be infeasible...
bool mustCallAgain() const
Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
CbcCutGenerator & operator=(const CbcCutGenerator &rhs)
Assignment operator.
int inaccuracy() const
Get level of cut inaccuracy (0 means exact e.g. cliques)
double timeInCutGenerator() const
Return time taken in cut generator.
void setGlobalCuts(bool yesNo)
Set whether global cuts.
int switchOffIfLessThan() const
void setNumberCutsAtRoot(int value)
bool generateCuts(OsiCuts &cs, int fullScan, OsiSolverInterface *solver, CbcNode *node)
Generate cuts for the client model.
int howOften() const
Get the cut generation interval.
void setTiming(bool value)
Set whether the cut generator is being timed.
int numberActiveCutsAtRoot() const
Number of cuts active at root.
bool timing() const
Get whether the cut generator is being timed.
bool ineffectualCuts() const
Whether last round of cuts did little.
void setNeedsOptimalBasis(bool yesNo)
Set if optimal basis needed.
void setWhetherInMustCallAgainMode(bool yesNo)
Set whether in must call again mode (or after others)
void setNumberShortCutsAtRoot(int value)
void setAtSolution(bool value)
Set whether the cut generator should be called when a solution is found.
void setSwitchedOff(bool yesNo)
Set whether generator switched off for moment.
void incrementNumberColumnCuts(int value=1)
int numberTimesEntered() const
Number times cut generator entered.
void refreshModel(CbcModel *model)
Set the client model.
void setNumberTimesEntered(int value)
Information required while the node is live.
Definition: CbcNode.hpp:49
bool atSolution() const
Get whether the cut generator should be called when a solution is found.
void setNumberCutsActive(int value)
bool switchedOff() const
Whether generator switched off for moment.
void setWhetherCallAtEnd(bool yesNo)
Set whether to call at end.
~CbcCutGenerator()
Destructor.
bool needsOptimalBasis() const
Say if optimal basis needed.
CglCutGenerator * generator() const
Get the CglCutGenerator corresponding to this CbcCutGenerator.
void generateTuning(FILE *fp)
Create C++ lines to show how to tune.
void scaleBackStatistics(int factor)
Scale back statistics by factor.
void setMaximumTries(int value)
Set maximum number of times to enter.
void setModel(CbcModel *model)
Set model.
void setGlobalCutsAtRoot(bool yesNo)
Set whether global cuts at root.
void setNeedsRefresh(bool yesNo)
Set whether needs refresh on copy.
bool whetherCallAtEnd() const
Whether to call at end.
int numberShortCutsAtRoot() const
Number of short cuts at root.
void incrementNumberCutsActive(int value=1)
void setInaccuracy(int level)
Set level of cut inaccuracy (0 means exact e.g. cliques)
void setNumberElementsInTotal(int value)
bool globalCutsAtRoot() const
Whether global cuts at root.
void setWhatDepthInSub(int value)
Set the cut generation depth in sub tree.
CbcCutGenerator()
Default constructor.
bool needsRefresh() const
Whether needs refresh on copy.
int numberElementsInTotal() const
Total number of elements added.
void setNumberActiveCutsAtRoot(int value)
void setMustCallAgain(bool yesNo)
Set whether generator MUST be called again if any cuts (i.e. ignore break from loop) ...
bool whetherInMustCallAgainMode() const
Whether in must call again mode (or after others)
Interface between Cbc and Cut Generation Library.
int howOftenInSub() const
Get the cut generation interval.in sub tree.
int numberCutsActive() const
Total number of cuts active after (at end of n cut passes at each node)
void addStatistics(const CbcCutGenerator *other)
Add in statistics from other.
void setSwitchOffIfLessThan(int value)
Simple Branch and bound class.
Definition: CbcModel.hpp:101
void setHowOften(int value)
Set the cut generation interval.
void incrementTimeInCutGenerator(double value)
void incrementNumberElementsInTotal(int value=1)
void incrementNumberTimesEntered(int value=1)
int whatDepth() const
Get the cut generation depth criterion.