Loading...
Searching...
No Matches
CglPreProcess.hpp
Go to the documentation of this file.
// Copyright (C) 2005, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
#ifndef CglPreProcess_H
#define CglPreProcess_H
#include <string>
#include <vector>
#include "CoinMessageHandler.hpp"
#include "OsiSolverInterface.hpp"
#include "CglStored.hpp"
#include "OsiPresolve.hpp"
#include "CglCutGenerator.hpp"
//#############################################################################
class CglPreProcess {
public:
OsiSolverInterface *preProcess(OsiSolverInterface &model,
bool makeEquality = false, int numberPasses = 5);
OsiSolverInterface *preProcessNonDefault(OsiSolverInterface &model,
int makeEquality = 0, int numberPasses = 5,
int tuning = 0);
void postProcess(OsiSolverInterface &model, int deleteStuff = 2);
int tightenPrimalBounds(OsiSolverInterface &model, double factor = 0.0);
OsiSolverInterface *someFixed(OsiSolverInterface &model,
double fractionToKeep = 0.25,
bool fixContinuousAsWell = false,
char *keep = NULL) const;
OsiSolverInterface *cliqueIt(OsiSolverInterface &model,
double cliquesNeeded = 0.0) const;
int reducedCostFix(OsiSolverInterface &model);
//---------------------------------------------------------------------------
void setCutoff(double value);
double getCutoff() const;
inline OsiSolverInterface *originalModel() const
{
return originalModel_;
}
inline void setOriginalModel(OsiSolverInterface *originalModel)
{
originalModel_ = originalModel;
}
inline OsiSolverInterface *startModel() const
{
return startModel_;
}
inline int numberSolvers() const
{
return numberSolvers_;
}
inline OsiSolverInterface *modelAtPass(int iPass) const
{
if (iPass >= 0 && iPass < numberSolvers_)
return model_[iPass];
else
return NULL;
}
inline OsiSolverInterface *modifiedModel(int iPass) const
{
if (iPass >= 0 && iPass < numberSolvers_)
return modifiedModel_[iPass];
else
return NULL;
}
inline OsiPresolve *presolve(int iPass) const
{
if (iPass >= 0 && iPass < numberSolvers_)
return presolve_[iPass];
else
return NULL;
}
inline void setPresolve(int iPass, OsiPresolve *presolve)
{
if (iPass >= 0 && iPass < numberSolvers_)
presolve_[iPass] = presolve;
}
const int *originalColumns();
const int *originalRows();
inline int numberSOS() const
{
return numberSOS_;
}
inline const int *typeSOS() const
{
return typeSOS_;
}
inline const int *startSOS() const
{
return startSOS_;
}
inline const int *whichSOS() const
{
return whichSOS_;
}
inline const double *weightSOS() const
{
return weightSOS_;
}
void passInProhibited(const char *prohibited, int numberColumns);
inline const char *prohibited()
{
return prohibited_;
}
inline int numberIterationsPre() const
{
return numberIterationsPre_;
}
inline int numberIterationsPost() const
{
return numberIterationsPost_;
}
void passInRowTypes(const char *rowTypes, int numberRows);
inline const char *rowTypes()
{
return rowType_;
}
inline const CglStored &cuts() const
{
return cuts_;
}
inline const CglStored *cutsPointer() const
{
return &cuts_;
}
void update(const OsiPresolve *pinfo, const OsiSolverInterface *solver);
inline int options() const
{
return options_;
}
inline void setOptions(int value)
{
options_ = value;
}
inline int numberCutGenerators() const
{
return numberCutGenerators_;
}
inline CglCutGenerator **cutGenerators() const
{
return generator_;
}
inline CglCutGenerator *cutGenerator(int i) const
{
return generator_[i];
}
void addCutGenerator(CglCutGenerator *generator);
void setApplicationData(void *appData);
void *getApplicationData() const;
//---------------------------------------------------------------------------
void passInMessageHandler(CoinMessageHandler *handler);
void newLanguage(CoinMessages::Language language);
inline void setLanguage(CoinMessages::Language language)
{
newLanguage(language);
}
inline CoinMessageHandler *messageHandler() const
{
return handler_;
}
inline CoinMessages messages()
{
return messages_;
}
inline CoinMessages *messagesPointer()
{
return &messages_;
}
//---------------------------------------------------------------------------
CglPreProcess();
CglPreProcess(const CglPreProcess &rhs);
CglPreProcess &operator=(const CglPreProcess &rhs);
~CglPreProcess();
void gutsOfDestructor();
void setTimeLimit(const double timeLimit, const bool useElapsedTime);
void setKeepColumnNames(const bool keep);
private:
OsiSolverInterface *modified(OsiSolverInterface *model,
bool constraints,
int &numberChanges,
int iBigPass,
int numberPasses);
void createOriginalIndices();
void makeInteger();
//---------------------------------------------------------------------------
private:
OsiSolverInterface *originalModel_;
OsiSolverInterface *startModel_;
int numberSolvers_;
OsiSolverInterface **model_;
OsiSolverInterface **modifiedModel_;
OsiPresolve **presolve_;
CoinMessageHandler *handler_;
bool defaultHandler_;
CoinMessages messages_;
void *appData_;
int *originalColumn_;
int *originalRow_;
int numberCutGenerators_;
CglCutGenerator **generator_;
int numberSOS_;
int *typeSOS_;
int *startSOS_;
int *whichSOS_;
double *weightSOS_;
int numberProhibited_;
int numberIterationsPre_;
int numberIterationsPost_;
char *prohibited_;
int numberRowType_;
int options_;
char *rowType_;
CglStored cuts_;
bool useElapsedTime_;
double timeLimit_;
bool keepColumnNames_;
double getCurrentCPUTime() const;
};
class CglBK {
public:
void bronKerbosch();
OsiSolverInterface *newSolver(const OsiSolverInterface &model);
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
CglBK();
CglBK(const OsiSolverInterface &model, const char *rowType,
int numberElements);
CglBK(const CglBK &rhs);
CglBK &operator=(const CglBK &rhs);
~CglBK();
//---------------------------------------------------------------------------
private:
int *candidates_;
char *mark_;
CoinBigIndex *start_;
int *otherColumn_;
int *originalRow_;
int *dominated_;
CoinPackedMatrix *cliqueMatrix_;
const char *rowType_;
int numberColumns_;
int numberRows_;
int numberPossible_;
int numberCandidates_;
int firstNot_;
int numberIn_;
int left_;
int lastColumn_;
};
// for hashing
typedef struct {
int index, next;
} CglHashLink;
class OsiRowCut;
class CglUniqueRowCuts {
public:
CglUniqueRowCuts(int initialMaxSize = 0, int hashMultiplier = 4);
~CglUniqueRowCuts();
CglUniqueRowCuts(const CglUniqueRowCuts &rhs);
CglUniqueRowCuts &operator=(const CglUniqueRowCuts &rhs);
inline OsiRowCut *cut(int sequence) const
{
return rowCut_[sequence];
}
inline int numberCuts() const
{
return numberCuts_;
}
inline int sizeRowCuts() const
{
return numberCuts_;
}
inline OsiRowCut *rowCutPtr(int sequence)
{
return rowCut_[sequence];
}
void eraseRowCut(int sequence);
// insert cut
inline void insert(const OsiRowCut &cut)
{
insertIfNotDuplicate(cut);
}
// Return 0 if added, 1 if not
int insertIfNotDuplicate(const OsiRowCut &cut);
// Add in cuts as normal cuts (and delete)
void addCuts(OsiCuts &cs);
private:
OsiRowCut **rowCut_;
CglHashLink *hash_;
int size_;
int hashMultiplier_;
int numberCuts_;
int lastHash_;
};
#endif
/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
*/
CglCutGenerator.hpp
CglStored.hpp
CglBK::CglBK
CglBK(const OsiSolverInterface &model, const char *rowType, int numberElements)
Useful constructor.
CglBK::mark_
char * mark_
Array to mark stuff.
Definition CglPreProcess.hpp:517
CglBK::firstNot_
int firstNot_
First not (stored backwards from numberPossible_).
Definition CglPreProcess.hpp:539
CglBK::CglBK
CglBK(const CglBK &rhs)
Copy constructor .
CglBK::numberRows_
int numberRows_
Number of original rows.
Definition CglPreProcess.hpp:533
CglBK::otherColumn_
int * otherColumn_
Other column/node.
Definition CglPreProcess.hpp:521
CglBK::operator=
CglBK & operator=(const CglBK &rhs)
Assignment operator.
CglBK::numberCandidates_
int numberCandidates_
Current number of candidates.
Definition CglPreProcess.hpp:537
CglBK::numberColumns_
int numberColumns_
Number of original columns.
Definition CglPreProcess.hpp:531
CglBK::rowType_
const char * rowType_
points to row types
Definition CglPreProcess.hpp:529
CglBK::~CglBK
~CglBK()
Destructor.
CglBK::left_
int left_
For acceleration.
Definition CglPreProcess.hpp:543
CglBK::start_
CoinBigIndex * start_
Starts for graph (numberPossible+1).
Definition CglPreProcess.hpp:519
CglBK::cliqueMatrix_
CoinPackedMatrix * cliqueMatrix_
Clique entries.
Definition CglPreProcess.hpp:527
CglBK::numberIn_
int numberIn_
Current number in clique.
Definition CglPreProcess.hpp:541
CglBK::originalRow_
int * originalRow_
Original row (in parallel with otherColumn_).
Definition CglPreProcess.hpp:523
CglBK::candidates_
int * candidates_
Current candidates (created at each level).
Definition CglPreProcess.hpp:515
CglBK::lastColumn_
int lastColumn_
Definition CglPreProcess.hpp:544
CglBK::CglBK
CglBK()
Default constructor.
CglBK::dominated_
int * dominated_
How many times each original row dominated.
Definition CglPreProcess.hpp:525
CglBK::numberPossible_
int numberPossible_
Number possible.
Definition CglPreProcess.hpp:535
CglBK::newSolver
OsiSolverInterface * newSolver(const OsiSolverInterface &model)
Creates strengthened smaller model.
CglBK::bronKerbosch
void bronKerbosch()
For recursive Bron-Kerbosch.
CglCutGenerator
Cut Generator Base Class.
Definition CglCutGenerator.hpp:23
CglPreProcess::passInProhibited
void passInProhibited(const char *prohibited, int numberColumns)
Pass in prohibited columns.
CglPreProcess::timeLimit_
double timeLimit_
time limit (default COIN_DBL_MAX)
Definition CglPreProcess.hpp:451
CglPreProcess::originalRows
const int * originalRows()
Return a pointer to the original rows MUST be called before postProcess otherwise you just get 0,...
CglPreProcess::messagesPointer
CoinMessages * messagesPointer()
Return pointer to messages.
Definition CglPreProcess.hpp:317
CglPreProcess::setCutoff
void setCutoff(double value)
Set cutoff bound on the objective function.
CglPreProcess::setApplicationData
void setApplicationData(void *appData)
Set application data.
CglPreProcess::preProcessNonDefault
OsiSolverInterface * preProcessNonDefault(OsiSolverInterface &model, int makeEquality=0, int numberPasses=5, int tuning=0)
preProcess problem - returning new problem.
CglPreProcess::CglPreProcess
CglPreProcess(const CglPreProcess &rhs)
Copy constructor .
CglPreProcess::~CglPreProcess
~CglPreProcess()
Destructor.
CglPreProcess::startModel
OsiSolverInterface * startModel() const
Solver after making clique equalities (may == original).
Definition CglPreProcess.hpp:129
CglPreProcess::numberProhibited_
int numberProhibited_
Number of columns in original prohibition set.
Definition CglPreProcess.hpp:419
CglPreProcess::passInRowTypes
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...
CglPreProcess::passInMessageHandler
void passInMessageHandler(CoinMessageHandler *handler)
Pass in Message handler (not deleted at end).
CglPreProcess::numberRowType_
int numberRowType_
Number of rows in original row types.
Definition CglPreProcess.hpp:427
CglPreProcess::prohibited
const char * prohibited()
Updated prohibited columns.
Definition CglPreProcess.hpp:202
CglPreProcess::startSOS_
int * startSOS_
Start of each SOS.
Definition CglPreProcess.hpp:413
CglPreProcess::whichSOS_
int * whichSOS_
Columns in SOS.
Definition CglPreProcess.hpp:415
CglPreProcess::rowType_
char * rowType_
Row types (may be NULL) Carried around and corresponds to existing rows -1 added by preprocess e....
Definition CglPreProcess.hpp:443
CglPreProcess::cutGenerator
CglCutGenerator * cutGenerator(int i) const
Get the specified cut generator.
Definition CglPreProcess.hpp:270
CglPreProcess::prohibited_
char * prohibited_
Columns which should not be presolved e.g. SOS.
Definition CglPreProcess.hpp:425
CglPreProcess::CglPreProcess
CglPreProcess()
Constructor.
CglPreProcess::modelAtPass
OsiSolverInterface * modelAtPass(int iPass) const
Copies of solver at various stages after presolve.
Definition CglPreProcess.hpp:139
CglPreProcess::weightSOS
const double * weightSOS() const
Weights for each SOS column.
Definition CglPreProcess.hpp:195
CglPreProcess::modified
OsiSolverInterface * modified(OsiSolverInterface *model, bool constraints, int &numberChanges, int iBigPass, int numberPasses)
Return model with useful modifications.
CglPreProcess::numberCutGenerators
int numberCutGenerators() const
Get the number of cut generators.
Definition CglPreProcess.hpp:260
CglPreProcess::handler_
CoinMessageHandler * handler_
Message handler.
Definition CglPreProcess.hpp:386
CglPreProcess::useElapsedTime_
bool useElapsedTime_
use elapsed (wallclock time) or cpu time
Definition CglPreProcess.hpp:448
CglPreProcess::makeInteger
void makeInteger()
Make continuous variables integer.
CglPreProcess::presolve_
OsiPresolve ** presolve_
Matching presolve information.
Definition CglPreProcess.hpp:383
CglPreProcess::someFixed
OsiSolverInterface * someFixed(OsiSolverInterface &model, double fractionToKeep=0.25, bool fixContinuousAsWell=false, char *keep=NULL) const
Fix some of problem - returning new problem.
CglPreProcess::numberIterationsPre
int numberIterationsPre() const
Number of iterations PreProcessing.
Definition CglPreProcess.hpp:207
CglPreProcess::generator_
CglCutGenerator ** generator_
Cut generators.
Definition CglPreProcess.hpp:407
CglPreProcess::cuts_
CglStored cuts_
Cuts from dropped rows.
Definition CglPreProcess.hpp:445
CglPreProcess::preProcess
OsiSolverInterface * preProcess(OsiSolverInterface &model, bool makeEquality=false, int numberPasses=5)
preProcess problem - returning new problem.
CglPreProcess::messageHandler
CoinMessageHandler * messageHandler() const
Return handler.
Definition CglPreProcess.hpp:307
CglPreProcess::numberSOS_
int numberSOS_
Number of SOS if found.
Definition CglPreProcess.hpp:409
CglPreProcess::setKeepColumnNames
void setKeepColumnNames(const bool keep)
Keeps original column names.
CglPreProcess::typeSOS_
int * typeSOS_
Type of each SOS.
Definition CglPreProcess.hpp:411
CglPreProcess::model_
OsiSolverInterface ** model_
Copies of solver at various stages after presolve.
Definition CglPreProcess.hpp:379
CglPreProcess::modifiedModel_
OsiSolverInterface ** modifiedModel_
Copies of solver at various stages after presolve after modifications.
Definition CglPreProcess.hpp:381
CglPreProcess::cutsPointer
const CglStored * cutsPointer() const
Return pointer to cuts from dropped rows.
Definition CglPreProcess.hpp:239
CglPreProcess::cliqueIt
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...
CglPreProcess::originalRow_
int * originalRow_
Original row numbers.
Definition CglPreProcess.hpp:403
CglPreProcess::numberIterationsPre_
int numberIterationsPre_
Number of iterations done in PreProcessing.
Definition CglPreProcess.hpp:421
CglPreProcess::originalColumns
const int * originalColumns()
Return a pointer to the original columns (with possible clique slacks) MUST be called before postProc...
CglPreProcess::operator=
CglPreProcess & operator=(const CglPreProcess &rhs)
Assignment operator.
CglPreProcess::messages
CoinMessages messages()
Return messages.
Definition CglPreProcess.hpp:312
CglPreProcess::reducedCostFix
int reducedCostFix(OsiSolverInterface &model)
If we have a cutoff - fix variables.
CglPreProcess::getApplicationData
void * getApplicationData() const
Get application data.
CglPreProcess::setOptions
void setOptions(int value)
Set options.
Definition CglPreProcess.hpp:251
CglPreProcess::numberSolvers
int numberSolvers() const
Number of solvers.
Definition CglPreProcess.hpp:134
CglPreProcess::numberSOS
int numberSOS() const
Number of SOS if found.
Definition CglPreProcess.hpp:175
CglPreProcess::startModel_
OsiSolverInterface * startModel_
Solver after making clique equalities (may == original).
Definition CglPreProcess.hpp:375
CglPreProcess::keepColumnNames_
bool keepColumnNames_
keep column names
Definition CglPreProcess.hpp:454
CglPreProcess::weightSOS_
double * weightSOS_
Weights for each SOS column.
Definition CglPreProcess.hpp:417
CglPreProcess::postProcess
void postProcess(OsiSolverInterface &model, int deleteStuff=2)
Creates solution in original model deleteStuff 0 - don't, 1 do (but not if infeasible),...
CglPreProcess::modifiedModel
OsiSolverInterface * modifiedModel(int iPass) const
Copies of solver at various stages after presolve after modifications.
Definition CglPreProcess.hpp:147
CglPreProcess::options
int options() const
Get options.
Definition CglPreProcess.hpp:246
CglPreProcess::getCurrentCPUTime
double getCurrentCPUTime() const
current elapsed or cpu time
CglPreProcess::numberSolvers_
int numberSolvers_
Number of solvers at various stages.
Definition CglPreProcess.hpp:377
CglPreProcess::setOriginalModel
void setOriginalModel(OsiSolverInterface *originalModel)
Set original model (probably acopy).
Definition CglPreProcess.hpp:124
CglPreProcess::cuts
const CglStored & cuts() const
Return cuts from dropped rows.
Definition CglPreProcess.hpp:234
CglPreProcess::rowTypes
const char * rowTypes()
Updated row types - may be NULL Carried around and corresponds to existing rows -1 added by preproces...
Definition CglPreProcess.hpp:229
CglPreProcess::numberCutGenerators_
int numberCutGenerators_
Number of cut generators.
Definition CglPreProcess.hpp:405
CglPreProcess::setPresolve
void setPresolve(int iPass, OsiPresolve *presolve)
Set matching presolve information.
Definition CglPreProcess.hpp:163
CglPreProcess::numberIterationsPost
int numberIterationsPost() const
Number of iterations PostProcessing.
Definition CglPreProcess.hpp:212
CglPreProcess::setLanguage
void setLanguage(CoinMessages::Language language)
Definition CglPreProcess.hpp:302
CglPreProcess::typeSOS
const int * typeSOS() const
Type of each SOS.
Definition CglPreProcess.hpp:180
CglPreProcess::presolve
OsiPresolve * presolve(int iPass) const
Matching presolve information.
Definition CglPreProcess.hpp:155
CglPreProcess::originalColumn_
int * originalColumn_
Original column numbers.
Definition CglPreProcess.hpp:401
CglPreProcess::gutsOfDestructor
void gutsOfDestructor()
Clears out as much as possible.
CglPreProcess::originalModel
OsiSolverInterface * originalModel() const
The original solver associated with this model.
Definition CglPreProcess.hpp:119
CglPreProcess::startSOS
const int * startSOS() const
Start of each SOS.
Definition CglPreProcess.hpp:185
CglPreProcess::numberIterationsPost_
int numberIterationsPost_
Number of iterations done in PostProcessing.
Definition CglPreProcess.hpp:423
CglPreProcess::update
void update(const OsiPresolve *pinfo, const OsiSolverInterface *solver)
Update prohibited and rowType.
CglPreProcess::messages_
CoinMessages messages_
Cgl messages.
Definition CglPreProcess.hpp:396
CglPreProcess::defaultHandler_
bool defaultHandler_
Flag to say if handler_ is the default handler.
Definition CglPreProcess.hpp:393
CglPreProcess::newLanguage
void newLanguage(CoinMessages::Language language)
Set language.
CglPreProcess::options_
int options_
Options 1 - original model had integer bounds before tightening 2 - don't do probing 4 - don't do dup...
Definition CglPreProcess.hpp:436
CglPreProcess::getCutoff
double getCutoff() const
Get the cutoff bound on the objective function - always as minimize.
CglPreProcess::appData_
void * appData_
Pointer to user-defined data structure.
Definition CglPreProcess.hpp:399
CglPreProcess::addCutGenerator
void addCutGenerator(CglCutGenerator *generator)
Add one generator - up to user to delete generators.
CglPreProcess::tightenPrimalBounds
int tightenPrimalBounds(OsiSolverInterface &model, double factor=0.0)
Tightens primal bounds to make dual and branch and cutfaster.
CglPreProcess::setTimeLimit
void setTimeLimit(const double timeLimit, const bool useElapsedTime)
Set time limit.
CglPreProcess::cutGenerators
CglCutGenerator ** cutGenerators() const
Get the list of cut generators.
Definition CglPreProcess.hpp:265
CglPreProcess::createOriginalIndices
void createOriginalIndices()
create original columns and rows
CglPreProcess::originalModel_
OsiSolverInterface * originalModel_
The original solver associated with this model.
Definition CglPreProcess.hpp:373
CglPreProcess::whichSOS
const int * whichSOS() const
Columns in SOS.
Definition CglPreProcess.hpp:190
CglStored
Stored Cut Generator Class.
Definition CglStored.hpp:16
CglUniqueRowCuts::CglUniqueRowCuts
CglUniqueRowCuts(int initialMaxSize=0, int hashMultiplier=4)
CglUniqueRowCuts::cut
OsiRowCut * cut(int sequence) const
Definition CglPreProcess.hpp:561
CglUniqueRowCuts::addCuts
void addCuts(OsiCuts &cs)
CglUniqueRowCuts::insert
void insert(const OsiRowCut &cut)
Definition CglPreProcess.hpp:579
CglUniqueRowCuts::insertIfNotDuplicate
int insertIfNotDuplicate(const OsiRowCut &cut)
CglUniqueRowCuts::operator=
CglUniqueRowCuts & operator=(const CglUniqueRowCuts &rhs)
CglUniqueRowCuts::rowCutPtr
OsiRowCut * rowCutPtr(int sequence)
Definition CglPreProcess.hpp:573
CglUniqueRowCuts::sizeRowCuts
int sizeRowCuts() const
Definition CglPreProcess.hpp:569
CglUniqueRowCuts::numberCuts
int numberCuts() const
Definition CglPreProcess.hpp:565
CglUniqueRowCuts::rowCut_
OsiRowCut ** rowCut_
Definition CglPreProcess.hpp:589
CglUniqueRowCuts::hashMultiplier_
int hashMultiplier_
Definition CglPreProcess.hpp:593
CglUniqueRowCuts::hash_
CglHashLink * hash_
Hash table.
Definition CglPreProcess.hpp:591
CglUniqueRowCuts::numberCuts_
int numberCuts_
Definition CglPreProcess.hpp:594
CglUniqueRowCuts::eraseRowCut
void eraseRowCut(int sequence)
CglUniqueRowCuts::~CglUniqueRowCuts
~CglUniqueRowCuts()
CglUniqueRowCuts::size_
int size_
Definition CglPreProcess.hpp:592
CglUniqueRowCuts::lastHash_
int lastHash_
Definition CglPreProcess.hpp:595
CglUniqueRowCuts::CglUniqueRowCuts
CglUniqueRowCuts(const CglUniqueRowCuts &rhs)
CglHashLink
Only store unique row cuts.
Definition CglPreProcess.hpp:551
CglHashLink::next
int next
Definition CglPreProcess.hpp:552
CglHashLink::index
int index
Definition CglPreProcess.hpp:552