Cgl  0.58.9
CglPreProcess.hpp
Go to the documentation of this file.
1 // Copyright (C) 2005, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 // This code is licensed under the terms of the Eclipse Public License (EPL).
4 
5 #ifndef CglPreProcess_H
6 #define CglPreProcess_H
7 
8 #include <string>
9 #include <vector>
10 
11 #include "CoinMessageHandler.hpp"
12 #include "OsiSolverInterface.hpp"
13 #include "CglStored.hpp"
14 #include "OsiPresolve.hpp"
15 #include "CglCutGenerator.hpp"
16 
17 //#############################################################################
18 
37 
38 public:
39 
41 
42 
51  OsiSolverInterface * preProcess(OsiSolverInterface & model,
52  bool makeEquality=false, int numberPasses=5);
64  OsiSolverInterface * preProcessNonDefault(OsiSolverInterface & model,
65  int makeEquality=0, int numberPasses=5,
66  int tuning=0);
68  void postProcess(OsiSolverInterface &model
69  ,bool deleteStuff=true);
77  int tightenPrimalBounds(OsiSolverInterface & model,double factor=0.0);
84  OsiSolverInterface * someFixed(OsiSolverInterface & model,
85  double fractionToKeep=0.25,
86  bool fixContinuousAsWell=false,
87  char * keep=NULL) const;
92  OsiSolverInterface * cliqueIt(OsiSolverInterface & model,
93  double cliquesNeeded=0.0) const;
95  int reducedCostFix(OsiSolverInterface & model);
97 
98  //---------------------------------------------------------------------------
99 
114  void setCutoff(double value) ;
115 
117  double getCutoff() const;
119  inline OsiSolverInterface * originalModel() const
120  { return originalModel_;}
122  inline OsiSolverInterface * startModel() const
123  { return startModel_;}
125  inline OsiSolverInterface * modelAtPass(int iPass) const
126  { if (iPass>=0&&iPass<numberSolvers_) return model_[iPass]; else return NULL;}
128  inline OsiSolverInterface * modifiedModel(int iPass) const
129  { if (iPass>=0&&iPass<numberSolvers_) return modifiedModel_[iPass]; else return NULL;}
131  inline OsiPresolve * presolve(int iPass) const
132  { if (iPass>=0&&iPass<numberSolvers_) return presolve_[iPass]; else return NULL;}
135  const int * originalColumns();
138  const int * originalRows();
140  inline int numberSOS() const
141  { return numberSOS_;}
143  inline const int * typeSOS() const
144  { return typeSOS_;}
146  inline const int * startSOS() const
147  { return startSOS_;}
149  inline const int * whichSOS() const
150  { return whichSOS_;}
152  inline const double * weightSOS() const
153  { return weightSOS_;}
155  void passInProhibited(const char * prohibited,int numberColumns);
157  inline const char * prohibited()
158  { return prohibited_;}
160  inline int numberIterationsPre() const
161  { return numberIterationsPre_;}
163  inline int numberIterationsPost() const
164  { return numberIterationsPost_;}
171  void passInRowTypes(const char * rowTypes,int numberRows);
178  inline const char * rowTypes()
179  { return rowType_;}
181  inline const CglStored & cuts() const
182  { return cuts_;}
184  inline const CglStored * cutsPointer() const
185  { return &cuts_;}
187  void update(const OsiPresolve * pinfo,const OsiSolverInterface * solver);
189  inline void setOptions(int value)
190  { options_=value;}
192 
194 
195  inline int numberCutGenerators() const
197  { return numberCutGenerators_;}
199  inline CglCutGenerator ** cutGenerators() const
200  { return generator_;}
202  inline CglCutGenerator * cutGenerator(int i) const
203  { return generator_[i];}
206  void addCutGenerator(CglCutGenerator * generator);
208 
218  void setApplicationData (void * appData);
219 
221  void * getApplicationData() const;
223 
224  //---------------------------------------------------------------------------
225 
228  void passInMessageHandler(CoinMessageHandler * handler);
231  void newLanguage(CoinMessages::Language language);
232  inline void setLanguage(CoinMessages::Language language)
233  {newLanguage(language);}
235  inline CoinMessageHandler * messageHandler() const
236  {return handler_;}
238  inline CoinMessages messages()
239  {return messages_;}
241  inline CoinMessages * messagesPointer()
242  {return &messages_;}
244  //---------------------------------------------------------------------------
245 
246 
248 
249  CglPreProcess();
251 
253  CglPreProcess(const CglPreProcess & rhs);
254 
256  CglPreProcess & operator=(const CglPreProcess& rhs);
257 
259  ~CglPreProcess ();
260 
262  void gutsOfDestructor();
264 private:
265 
267 
268 
272  OsiSolverInterface * modified(OsiSolverInterface * model,
273  bool constraints,
274  int & numberChanges,
275  int iBigPass,
276  int numberPasses);
278  void createOriginalIndices();
280  void makeInteger();
282 
283 //---------------------------------------------------------------------------
284 
285 private:
287 
288 
290  OsiSolverInterface * originalModel_;
292  OsiSolverInterface * startModel_;
294  int numberSolvers_;
296  OsiSolverInterface ** model_;
298  OsiSolverInterface ** modifiedModel_;
300  OsiPresolve ** presolve_;
301 
303  CoinMessageHandler * handler_;
304 
310  bool defaultHandler_;
311 
313  CoinMessages messages_;
314 
316  void * appData_;
318  int * originalColumn_;
320  int * originalRow_;
322  int numberCutGenerators_;
324  CglCutGenerator ** generator_;
326  int numberSOS_;
328  int * typeSOS_;
330  int * startSOS_;
332  int * whichSOS_;
334  double * weightSOS_;
336  int numberProhibited_;
338  int numberIterationsPre_;
340  int numberIterationsPost_;
342  char * prohibited_;
344  int numberRowType_;
351  int options_;
358  char * rowType_;
360  CglStored cuts_;
362 };
364 class CglBK {
365 
366 public:
367 
369 
370  void bronKerbosch();
373  OsiSolverInterface * newSolver(const OsiSolverInterface & model);
375 
376  //---------------------------------------------------------------------------
377 
387 
388 
389  //---------------------------------------------------------------------------
390 
391 
393 
394  CglBK();
396 
398  CglBK(const OsiSolverInterface & model, const char * rowType,
399  int numberElements);
400 
402  CglBK(const CglBK & rhs);
403 
405  CglBK & operator=(const CglBK& rhs);
406 
408  ~CglBK ();
409 
411 
412 //---------------------------------------------------------------------------
413 
414 private:
416 
417  int * candidates_;
420  char * mark_;
422  int * start_;
424  int * otherColumn_;
426  int * originalRow_;
428  int * dominated_;
430  CoinPackedMatrix * cliqueMatrix_;
432  const char * rowType_;
434  int numberColumns_;
436  int numberRows_;
438  int numberPossible_;
440  int numberCandidates_;
442  int firstNot_;
444  int numberIn_;
446  int left_;
447  int lastColumn_;
449 };
453 // for hashing
454 typedef struct {
455  int index, next;
456 } CglHashLink;
457 class OsiRowCut;
459 public:
460 
461  CglUniqueRowCuts(int initialMaxSize=0, int hashMultiplier=4 );
465  inline OsiRowCut * cut(int sequence) const
466  { return rowCut_[sequence];}
467  inline int numberCuts() const
468  { return numberCuts_;}
469  inline int sizeRowCuts() const
470  { return numberCuts_;}
471  inline OsiRowCut * rowCutPtr(int sequence)
472  { return rowCut_[sequence];}
473  void eraseRowCut(int sequence);
474  // insert cut
475  inline void insert(const OsiRowCut & cut)
476  { insertIfNotDuplicate(cut);}
477  // Return 0 if added, 1 if not
478  int insertIfNotDuplicate(const OsiRowCut & cut);
479  // Add in cuts as normal cuts (and delete)
480  void addCuts(OsiCuts & cs);
481 private:
482  OsiRowCut ** rowCut_;
484  CglHashLink *hash_;
485  int size_;
486  int hashMultiplier_;
487  int numberCuts_;
488  int lastHash_;
489 };
490 #endif
const double * weightSOS() const
Weights for each SOS column.
void gutsOfDestructor()
Clears out as much as possible.
int numberCuts() const
int tightenPrimalBounds(OsiSolverInterface &model, double factor=0.0)
Tightens primal bounds to make dual and branch and cutfaster.
For Bron-Kerbosch.
void newLanguage(CoinMessages::Language language)
Set language.
CglUniqueRowCuts(int initialMaxSize=0, int hashMultiplier=4)
void addCutGenerator(CglCutGenerator *generator)
Add one generator - up to user to delete generators.
OsiRowCut * cut(int sequence) const
Stored Cut Generator Class.
Definition: CglStored.hpp:16
CglCutGenerator ** cutGenerators() const
Get the list of cut generators.
void update(const OsiPresolve *pinfo, const OsiSolverInterface *solver)
Update prohibited and rowType.
int sizeRowCuts() const
void setApplicationData(void *appData)
Set application data.
CglPreProcess & operator=(const CglPreProcess &rhs)
Assignment operator.
void setLanguage(CoinMessages::Language language)
CglBK & operator=(const CglBK &rhs)
Assignment operator.
~CglBK()
Destructor.
OsiSolverInterface * cliqueIt(OsiSolverInterface &model, double cliquesNeeded=0.0) const
Replace cliques by more maximal cliques Returns NULL if rows not reduced by greater than cliquesNeede...
OsiSolverInterface * newSolver(const OsiSolverInterface &model)
Creates strengthened smaller model.
void postProcess(OsiSolverInterface &model, bool deleteStuff=true)
Creates solution in original model.
void bronKerbosch()
For recursive Bron-Kerbosch.
void setOptions(int value)
Set options.
OsiSolverInterface * preProcessNonDefault(OsiSolverInterface &model, int makeEquality=0, int numberPasses=5, int tuning=0)
preProcess problem - returning new problem.
int numberIterationsPre() const
Number of iterations PreProcessing.
const int * whichSOS() const
Columns in SOS.
OsiSolverInterface * someFixed(OsiSolverInterface &model, double fractionToKeep=0.25, bool fixContinuousAsWell=false, char *keep=NULL) const
Fix some of problem - returning new problem.
Cut Generator Base Class.
int numberSOS() const
Number of SOS if found.
int numberIterationsPost() const
Number of iterations PostProcessing.
void eraseRowCut(int sequence)
void addCuts(OsiCuts &cs)
void passInMessageHandler(CoinMessageHandler *handler)
Pass in Message handler (not deleted at end)
CglCutGenerator * cutGenerator(int i) const
Get the specified cut generator.
void passInRowTypes(const char *rowTypes, int numberRows)
Pass in row types 0 normal 1 cut rows - will be dropped if remain in At end of preprocess cut rows wi...
void insert(const OsiRowCut &cut)
OsiSolverInterface * originalModel() const
The original solver associated with this model.
OsiSolverInterface * modelAtPass(int iPass) const
Copies of solver at various stages after presolve.
CglUniqueRowCuts & operator=(const CglUniqueRowCuts &rhs)
const int * originalColumns()
Return a pointer to the original columns (with possible clique slacks) MUST be called before postProc...
CoinMessages * messagesPointer()
Return pointer to messages.
const CglStored & cuts() const
Return cuts from dropped rows.
CglPreProcess()
Constructor.
const CglStored * cutsPointer() const
Return pointer to cuts from dropped rows.
void setCutoff(double value)
Set cutoff bound on the objective function.
OsiSolverInterface * startModel() const
Solver after making clique equalities (may == original)
OsiPresolve * presolve(int iPass) const
Matching presolve information.
OsiSolverInterface * modifiedModel(int iPass) const
Copies of solver at various stages after presolve after modifications.
void passInProhibited(const char *prohibited, int numberColumns)
Pass in prohibited columns.
OsiRowCut * rowCutPtr(int sequence)
OsiSolverInterface * preProcess(OsiSolverInterface &model, bool makeEquality=false, int numberPasses=5)
preProcess problem - returning new problem.
const char * rowTypes()
Updated row types - may be NULL Carried around and corresponds to existing rows -1 added by preproces...
const int * startSOS() const
Start of each SOS.
int numberCutGenerators() const
Get the number of cut generators.
const char * prohibited()
Updated prohibited columns.
Class for preProcessing and postProcessing.
CoinMessageHandler * messageHandler() const
Return handler.
CoinMessages messages()
Return messages.
void * getApplicationData() const
Get application data.
int reducedCostFix(OsiSolverInterface &model)
If we have a cutoff - fix variables.
~CglPreProcess()
Destructor.
CglBK()
Default constructor.
double getCutoff() const
Get the cutoff bound on the objective function - always as minimize.
const int * originalRows()
Return a pointer to the original rows MUST be called before postProcess otherwise you just get 0...
const int * typeSOS() const
Type of each SOS.
int insertIfNotDuplicate(const OsiRowCut &cut)