//===========================================================================// // This file is part of the DIP Solver Framework. // // // // DIP is distributed under the Eclipse Public License as part of the // // COIN-OR repository (http://www.coin-or.org). // // // // Author: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) // // // // Conceptual Design: Matthew Galati, SAS Institute Inc. // // Ted Ralphs, Lehigh University // // // // Copyright (C) 2002-2009, Lehigh University, Matthew Galati, and Ted Ralphs// // All Rights Reserved. // //===========================================================================// #ifndef DECOMP_CONSTRAINTSET_INCLUDED #define DECOMP_CONSTRAINTSET_INCLUDED // --------------------------------------------------------------------- // #include "Decomp.h" #include "UtilMacros.h" // --------------------------------------------------------------------- // enum ColMarkerType { DecompColNonActive = 0, DecompColActive = 1, DecompColMasterOnly= 2 }; // --------------------------------------------------------------------- // class DecompConstraintSet{ public: CoinPackedMatrix * M; int nBaseRowsOrig; int nBaseRows; vector rowHash; vector rowSense; vector rowRhs; vector rowLB; vector rowUB; vector colLB; vector colUB; vector integerVars; vector integerMark; //'C' = continuous, 'I' = integral vector colNames; vector rowNames; vector activeColumns; //if block, define the active columns set activeColumnsS;//if block, define the active columns vector masterOnlyCols; bool prepHasRun; //for storage of several rows of row-majored sparse matrix // to be used with appendRows vector m_rowBeg; vector m_rowInd; vector m_rowVal; //for special case of master-only vars bool m_masterOnly; int m_masterOnlyIndex; double m_masterOnlyLB; double m_masterOnlyUB; bool m_masterOnlyIsInt; //for special case of sparse representation bool m_isSparse; int m_numColsOrig; map m_origToSparse; map m_sparseToOrig; public: inline void setSparse(const int numColsOrig){ m_numColsOrig = numColsOrig; m_isSparse = true; } inline const bool isSparse() const { return m_origToSparse.size() ? true : false; }; inline const CoinPackedMatrix * getMatrix() const { return M; }; inline const int getNumRows() const { return M ? M->getNumRows() : static_cast(rowLB.size()); } inline const int getNumCols() const { return M ? M->getNumCols() : static_cast(colLB.size()); } inline const int getNumColsOrig() const { return isSparse() ? m_numColsOrig : getNumCols(); }; inline const int getNumInts() const { return static_cast(integerVars.size());} inline const vector & getActiveColumns() const { return activeColumns;} inline const vector & getRowNames() const {return rowNames;} inline const vector & getColNames() const {return colNames;} inline vector & getRowNamesMutable() {return rowNames;} inline vector & getColNamesMutable() {return colNames;} inline const char * getIntegerMark() { return &integerMark[0];} inline const int * getIntegerVars() { return &integerVars[0];} inline const double * getColLB() const { return &colLB[0]; }; inline const double * getColUB() const { return &colUB[0]; }; inline const double * getRowLB() const { return &rowLB[0]; }; inline const double * getRowUB() const { return &rowUB[0]; }; inline const bool hasPrepRun() const { return prepHasRun; }; inline const bool isMasterOnly() const { return m_masterOnly; }; inline const map & getMapOrigToSparse() const { return m_origToSparse;}; inline const map & getMapSparseToOrig() const { return m_sparseToOrig;}; public: void prepareModel(); void createRowHash(); void checkSenseAndBound(); void sensesToBounds(); void boundsToSenses(); void fixNonActiveColumns(); inline void appendRow(CoinPackedVector & row, double loBound, double upBound){ M->appendRow(row); rowLB.push_back(loBound); rowUB.push_back(upBound); } inline void appendRow(CoinPackedVector & row, double loBound, double upBound, string & rowName){ appendRow(row, loBound, upBound); rowNames.push_back(rowName); } inline void pushCol(const double loBound, const double upBound, const bool isInteger = false, const int origIndex = -1){ int index = static_cast(colLB.size()); colLB.push_back(loBound); colUB.push_back(upBound); if(isInteger) integerVars.push_back(index); if(origIndex >= 0){ m_origToSparse.insert(make_pair(origIndex, index)); m_sparseToOrig.insert(make_pair(index, origIndex)); } } inline void reserve(const int nCols, const int nRows){ M->reserve(nRows, nCols); rowLB.reserve(nRows); rowUB.reserve(nRows); colLB.reserve(nCols); colUB.reserve(nCols); } public: DecompConstraintSet() : M (0), nBaseRowsOrig (0), nBaseRows (0), prepHasRun (false), m_masterOnly (false), m_masterOnlyIndex(0), m_masterOnlyLB (0.0), m_masterOnlyUB (0.0), m_masterOnlyIsInt(false), m_isSparse (false), m_numColsOrig (0) {}; ~DecompConstraintSet() { UTIL_DELPTR(M); }; }; #endif