Cbc  2.10.3
CbcCutGenerator.hpp
Go to the documentation of this file.
1 /* $Id: CbcCutGenerator.hpp 2465 2019-01-03 19:26:52Z unxusr $ */
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 
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  {
171  return depthCutGeneratorInSub_;
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  {
430  return numberActiveCutsAtRoot_;
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:
481 
482  OsiCuts savedCuts_;
485  double timeInCutGenerator_;
487  CbcModel *model_;
488 
489  // The CglCutGenerator object
490  CglCutGenerator *generator_;
491 
493  char *generatorName_;
494 
498  int whenCutGenerator_;
502  int whenCutGeneratorInSub_;
505  int switchOffIfLessThan_;
506 
510  int depthCutGenerator_;
511 
516  int depthCutGeneratorInSub_;
517 
519  int inaccuracy_;
521  int numberTimes_;
523  int numberCuts_;
525  int numberElements_;
527  int numberColumnCuts_;
529  int numberCutsActive_;
531  int numberCutsAtRoot_;
533  int numberActiveCutsAtRoot_;
535  int numberShortCutsAtRoot_;
537  int switches_;
539  int maximumTries_;
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 */
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:100
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.