Cgl 0.60.3
Loading...
Searching...
No Matches
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
39public:
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);
69 void postProcess(OsiSolverInterface &model, int deleteStuff = 2);
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 {
121 return originalModel_;
122 }
124 inline void setOriginalModel(OsiSolverInterface *originalModel)
125 {
127 }
129 inline OsiSolverInterface *startModel() const
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 {
210 }
212 inline int numberIterationsPost() const
213 {
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
260 inline int numberCutGenerators() const
261 {
263 }
266 {
267 return generator_;
268 }
270 inline CglCutGenerator *cutGenerator(int i) const
271 {
272 return generator_[i];
273 }
278
288 void setApplicationData(void *appData);
289
291 void *getApplicationData() const;
293
294 //---------------------------------------------------------------------------
295
299 void passInMessageHandler(CoinMessageHandler *handler);
301 void newLanguage(CoinMessages::Language language);
302 inline void setLanguage(CoinMessages::Language language)
303 {
304 newLanguage(language);
305 }
307 inline CoinMessageHandler *messageHandler() const
308 {
309 return handler_;
310 }
312 inline CoinMessages messages()
313 {
314 return messages_;
315 }
317 inline CoinMessages *messagesPointer()
318 {
319 return &messages_;
320 }
322 //---------------------------------------------------------------------------
323
325
326
328
331
334
337
340
342 void setTimeLimit(const double timeLimit, const bool useElapsedTime);
343
345 void setKeepColumnNames(const bool keep);
346
348private:
350
351
355 OsiSolverInterface *modified(OsiSolverInterface *model,
356 bool constraints,
357 int &numberChanges,
358 int iBigPass,
359 int numberPasses);
365
366 //---------------------------------------------------------------------------
367
368private:
370
371
373 OsiSolverInterface *originalModel_;
375 OsiSolverInterface *startModel_;
379 OsiSolverInterface **model_;
381 OsiSolverInterface **modifiedModel_;
383 OsiPresolve **presolve_;
384
386 CoinMessageHandler *handler_;
387
394
396 CoinMessages messages_;
397
399 void *appData_;
417 double *weightSOS_;
443 char *rowType_;
446
449
452
455
457 double getCurrentCPUTime() const;
458
460};
461
463class CglBK {
464
465public:
467
468
471 OsiSolverInterface *newSolver(const OsiSolverInterface &model);
473
474 //---------------------------------------------------------------------------
475
486
487 //---------------------------------------------------------------------------
488
490
491
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
506
508
509 //---------------------------------------------------------------------------
510
511private:
513
514
517 char *mark_;
519 CoinBigIndex *start_;
527 CoinPackedMatrix *cliqueMatrix_;
529 const char *rowType_;
543 int left_;
546};
550// for hashing
551typedef struct {
552 int index, next;
554class OsiRowCut;
556public:
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
588private:
589 OsiRowCut **rowCut_;
592 int size_;
596};
597#endif
598
599/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
600*/
For Bron-Kerbosch.
CglBK(const OsiSolverInterface &model, const char *rowType, int numberElements)
Useful constructor.
char * mark_
Array to mark stuff.
int firstNot_
First not (stored backwards from numberPossible_)
CglBK(const CglBK &rhs)
Copy constructor .
int numberRows_
Number of original rows.
int * otherColumn_
Other column/node.
CglBK & operator=(const CglBK &rhs)
Assignment operator.
int numberCandidates_
Current number of candidates.
int numberColumns_
Number of original columns.
const char * rowType_
points to row types
~CglBK()
Destructor.
int left_
For acceleration.
CoinBigIndex * start_
Starts for graph (numberPossible+1)
CoinPackedMatrix * cliqueMatrix_
Clique entries.
int numberIn_
Current number in clique.
int * originalRow_
Original row (in parallel with otherColumn_)
int * candidates_
Current candidates (created at each level)
int lastColumn_
CglBK()
Default constructor.
int * dominated_
How many times each original row dominated.
int numberPossible_
Number possible.
OsiSolverInterface * newSolver(const OsiSolverInterface &model)
Creates strengthened smaller model.
void bronKerbosch()
For recursive Bron-Kerbosch.
Cut Generator Base Class.
Class for preProcessing and postProcessing.
void passInProhibited(const char *prohibited, int numberColumns)
Pass in prohibited columns.
double timeLimit_
time limit (default COIN_DBL_MAX)
const int * originalRows()
Return a pointer to the original rows MUST be called before postProcess otherwise you just get 0,...
CoinMessages * messagesPointer()
Return pointer to messages.
void setCutoff(double value)
Set cutoff bound on the objective function.
void setApplicationData(void *appData)
Set application data.
OsiSolverInterface * preProcessNonDefault(OsiSolverInterface &model, int makeEquality=0, int numberPasses=5, int tuning=0)
preProcess problem - returning new problem.
CglPreProcess(const CglPreProcess &rhs)
Copy constructor .
~CglPreProcess()
Destructor.
OsiSolverInterface * startModel() const
Solver after making clique equalities (may == original)
int numberProhibited_
Number of columns in original prohibition set.
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 passInMessageHandler(CoinMessageHandler *handler)
Pass in Message handler (not deleted at end)
int numberRowType_
Number of rows in original row types.
const char * prohibited()
Updated prohibited columns.
int * startSOS_
Start of each SOS.
int * whichSOS_
Columns in SOS.
char * rowType_
Row types (may be NULL) Carried around and corresponds to existing rows -1 added by preprocess e....
CglCutGenerator * cutGenerator(int i) const
Get the specified cut generator.
char * prohibited_
Columns which should not be presolved e.g. SOS.
CglPreProcess()
Constructor.
OsiSolverInterface * modelAtPass(int iPass) const
Copies of solver at various stages after presolve.
const double * weightSOS() const
Weights for each SOS column.
OsiSolverInterface * modified(OsiSolverInterface *model, bool constraints, int &numberChanges, int iBigPass, int numberPasses)
Return model with useful modifications.
int numberCutGenerators() const
Get the number of cut generators.
CoinMessageHandler * handler_
Message handler.
bool useElapsedTime_
use elapsed (wallclock time) or cpu time
void makeInteger()
Make continuous variables integer.
OsiPresolve ** presolve_
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.
int numberIterationsPre() const
Number of iterations PreProcessing.
CglCutGenerator ** generator_
Cut generators.
CglStored cuts_
Cuts from dropped rows.
OsiSolverInterface * preProcess(OsiSolverInterface &model, bool makeEquality=false, int numberPasses=5)
preProcess problem - returning new problem.
CoinMessageHandler * messageHandler() const
Return handler.
int numberSOS_
Number of SOS if found.
void setKeepColumnNames(const bool keep)
Keeps original column names.
int * typeSOS_
Type of each SOS.
OsiSolverInterface ** model_
Copies of solver at various stages after presolve.
OsiSolverInterface ** modifiedModel_
Copies of solver at various stages after presolve after modifications.
const CglStored * cutsPointer() const
Return pointer to cuts from dropped rows.
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...
int * originalRow_
Original row numbers.
int numberIterationsPre_
Number of iterations done in PreProcessing.
const int * originalColumns()
Return a pointer to the original columns (with possible clique slacks) MUST be called before postProc...
CglPreProcess & operator=(const CglPreProcess &rhs)
Assignment operator.
CoinMessages messages()
Return messages.
int reducedCostFix(OsiSolverInterface &model)
If we have a cutoff - fix variables.
void * getApplicationData() const
Get application data.
void setOptions(int value)
Set options.
int numberSolvers() const
Number of solvers.
int numberSOS() const
Number of SOS if found.
OsiSolverInterface * startModel_
Solver after making clique equalities (may == original)
bool keepColumnNames_
keep column names
double * weightSOS_
Weights for each SOS column.
void postProcess(OsiSolverInterface &model, int deleteStuff=2)
Creates solution in original model deleteStuff 0 - don't, 1 do (but not if infeasible),...
OsiSolverInterface * modifiedModel(int iPass) const
Copies of solver at various stages after presolve after modifications.
int options() const
Get options.
double getCurrentCPUTime() const
current elapsed or cpu time
int numberSolvers_
Number of solvers at various stages.
void setOriginalModel(OsiSolverInterface *originalModel)
Set original model (probably acopy)
const CglStored & cuts() const
Return cuts from dropped rows.
const char * rowTypes()
Updated row types - may be NULL Carried around and corresponds to existing rows -1 added by preproces...
int numberCutGenerators_
Number of cut generators.
void setPresolve(int iPass, OsiPresolve *presolve)
Set matching presolve information.
int numberIterationsPost() const
Number of iterations PostProcessing.
void setLanguage(CoinMessages::Language language)
const int * typeSOS() const
Type of each SOS.
OsiPresolve * presolve(int iPass) const
Matching presolve information.
int * originalColumn_
Original column numbers.
void gutsOfDestructor()
Clears out as much as possible.
OsiSolverInterface * originalModel() const
The original solver associated with this model.
const int * startSOS() const
Start of each SOS.
int numberIterationsPost_
Number of iterations done in PostProcessing.
void update(const OsiPresolve *pinfo, const OsiSolverInterface *solver)
Update prohibited and rowType.
CoinMessages messages_
Cgl messages.
bool defaultHandler_
Flag to say if handler_ is the default handler.
void newLanguage(CoinMessages::Language language)
Set language.
int options_
Options 1 - original model had integer bounds before tightening 2 - don't do probing 4 - don't do dup...
double getCutoff() const
Get the cutoff bound on the objective function - always as minimize.
void * appData_
Pointer to user-defined data structure.
void addCutGenerator(CglCutGenerator *generator)
Add one generator - up to user to delete generators.
int tightenPrimalBounds(OsiSolverInterface &model, double factor=0.0)
Tightens primal bounds to make dual and branch and cutfaster.
void setTimeLimit(const double timeLimit, const bool useElapsedTime)
Set time limit.
CglCutGenerator ** cutGenerators() const
Get the list of cut generators.
void createOriginalIndices()
create original columns and rows
OsiSolverInterface * originalModel_
The original solver associated with this model.
const int * whichSOS() const
Columns in SOS.
Stored Cut Generator Class.
Definition CglStored.hpp:16
CglUniqueRowCuts(int initialMaxSize=0, int hashMultiplier=4)
OsiRowCut * cut(int sequence) const
void addCuts(OsiCuts &cs)
void insert(const OsiRowCut &cut)
int insertIfNotDuplicate(const OsiRowCut &cut)
CglUniqueRowCuts & operator=(const CglUniqueRowCuts &rhs)
OsiRowCut * rowCutPtr(int sequence)
int sizeRowCuts() const
int numberCuts() const
OsiRowCut ** rowCut_
CglHashLink * hash_
Hash table.
void eraseRowCut(int sequence)
CglUniqueRowCuts(const CglUniqueRowCuts &rhs)