coin-Bcp
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 
38 
39 public:
41 
42 
52  bool makeEquality = false, int numberPasses = 5);
65  int makeEquality = 0, int numberPasses = 5,
66  int tuning = 0);
69  void postProcess(OsiSolverInterface &model, int deleteStuff = 2);
77  int tightenPrimalBounds(OsiSolverInterface &model, double factor = 0.0);
85  double fractionToKeep = 0.25,
86  bool fixContinuousAsWell = false,
87  char *keep = NULL) const;
93  double cliquesNeeded = 0.0) const;
97 
98  //---------------------------------------------------------------------------
99 
114  void setCutoff(double value);
115 
117  double getCutoff() const;
120  {
121  return originalModel_;
122  }
125  {
127  }
130  {
131  return startModel_;
132  }
134  inline int numberSolvers() const
135  {
136  return numberSolvers_;
137  }
139  inline OsiSolverInterface *modelAtPass(int iPass) const
140  {
141  if (iPass >= 0 && iPass < numberSolvers_)
142  return model_[iPass];
143  else
144  return NULL;
145  }
147  inline OsiSolverInterface *modifiedModel(int iPass) const
148  {
149  if (iPass >= 0 && iPass < numberSolvers_)
150  return modifiedModel_[iPass];
151  else
152  return NULL;
153  }
155  inline OsiPresolve *presolve(int iPass) const
156  {
157  if (iPass >= 0 && iPass < numberSolvers_)
158  return presolve_[iPass];
159  else
160  return NULL;
161  }
163  inline void setPresolve(int iPass, OsiPresolve *presolve)
164  {
165  if (iPass >= 0 && iPass < numberSolvers_)
166  presolve_[iPass] = presolve;
167  }
170  const int *originalColumns();
173  const int *originalRows();
175  inline int numberSOS() const
176  {
177  return numberSOS_;
178  }
180  inline const int *typeSOS() const
181  {
182  return typeSOS_;
183  }
185  inline const int *startSOS() const
186  {
187  return startSOS_;
188  }
190  inline const int *whichSOS() const
191  {
192  return whichSOS_;
193  }
195  inline const double *weightSOS() const
196  {
197  return weightSOS_;
198  }
200  void passInProhibited(const char *prohibited, int numberColumns);
202  inline const char *prohibited()
203  {
204  return prohibited_;
205  }
207  inline int numberIterationsPre() const
208  {
209  return numberIterationsPre_;
210  }
212  inline int numberIterationsPost() const
213  {
214  return numberIterationsPost_;
215  }
222  void passInRowTypes(const char *rowTypes, int numberRows);
229  inline const char *rowTypes()
230  {
231  return rowType_;
232  }
234  inline const CglStored &cuts() const
235  {
236  return cuts_;
237  }
239  inline const CglStored *cutsPointer() const
240  {
241  return &cuts_;
242  }
244  void update(const OsiPresolve *pinfo, const OsiSolverInterface *solver);
246  inline int options() const
247  {
248  return options_;
249  }
251  inline void setOptions(int value)
252  {
253  options_ = value;
254  }
256 
258 
259  inline int numberCutGenerators() const
261  {
262  return numberCutGenerators_;
263  }
266  {
267  return generator_;
268  }
270  inline CglCutGenerator *cutGenerator(int i) const
271  {
272  return generator_[i];
273  }
276  void addCutGenerator(CglCutGenerator *generator);
278 
288  void setApplicationData(void *appData);
289 
291  void *getApplicationData() const;
293 
294  //---------------------------------------------------------------------------
295 
301  void newLanguage(CoinMessages::Language language);
302  inline void setLanguage(CoinMessages::Language language)
303  {
304  newLanguage(language);
305  }
308  {
309  return handler_;
310  }
313  {
314  return messages_;
315  }
318  {
319  return &messages_;
320  }
322  //---------------------------------------------------------------------------
323 
325 
326  CglPreProcess();
328 
330  CglPreProcess(const CglPreProcess &rhs);
331 
334 
336  ~CglPreProcess();
337 
339  void gutsOfDestructor();
340 
342  void setTimeLimit(const double timeLimit, const bool useElapsedTime);
343 
345  void setKeepColumnNames(const bool keep);
346 
348 private:
350 
351 
356  bool constraints,
357  int &numberChanges,
358  int iBigPass,
359  int numberPasses);
361  void createOriginalIndices();
363  void makeInteger();
365 
366  //---------------------------------------------------------------------------
367 
368 private:
370 
371 
384 
387 
394 
397 
399  void *appData_;
411  int *typeSOS_;
413  int *startSOS_;
415  int *whichSOS_;
417  double *weightSOS_;
425  char *prohibited_;
436  int options_;
443  char *rowType_;
446 
449 
451  double timeLimit_;
452 
455 
457  double getCurrentCPUTime() const;
458 
460 };
461 
463 class CglBK {
464 
465 public:
467 
468  void bronKerbosch();
473 
474  //---------------------------------------------------------------------------
475 
485 
486 
487  //---------------------------------------------------------------------------
488 
490 
491  CglBK();
493 
495  CglBK(const OsiSolverInterface &model, const char *rowType,
496  int numberElements);
497 
499  CglBK(const CglBK &rhs);
500 
502  CglBK &operator=(const CglBK &rhs);
503 
505  ~CglBK();
506 
508 
509  //---------------------------------------------------------------------------
510 
511 private:
513 
514  int *candidates_;
517  char *mark_;
529  const char *rowType_;
543  int left_;
546 };
550 // for hashing
551 typedef struct {
552  int index, next;
553 } CglHashLink;
554 class OsiRowCut;
556 public:
557  CglUniqueRowCuts(int initialMaxSize = 0, int hashMultiplier = 4);
561  inline OsiRowCut *cut(int sequence) const
562  {
563  return rowCut_[sequence];
564  }
565  inline int numberCuts() const
566  {
567  return numberCuts_;
568  }
569  inline int sizeRowCuts() const
570  {
571  return numberCuts_;
572  }
573  inline OsiRowCut *rowCutPtr(int sequence)
574  {
575  return rowCut_[sequence];
576  }
577  void eraseRowCut(int sequence);
578  // insert cut
579  inline void insert(const OsiRowCut &cut)
580  {
582  }
583  // Return 0 if added, 1 if not
584  int insertIfNotDuplicate(const OsiRowCut &cut);
585  // Add in cuts as normal cuts (and delete)
586  void addCuts(OsiCuts &cs);
587 
588 private:
592  int size_;
596 };
597 #endif
598 
599 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
600 */
const char * prohibited()
Updated prohibited columns.
int numberCutGenerators() const
Get the number of cut generators.
int numberRowType_
Number of rows in original row types.
int CoinBigIndex
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...
char * prohibited_
Columns which should not be presolved e.g. SOS.
void setOriginalModel(OsiSolverInterface *originalModel)
Set original model (probably acopy)
int * originalRow_
Original row numbers.
void passInProhibited(const char *prohibited, int numberColumns)
Pass in prohibited columns.
void postProcess(OsiSolverInterface &model, int deleteStuff=2)
Creates solution in original model deleteStuff 0 - don&#39;t, 1 do (but not if infeasible), 2 always.
Base class for message handling.
CglUniqueRowCuts(int initialMaxSize=0, int hashMultiplier=4)
double * weightSOS_
Weights for each SOS column.
int * startSOS_
Start of each SOS.
int numberIterationsPre_
Number of iterations done in PreProcessing.
int numberSOS() const
Number of SOS if found.
bool defaultHandler_
Flag to say if handler_ is the default handler.
void bronKerbosch()
For recursive Bron-Kerbosch.
void setLanguage(CoinMessages::Language language)
Pass in Message handler (not deleted at end)
Row Cut Class.
Definition: OsiRowCut.hpp:29
int * originalColumn_
Original column numbers.
int numberRows_
Number of original rows.
int numberIn_
Current number in clique.
Class for preProcessing and postProcessing.
void eraseRowCut(int sequence)
int * candidates_
Current candidates (created at each level)
void passInMessageHandler(CoinMessageHandler *handler)
Pass in Message handler (not deleted at end)
~CglPreProcess()
Destructor.
int numberSolvers() const
Number of solvers.
char * rowType_
Row types (may be NULL) Carried around and corresponds to existing rows -1 added by preprocess e...
CoinMessages * messagesPointer()
Return pointer to messages.
const char * rowTypes()
Updated row types - may be NULL Carried around and corresponds to existing rows -1 added by preproces...
void insert(const OsiRowCut &cut)
const int * originalRows()
Return a pointer to the original rows MUST be called before postProcess otherwise you just get 0...
void setTimeLimit(const double timeLimit, const bool useElapsedTime)
Set time limit.
int numberIterationsPre() const
Number of iterations PreProcessing.
Sparse Matrix Base Class.
CglCutGenerator * cutGenerator(int i) const
Get the specified cut generator.
CglCutGenerator ** cutGenerators() const
Get the list of cut generators.
bool useElapsedTime_
use elapsed (wallclock time) or cpu time
~CglBK()
Destructor.
Collections of row cuts and column cuts.
Definition: OsiCuts.hpp:19
int numberSolvers_
Number of solvers at various stages.
int numberCandidates_
Current number of candidates.
const int * whichSOS() const
Columns in SOS.
OsiRowCut ** rowCut_
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...
void addCuts(OsiCuts &cs)
int numberProhibited_
Number of columns in original prohibition set.
int numberIterationsPost() const
Number of iterations PostProcessing.
int numberPossible_
Number possible.
void update(const OsiPresolve *pinfo, const OsiSolverInterface *solver)
Update prohibited and rowType.
int firstNot_
First not (stored backwards from numberPossible_)
OsiPresolve * presolve(int iPass) const
Matching presolve information.
OsiSolverInterface * someFixed(OsiSolverInterface &model, double fractionToKeep=0.25, bool fixContinuousAsWell=false, char *keep=NULL) const
Fix some of problem - returning new problem.
OsiSolverInterface * startModel_
Solver after making clique equalities (may == original)
double timeLimit_
time limit (default COIN_DBL_MAX)
OsiSolverInterface * startModel() const
Solver after making clique equalities (may == original)
OsiSolverInterface * preProcessNonDefault(OsiSolverInterface &model, int makeEquality=0, int numberPasses=5, int tuning=0)
preProcess problem - returning new problem.
int numberIterationsPost_
Number of iterations done in PostProcessing.
OSI interface to COIN problem simplification capabilities.
Definition: OsiPresolve.hpp:59
const int * originalColumns()
Return a pointer to the original columns (with possible clique slacks) MUST be called before postProc...
OsiSolverInterface * originalModel() const
The original solver associated with this model.
const int * startSOS() const
Start of each SOS.
CglPreProcess()
Constructor.
int * whichSOS_
Columns in SOS.
int numberSOS_
Number of SOS if found.
OsiSolverInterface * modified(OsiSolverInterface *model, bool constraints, int &numberChanges, int iBigPass, int numberPasses)
Return model with useful modifications.
This is a first attempt at a message handler.
int lastColumn_
Current candidates (created at each level)
void setCutoff(double value)
Set cutoff bound on the objective function.
OsiRowCut * cut(int sequence) const
void * appData_
Pointer to user-defined data structure.
Abstract Base Class for describing an interface to a solver.
void makeInteger()
Make continuous variables integer.
CglPreProcess & operator=(const CglPreProcess &rhs)
Assignment operator.
Cut Generator Base Class.
CoinMessageHandler * messageHandler() const
Return handler.
void gutsOfDestructor()
Clears out as much as possible.
int insertIfNotDuplicate(const OsiRowCut &cut)
int options_
Options 1 - original model had integer bounds before tightening 2 - don&#39;t do probing 4 - don&#39;t do dup...
CglStored cuts_
Cuts from dropped rows.
Class to hold and manipulate an array of massaged messages.
int * typeSOS_
Type of each SOS.
const char * rowType_
points to row types
const CglStored * cutsPointer() const
Return pointer to cuts from dropped rows.
void * getApplicationData() const
Get application data.
OsiSolverInterface * modifiedModel(int iPass) const
Copies of solver at various stages after presolve after modifications.
For Bron-Kerbosch.
OsiPresolve ** presolve_
Matching presolve information.
CoinBigIndex * start_
Starts for graph (numberPossible+1)
CglUniqueRowCuts & operator=(const CglUniqueRowCuts &rhs)
void newLanguage(CoinMessages::Language language)
Set language.
int reducedCostFix(OsiSolverInterface &model)
If we have a cutoff - fix variables.
OsiRowCut * rowCutPtr(int sequence)
const CglStored & cuts() const
Return cuts from dropped rows.
int * dominated_
How many times each original row dominated.
int numberCuts() const
void setApplicationData(void *appData)
Set application data.
int tightenPrimalBounds(OsiSolverInterface &model, double factor=0.0)
Tightens primal bounds to make dual and branch and cutfaster.
bool keepColumnNames_
keep column names
int numberColumns_
Number of original columns.
CoinMessages messages()
Return messages.
Stored Cut Generator Class.
Definition: CglStored.hpp:16
OsiSolverInterface * preProcess(OsiSolverInterface &model, bool makeEquality=false, int numberPasses=5)
preProcess problem - returning new problem.
CglBK & operator=(const CglBK &rhs)
Assignment operator.
CoinMessageHandler * handler_
Message handler.
OsiSolverInterface ** modifiedModel_
Copies of solver at various stages after presolve after modifications.
CoinPackedMatrix * cliqueMatrix_
Clique entries.
OsiSolverInterface * newSolver(const OsiSolverInterface &model)
Creates strengthened smaller model.
CglBK()
Default constructor.
int * originalRow_
Original row (in parallel with otherColumn_)
CoinMessages messages_
Cgl messages.
void addCutGenerator(CglCutGenerator *generator)
Add one generator - up to user to delete generators.
void setPresolve(int iPass, OsiPresolve *presolve)
Set matching presolve information.
CglCutGenerator ** generator_
Cut generators.
int sizeRowCuts() const
const int * typeSOS() const
Type of each SOS.
Language
Supported languages.
const double * weightSOS() const
Weights for each SOS column.
OsiSolverInterface * originalModel_
The original solver associated with this model.
void createOriginalIndices()
create original columns and rows
void setOptions(int value)
Set options.
CglHashLink * hash_
Hash table.
OsiSolverInterface ** model_
Copies of solver at various stages after presolve.
int numberCutGenerators_
Number of cut generators.
double getCurrentCPUTime() const
current elapsed or cpu time
int * otherColumn_
Other column/node.
void setKeepColumnNames(const bool keep)
Keeps original column names.
char * mark_
Array to mark stuff.
double getCutoff() const
Get the cutoff bound on the objective function - always as minimize.
OsiSolverInterface * modelAtPass(int iPass) const
Copies of solver at various stages after presolve.
int options() const
Get options.
int left_
For acceleration.