Cbc  2.10.5
CbcCutGenerator.hpp
Go to the documentation of this file.
1 /* $Id$ */
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:
70  bool generateCuts(OsiCuts &cs, int fullScan, OsiSolverInterface *solver,
71  CbcNode *node);
73 
78 
80  CbcCutGenerator(CbcModel *model, CglCutGenerator *generator,
81  int howOften = 1, const char *name = NULL,
82  bool normal = true, bool atSolution = false,
83  bool infeasible = false, int howOftenInsub = -100,
84  int whatDepth = -1, int whatDepthInSub = -1, int switchOffIfLessThan = 0);
85 
88 
91 
95 
103  void refreshModel(CbcModel *model);
104 
106  inline const char *cutGeneratorName() const
107  {
108  return generatorName_;
109  }
110 
112  void generateTuning(FILE *fp);
127  void setHowOften(int value);
128 
130  inline int howOften() const
131  {
132  return whenCutGenerator_;
133  }
135  inline int howOftenInSub() const
136  {
137  return whenCutGeneratorInSub_;
138  }
140  inline int inaccuracy() const
141  {
142  return inaccuracy_;
143  }
145  inline void setInaccuracy(int level)
146  {
147  inaccuracy_ = level;
148  }
149 
160  void setWhatDepth(int value);
162  void setWhatDepthInSub(int value);
164  inline int whatDepth() const
165  {
166  return depthCutGenerator_;
167  }
169  inline int whatDepthInSub() const
170  {
172  }
174  inline void setMaximumTries(int value)
175  {
176  maximumTries_ = value;
177  }
179  inline int maximumTries() const
180  {
181  return maximumTries_;
182  }
183 
185  inline int switches() const
186  {
187  return switches_;
188  }
190  inline void setSwitches(int value)
191  {
192  switches_ = value;
193  }
195  inline bool normal() const
196  {
197  return (switches_ & 1) != 0;
198  }
200  inline void setNormal(bool value)
201  {
202  switches_ &= ~1;
203  switches_ |= value ? 1 : 0;
204  }
206  inline bool atSolution() const
207  {
208  return (switches_ & 2) != 0;
209  }
211  inline void setAtSolution(bool value)
212  {
213  switches_ &= ~2;
214  switches_ |= value ? 2 : 0;
215  }
219  inline bool whenInfeasible() const
220  {
221  return (switches_ & 4) != 0;
222  }
226  inline void setWhenInfeasible(bool value)
227  {
228  switches_ &= ~4;
229  switches_ |= value ? 4 : 0;
230  }
232  inline bool timing() const
233  {
234  return (switches_ & 64) != 0;
235  }
237  inline void setTiming(bool value)
238  {
239  switches_ &= ~64;
240  switches_ |= value ? 64 : 0;
241  timeInCutGenerator_ = 0.0;
242  }
244  inline double timeInCutGenerator() const
245  {
246  return timeInCutGenerator_;
247  }
248  inline void incrementTimeInCutGenerator(double value)
249  {
250  timeInCutGenerator_ += value;
251  }
253  inline CglCutGenerator *generator() const
254  {
255  return generator_;
256  }
258  inline int numberTimesEntered() const
259  {
260  return numberTimes_;
261  }
262  inline void setNumberTimesEntered(int value)
263  {
264  numberTimes_ = value;
265  }
266  inline void incrementNumberTimesEntered(int value = 1)
267  {
268  numberTimes_ += value;
269  }
271  inline int numberCutsInTotal() const
272  {
273  return numberCuts_;
274  }
275  inline void setNumberCutsInTotal(int value)
276  {
277  numberCuts_ = value;
278  }
279  inline void incrementNumberCutsInTotal(int value = 1)
280  {
281  numberCuts_ += value;
282  }
284  inline int numberElementsInTotal() const
285  {
286  return numberElements_;
287  }
288  inline void setNumberElementsInTotal(int value)
289  {
290  numberElements_ = value;
291  }
292  inline void incrementNumberElementsInTotal(int value = 1)
293  {
294  numberElements_ += value;
295  }
297  inline int numberColumnCuts() const
298  {
299  return numberColumnCuts_;
300  }
301  inline void setNumberColumnCuts(int value)
302  {
303  numberColumnCuts_ = value;
304  }
305  inline void incrementNumberColumnCuts(int value = 1)
306  {
307  numberColumnCuts_ += value;
308  }
310  inline int numberCutsActive() const
311  {
312  return numberCutsActive_;
313  }
314  inline void setNumberCutsActive(int value)
315  {
316  numberCutsActive_ = value;
317  }
318  inline void incrementNumberCutsActive(int value = 1)
319  {
320  numberCutsActive_ += value;
321  }
322  inline void setSwitchOffIfLessThan(int value)
323  {
324  switchOffIfLessThan_ = value;
325  }
326  inline int switchOffIfLessThan() const
327  {
328  return switchOffIfLessThan_;
329  }
331  inline bool needsOptimalBasis() const
332  {
333  return (switches_ & 128) != 0;
334  }
336  inline void setNeedsOptimalBasis(bool yesNo)
337  {
338  switches_ &= ~128;
339  switches_ |= yesNo ? 128 : 0;
340  }
342  inline bool mustCallAgain() const
343  {
344  return (switches_ & 8) != 0;
345  }
347  inline void setMustCallAgain(bool yesNo)
348  {
349  switches_ &= ~8;
350  switches_ |= yesNo ? 8 : 0;
351  }
353  inline bool switchedOff() const
354  {
355  return (switches_ & 16) != 0;
356  }
358  inline void setSwitchedOff(bool yesNo)
359  {
360  switches_ &= ~16;
361  switches_ |= yesNo ? 16 : 0;
362  }
364  inline bool ineffectualCuts() const
365  {
366  return (switches_ & 512) != 0;
367  }
369  inline void setIneffectualCuts(bool yesNo)
370  {
371  switches_ &= ~512;
372  switches_ |= yesNo ? 512 : 0;
373  }
375  inline bool whetherToUse() const
376  {
377  return (switches_ & 1024) != 0;
378  }
380  inline void setWhetherToUse(bool yesNo)
381  {
382  switches_ &= ~1024;
383  switches_ |= yesNo ? 1024 : 0;
384  }
386  inline bool whetherInMustCallAgainMode() const
387  {
388  return (switches_ & 2048) != 0;
389  }
391  inline void setWhetherInMustCallAgainMode(bool yesNo)
392  {
393  switches_ &= ~2048;
394  switches_ |= yesNo ? 2048 : 0;
395  }
397  inline bool whetherCallAtEnd() const
398  {
399  return (switches_ & 4096) != 0;
400  }
402  inline void setWhetherCallAtEnd(bool yesNo)
403  {
404  switches_ &= ~4096;
405  switches_ |= yesNo ? 4096 : 0;
406  }
408  inline bool needsRefresh() const
409  {
410  return (switches_ & 8192) != 0;
411  }
413  inline void setNeedsRefresh(bool yesNo)
414  {
415  switches_ &= ~8192;
416  switches_ |= yesNo ? 8192 : 0;
417  }
419  inline int numberCutsAtRoot() const
420  {
421  return numberCutsAtRoot_;
422  }
423  inline void setNumberCutsAtRoot(int value)
424  {
425  numberCutsAtRoot_ = value;
426  }
428  inline int numberActiveCutsAtRoot() const
429  {
431  }
432  inline void setNumberActiveCutsAtRoot(int value)
433  {
434  numberActiveCutsAtRoot_ = value;
435  }
437  inline int numberShortCutsAtRoot() const
438  {
439  return numberShortCutsAtRoot_;
440  }
441  inline void setNumberShortCutsAtRoot(int value)
442  {
443  numberShortCutsAtRoot_ = value;
444  }
446  inline void setModel(CbcModel *model)
447  {
448  model_ = model;
449  }
451  inline bool globalCutsAtRoot() const
452  {
453  return (switches_ & 32) != 0;
454  }
456  inline void setGlobalCutsAtRoot(bool yesNo)
457  {
458  switches_ &= ~32;
459  switches_ |= yesNo ? 32 : 0;
460  }
462  inline bool globalCuts() const
463  {
464  return (switches_ & 256) != 0;
465  }
467  inline void setGlobalCuts(bool yesNo)
468  {
469  switches_ &= ~256;
470  switches_ |= yesNo ? 256 : 0;
471  }
473  void addStatistics(const CbcCutGenerator *other);
475  void scaleBackStatistics(int factor);
477 
478 private:
482  OsiCuts savedCuts_;
488 
489  // The CglCutGenerator object
490  CglCutGenerator *generator_;
491 
494 
506 
511 
517 
540 };
541 
542 // How often to do if mostly switched off (A)
543 #define SCANCUTS 1000
544 // How often to do if mostly switched off (probing B)
545 #define SCANCUTS_PROBING 1000
546 
547 #endif
548 
549 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
550 */
Interface between Cbc and Cut Generation Library.
int depthCutGeneratorInSub_
Depth at which to call the CglCutGenerator::generateCuts routine (If >0 then overrides when and is ca...
int whatDepthInSub() const
Get the cut generation depth criterion.in sub tree.
void setNumberTimesEntered(int value)
void setWhetherToUse(bool yesNo)
Set whether to use if any cuts generated.
void incrementNumberColumnCuts(int value=1)
void incrementTimeInCutGenerator(double value)
void setNumberCutsInTotal(int value)
double timeInCutGenerator_
Time in cut generator.
void incrementNumberTimesEntered(int value=1)
int depthCutGenerator_
Depth at which to call the CglCutGenerator::generateCuts routine (If >0 then overrides when and is ca...
bool needsOptimalBasis() const
Say if optimal basis needed.
void setNumberCutsActive(int value)
void setAtSolution(bool value)
Set whether the cut generator should be called when a solution is found.
bool atSolution() const
Get whether the cut generator should be called when a solution is found.
void setNumberActiveCutsAtRoot(int value)
bool whetherCallAtEnd() const
Whether to call at end.
void incrementNumberElementsInTotal(int value=1)
int numberTimes_
Number times cut generator entered.
CglCutGenerator * generator_
int numberShortCutsAtRoot() const
Number of short cuts at root.
int howOftenInSub() const
Get the cut generation interval.in sub tree.
void setWhatDepth(int value)
Set the cut generation depth.
bool needsRefresh() const
Whether needs refresh on copy.
int numberCutsActive_
Total number of cuts active after (at end of n cut passes at each node)
bool ineffectualCuts() const
Whether last round of cuts did little.
CbcCutGenerator & operator=(const CbcCutGenerator &rhs)
Assignment operator.
int numberActiveCutsAtRoot() const
Number of cuts active at root.
void incrementNumberCutsActive(int value=1)
void setTiming(bool value)
Set whether the cut generator is being timed.
int whatDepth() const
Get the cut generation depth criterion.
void setMustCallAgain(bool yesNo)
Set whether generator MUST be called again if any cuts (i.e. ignore break from loop)
void setNeedsRefresh(bool yesNo)
Set whether needs refresh on copy.
int whenCutGeneratorInSub_
Number of nodes between calls to the CglCutGenerator::generateCuts routine in sub tree.
int inaccuracy_
Level of cut inaccuracy (0 means exact e.g. cliques)
bool switchedOff() const
Whether generator switched off for moment.
int numberActiveCutsAtRoot_
Number of cuts active at root.
bool globalCuts() const
Whether global cuts.
bool timing() const
Get whether the cut generator is being timed.
OsiCuts savedCuts_
Saved cuts.
bool whetherInMustCallAgainMode() const
Whether in must call again mode (or after others)
int switchOffIfLessThan_
If first pass at root produces fewer than this cuts then switch off.
void setNeedsOptimalBasis(bool yesNo)
Set if optimal basis needed.
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 setNumberElementsInTotal(int value)
void setWhetherCallAtEnd(bool yesNo)
Set whether to call at end.
char * generatorName_
Name of generator.
void setIneffectualCuts(bool yesNo)
Set whether last round of cuts did little.
int numberCutsAtRoot() const
Number of cuts generated at root.
int numberShortCutsAtRoot_
Number of short cuts at root.
int numberTimesEntered() const
Number times cut generator entered.
double timeInCutGenerator() const
Return time taken in cut generator.
void setHowOften(int value)
Set the cut generation interval.
void setNormal(bool value)
Set whether the cut generator should be called in the normal place.
int numberColumnCuts() const
Total number of column cuts.
int numberElementsInTotal() const
Total number of elements added.
void setSwitches(int value)
Set switches (for copying from virgin state)
~CbcCutGenerator()
Destructor.
int switchOffIfLessThan() const
int numberCutsAtRoot_
Number of cuts generated at root.
int switches_
Switches - see gets and sets.
void setSwitchedOff(bool yesNo)
Set whether generator switched off for moment.
CglCutGenerator * generator() const
Get the CglCutGenerator corresponding to this CbcCutGenerator.
void generateTuning(FILE *fp)
Create C++ lines to show how to tune.
int numberCutsInTotal() const
Total number of cuts added.
CbcCutGenerator(const CbcCutGenerator &)
Copy constructor.
bool normal() const
Get whether the cut generator should be called in the normal place.
void setGlobalCutsAtRoot(bool yesNo)
Set whether global cuts at root.
void setNumberShortCutsAtRoot(int value)
int whenCutGenerator_
Number of nodes between calls to the CglCutGenerator::generateCuts routine.
CbcCutGenerator(CbcModel *model, CglCutGenerator *generator, int howOften=1, const char *name=NULL, bool normal=true, bool atSolution=false, bool infeasible=false, int howOftenInsub=-100, int whatDepth=-1, int whatDepthInSub=-1, int switchOffIfLessThan=0)
Normal constructor.
int maximumTries() const
Get maximum number of times to enter.
CbcCutGenerator()
Default constructor.
void setInaccuracy(int level)
Set level of cut inaccuracy (0 means exact e.g. cliques)
bool generateCuts(OsiCuts &cs, int fullScan, OsiSolverInterface *solver, CbcNode *node)
Generate cuts for the client model.
void refreshModel(CbcModel *model)
Set the client model.
CbcModel * model_
The client model.
void incrementNumberCutsInTotal(int value=1)
int numberColumnCuts_
Total number of column cuts added.
void setNumberCutsAtRoot(int value)
void setWhetherInMustCallAgainMode(bool yesNo)
Set whether in must call again mode (or after others)
void setMaximumTries(int value)
Set maximum number of times to enter.
const char * cutGeneratorName() const
return name of generator
int numberCuts_
Total number of cuts added.
int numberElements_
Total number of elements added.
bool whetherToUse() const
Whether to use if any cuts generated.
int inaccuracy() const
Get level of cut inaccuracy (0 means exact e.g. cliques)
void setSwitchOffIfLessThan(int value)
void setGlobalCuts(bool yesNo)
Set whether global cuts.
void setModel(CbcModel *model)
Set model.
void setWhatDepthInSub(int value)
Set the cut generation depth in sub tree.
bool whenInfeasible() const
Get whether the cut generator should be called when the subproblem is found to be infeasible.
int maximumTries_
Maximum number of times to enter.
int howOften() const
Get the cut generation interval.
bool mustCallAgain() const
Whether generator MUST be called again if any cuts (i.e. ignore break from loop)
bool globalCutsAtRoot() const
Whether global cuts at root.
void scaleBackStatistics(int factor)
Scale back statistics by factor.
int switches() const
Get switches.
void setWhenInfeasible(bool value)
Set whether the cut generator should be called when the subproblem is found to be infeasible.
void setNumberColumnCuts(int value)
Simple Branch and bound class.
Definition: CbcModel.hpp:100
Information required while the node is live.
Definition: CbcNode.hpp:49