Cgl  0.59.10
CglProbing.hpp
Go to the documentation of this file.
1 // $Id: CglProbing.hpp 1201 2014-03-07 17:24:04Z forrest $
2 // Copyright (C) 2002, 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 CglProbing_H
7 #define CglProbing_H
8 
9 #include <string>
10 
11 #include "CglCutGenerator.hpp"
16  typedef struct {
17  //unsigned int zeroOne:1; // nonzero if affected variable is 0-1
18  //unsigned int whenAtUB:1; // nonzero if fixing happens when this variable at 1
19  //unsigned int affectedToUB:1; // nonzero if affected variable fixed to UB
20  //unsigned int affected:29; // If 0-1 then 0-1 sequence, otherwise true
21  unsigned int affected;
23 
25 class CglProbing : public CglCutGenerator {
26  friend void CglProbingUnitTest(const OsiSolverInterface * siP,
27  const std::string mpdDir );
28 
29 public:
30 
31 
99  virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
100  const CglTreeInfo info = CglTreeInfo());
101  int generateCutsAndModify( const OsiSolverInterface & si, OsiCuts & cs,
102  CglTreeInfo * info);
104 
115  int snapshot ( const OsiSolverInterface & si,
116  char * possible=NULL,
117  bool withObjective=true);
119  void deleteSnapshot ( );
125  int createCliques( OsiSolverInterface & si,
126  int minimumSize=2, int maximumSize=100);
128  void deleteCliques();
132  OsiSolverInterface * cliqueModel(const OsiSolverInterface * model,
133  int type);
135 
138  const double * tightLower() const;
141  const double * tightUpper() const;
143  const char * tightenBounds() const
144  { return tightenBounds_;}
146 
149  const double * relaxedRowLower() const;
152  const double * relaxedRowUpper() const;
154 
157  void setMode(int mode);
160  int getMode() const;
162 
165  void setMaxPass(int value);
168  int getMaxPass() const;
170  void setLogLevel(int value);
172  int getLogLevel() const;
174  void setMaxProbe(int value);
176  int getMaxProbe() const;
178  void setMaxLook(int value);
180  int getMaxLook() const;
182  void setMaxElements(int value);
184  int getMaxElements() const;
186  void setMaxPassRoot(int value);
188  int getMaxPassRoot() const;
190  void setMaxProbeRoot(int value);
192  int getMaxProbeRoot() const;
194  void setMaxLookRoot(int value);
196  int getMaxLookRoot() const;
198  void setMaxElementsRoot(int value);
200  int getMaxElementsRoot() const;
208  virtual bool mayGenerateRowCutsInTree() const;
210 
213  inline int numberThisTime() const
215  { return numberThisTime_;}
217  inline const int * lookedAt() const
218  { return lookedAt_;}
220 
223  void setRowCuts(int type);
227  int rowCuts() const;
229  typedef struct {
231  unsigned int equality:1; // nonzero if clique is ==
232  } CliqueType;
233 
236  inline int numberCliques() const
238  { return numberCliques_;}
240  inline CliqueType * cliqueType() const
241  { return cliqueType_;}
243  inline int * cliqueStart() const
244  { return cliqueStart_;}
246  inline CliqueEntry * cliqueEntry() const
247  { return cliqueEntry_;}
249 
257  void setUsingObjective(int yesNo);
259  int getUsingObjective() const;
261 
264  void tightenThese(const OsiSolverInterface & solver, int number, const int * which);
267 
270  CglProbing ();
272 
274  CglProbing (
275  const CglProbing &);
276 
278  virtual CglCutGenerator * clone() const;
279 
281  CglProbing &
282  operator=(
283  const CglProbing& rhs);
284 
286  virtual
287  ~CglProbing ();
288 
290  virtual void refreshSolver(OsiSolverInterface * solver);
292  virtual std::string generateCpp( FILE * fp);
294 
295 private:
296 
297  // Private member methods
300  int probe( const OsiSolverInterface & si,
302  const OsiRowCutDebugger * debugger,
303  OsiCuts & cs,
304  double * colLower, double * colUpper, CoinPackedMatrix *rowCopy,
305  CoinPackedMatrix *columnCopy,const CoinBigIndex * rowStartPos,
306  const int * realRow, const double * rowLower, const double * rowUpper,
307  const char * intVar, double * minR, double * maxR, int * markR,
308  CglTreeInfo * info);
310  int probeCliques( const OsiSolverInterface & si,
311  const OsiRowCutDebugger * debugger,
312  OsiCuts & cs,
313  double * colLower, double * colUpper, CoinPackedMatrix *rowCopy,
314  CoinPackedMatrix *columnCopy, const int * realRow,
315  double * rowLower, double * rowUpper,
316  char * intVar, double * minR, double * maxR, int * markR,
317  CglTreeInfo * info);
319  int probeSlacks( const OsiSolverInterface & si,
320  const OsiRowCutDebugger * debugger,
321  OsiCuts & cs,
322  double * colLower, double * colUpper, CoinPackedMatrix *rowCopy,
323  CoinPackedMatrix *columnCopy,
324  double * rowLower, double * rowUpper,
325  char * intVar, double * minR, double * maxR,int * markR,
326  CglTreeInfo * info);
329  int gutsOfGenerateCuts( const OsiSolverInterface & si,
330  OsiCuts & cs,
331  double * rowLower, double * rowUpper,
332  double * colLower, double * colUpper,
333  CglTreeInfo * info);
335  void setupRowCliqueInformation(const OsiSolverInterface & si);
338  int tighten(double *colLower, double * colUpper,
339  const int *column, const double *rowElements,
340  const CoinBigIndex *rowStart,const CoinBigIndex * rowStartPos,
341  const int * rowLength,
342  double *rowLower, double *rowUpper,
343  int nRows,int nCols,char * intVar,int maxpass,
344  double tolerance);
346  void tighten2(double *colLower, double * colUpper,
347  const int *column, const double *rowElements,
348  const CoinBigIndex *rowStart,
349  const int * rowLength,
350  double *rowLower, double *rowUpper,
351  double * minR, double * maxR, int * markR,
352  int nRows);
354 
355  // Private member data
356 
357  struct disaggregation_struct_tag ;
359 
362  CoinPackedMatrix * rowCopy_;
365  CoinPackedMatrix * columnCopy_;
367  double * rowLower_;
369  double * rowUpper_;
371  double * colLower_;
373  double * colUpper_;
375  int numberRows_;
377  int numberColumns_;
379  double primalTolerance_;
383  int mode_;
388  int rowCuts_;
390  int maxPass_;
392  int logLevel_;
394  int maxProbe_;
396  int maxStack_;
398  int maxElements_;
400  int maxPassRoot_;
402  int maxProbeRoot_;
404  int maxStackRoot_;
406  int maxElementsRoot_;
408  int usingObjective_;
410  int numberIntegers_;
412  int number01Integers_;
414  int numberThisTime_;
416  int totalTimesCalled_;
418  int * lookedAt_;
420  typedef struct disaggregation_struct_tag {
421  int sequence; // integer variable
422  // index will be NULL if no probing done yet
423  int length; // length of newValue
424  disaggregationAction * index; // columns whose bounds will be changed
425  } disaggregation;
426  disaggregation * cutVector_;
429  int numberCliques_;
431  CliqueType * cliqueType_;
433  int * cliqueStart_;
435  CliqueEntry * cliqueEntry_;
438  int * oneFixStart_;
441  int * zeroFixStart_;
443  int * endFixStart_;
445  int * whichClique_;
450  CliqueEntry * cliqueRow_;
452  int * cliqueRowStart_;
454  char * tightenBounds_;
456 };
458 { return dis.affected&0x1fffffff;}
460  int affected)
461 { dis.affected = affected|(dis.affected&0xe0000000);}
462 #ifdef NDEBUG
463 inline bool zeroOneInDisaggregation(const disaggregationAction & )
464 { return true;}
465 #else
467 //{ return (dis.affected&0x80000000)!=0;}
468 { assert ((dis.affected&0x80000000)!=0); return true;}
469 #endif
470 inline void setZeroOneInDisaggregation(disaggregationAction & dis,bool zeroOne)
471 { dis.affected = (zeroOne ? 0x80000000 : 0)|(dis.affected&0x7fffffff);}
473 { return (dis.affected&0x40000000)!=0;}
474 inline void setWhenAtUBInDisaggregation(disaggregationAction & dis,bool whenAtUB)
475 { dis.affected = (whenAtUB ? 0x40000000 : 0)|(dis.affected&0xbfffffff);}
477 { return (dis.affected&0x20000000)!=0;}
478 inline void setAffectedToUBInDisaggregation(disaggregationAction & dis,bool affectedToUB)
479 { dis.affected = (affectedToUB ? 0x20000000 : 0)|(dis.affected&0xdfffffff);}
480 
481 //#############################################################################
487 void CglProbingUnitTest(const OsiSolverInterface * siP,
488  const std::string mpdDir );
491 
492 public:
493 
499  virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
500  const CglTreeInfo info = CglTreeInfo());
502 
505  CglImplication ();
507 
510 
513  const CglImplication &);
514 
516  virtual CglCutGenerator * clone() const;
517 
520  operator=(
521  const CglImplication& rhs);
522 
524  virtual
525  ~CglImplication ();
527  virtual std::string generateCpp( FILE * fp);
529 
531  inline void setProbingInfo(CglTreeProbingInfo * info)
533  { probingInfo_=info;}
535 
536 private:
539  CglTreeProbingInfo * probingInfo_;
542 };
543 #endif
const char * tightenBounds() const
Array which says tighten continuous.
Definition: CglProbing.hpp:143
This just uses implication info.
Definition: CglProbing.hpp:490
void setMaxElements(int value)
Set maximum number of elements in row for it to be considered.
const double * relaxedRowUpper() const
Upper.
int getMaxProbeRoot() const
Get maximum number of unsatisfied variables to look at (root node)
void setMaxLookRoot(int value)
Set maximum number of variables to look at in one probe (root node)
int getMaxLookRoot() const
Get maximum number of variables to look at in one probe (root node)
void setMaxPass(int value)
Set maximum number of passes per node.
int getMaxPassRoot() const
Get maximum number of passes per node (root node)
void setWhenAtUBInDisaggregation(disaggregationAction &dis, bool whenAtUB)
Definition: CglProbing.hpp:474
virtual std::string generateCpp(FILE *fp)
Create C++ lines to get to current state.
int getMode() const
Get.
Information about where the cut generator is invoked from.
Definition: CglTreeInfo.hpp:15
int getLogLevel() const
Get log level.
CliqueEntry * cliqueEntry() const
Entries for clique.
Definition: CglProbing.hpp:246
const double * relaxedRowLower() const
Lower.
void setMode(int mode)
Set.
void setAffectedInDisaggregation(disaggregationAction &dis, int affected)
Definition: CglProbing.hpp:459
void deleteSnapshot()
Deletes snapshot.
int createCliques(OsiSolverInterface &si, int minimumSize=2, int maximumSize=100)
Creates cliques for use by probing.
int getMaxElements() const
Get maximum number of elements in row for it to be considered.
void setMaxLook(int value)
Set maximum number of variables to look at in one probe.
void setMaxElementsRoot(int value)
Set maximum number of elements in row for it to be considered (root node)
int getMaxPass() const
Get maximum number of passes per node.
unsigned int affected
Definition: CglProbing.hpp:21
OsiSolverInterface * cliqueModel(const OsiSolverInterface *model, int type)
Create a fake model by adding cliques if type&4 then delete rest of model first, if 1 then add proper...
Derived class to pick up probing info.
Definition: CglTreeInfo.hpp:79
bool zeroOneInDisaggregation(const disaggregationAction &dis)
Definition: CglProbing.hpp:466
const double * tightUpper() const
Upper.
int getUsingObjective() const
Get.
void setMaxProbe(int value)
Set maximum number of unsatisfied variables to look at.
Cut Generator Base Class.
friend struct CglProbing::disaggregation_struct_tag
Definition: CglProbing.hpp:357
Only useful type of disaggregation is most normal For now just done for 0-1 variables Can be used for...
Definition: CglProbing.hpp:16
CglProbing()
Default constructor.
bool affectedToUBInDisaggregation(const disaggregationAction &dis)
Definition: CglProbing.hpp:476
int * cliqueStart() const
Start of each clique.
Definition: CglProbing.hpp:243
const int * lookedAt() const
Which ones looked at this time.
Definition: CglProbing.hpp:217
virtual void generateCuts(const OsiSolverInterface &si, OsiCuts &cs, const CglTreeInfo info=CglTreeInfo())
Generate probing/disaggregation cuts for the model of the solver interface, si.
void setZeroOneInDisaggregation(disaggregationAction &dis, bool zeroOne)
Definition: CglProbing.hpp:470
virtual bool mayGenerateRowCutsInTree() const
Returns true if may generate Row cuts in tree (rather than root node).
int getMaxLook() const
Get maximum number of variables to look at in one probe.
int getMaxElementsRoot() const
Get maximum number of elements in row for it to be considered (root node)
int numberThisTime() const
Number looked at this time.
Definition: CglProbing.hpp:214
const double * tightLower() const
Lower.
void setLogLevel(int value)
Set log level - 0 none, 1 - a bit, 2 - more details.
void setAffectedToUBInDisaggregation(disaggregationAction &dis, bool affectedToUB)
Definition: CglProbing.hpp:478
virtual void refreshSolver(OsiSolverInterface *solver)
This can be used to refresh any inforamtion.
CliqueType * cliqueType() const
Clique type.
Definition: CglProbing.hpp:240
int numberCliques() const
Number of cliques.
Definition: CglProbing.hpp:237
void tightenThese(const OsiSolverInterface &solver, int number, const int *which)
Mark variables to be tightened.
int getMaxProbe() const
Get maximum number of unsatisfied variables to look at.
int snapshot(const OsiSolverInterface &si, char *possible=NULL, bool withObjective=true)
Create a copy of matrix which is to be used this is to speed up process and to give global cuts Can g...
void setUsingObjective(int yesNo)
Set 0 don&#39;t 1 do -1 don&#39;t even think about it.
friend void CglProbingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglProbing class.
bool whenAtUBInDisaggregation(const disaggregationAction &dis)
Definition: CglProbing.hpp:472
int generateCutsAndModify(const OsiSolverInterface &si, OsiCuts &cs, CglTreeInfo *info)
void setMaxProbeRoot(int value)
Set maximum number of unsatisfied variables to look at (root node)
virtual CglCutGenerator * clone() const
Clone.
void setRowCuts(int type)
Set 0 no cuts, 1 just disaggregation type, 2 coefficient ( 3 both)
int affectedInDisaggregation(const disaggregationAction &dis)
Definition: CglProbing.hpp:457
int rowCuts() const
Get.
virtual ~CglProbing()
Destructor.
Probing Cut Generator Class.
Definition: CglProbing.hpp:25
void setMaxPassRoot(int value)
Set maximum number of passes per node (root node)
CglProbing & operator=(const CglProbing &rhs)
Assignment operator.
void deleteCliques()
Delete all clique information.