DecompConstraintSet.h

Go to the documentation of this file.
00001 //===========================================================================//
00002 // This file is part of the DIP Solver Framework.                            //
00003 //                                                                           //
00004 // DIP is distributed under the Eclipse Public License as part of the        //
00005 // COIN-OR repository (http://www.coin-or.org).                              //
00006 //                                                                           //
00007 // Author: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com)       //
00008 //                                                                           //
00009 // Conceptual Design: Matthew Galati, SAS Institute Inc.                     //
00010 //                    Ted Ralphs, Lehigh University                          //
00011 //                                                                           //
00012 // Copyright (C) 2002-2013, Lehigh University, Matthew Galati, and Ted Ralphs//
00013 // All Rights Reserved.                                                      //
00014 //===========================================================================//
00015 
00016 #ifndef DECOMP_CONSTRAINTSET_INCLUDED
00017 #define DECOMP_CONSTRAINTSET_INCLUDED
00018 
00019 // --------------------------------------------------------------------- //
00020 #include "Decomp.h"
00021 #include "UtilMacros.h"
00022 
00023 // --------------------------------------------------------------------- //
00024 enum ColMarkerType {
00025    DecompColNonActive = 0,
00026    DecompColActive    = 1,
00027    DecompColMasterOnly = 2
00028 };
00029 
00030 // --------------------------------------------------------------------- //
00031 class DecompConstraintSet {
00032 public:
00033    CoinPackedMatrix*    M;
00034    int                  nBaseRowsOrig;
00035    int                  nBaseRows;
00036    std::vector<std::string>       rowHash;
00037    std::vector<char>         rowSense;
00038    std::vector<double>       rowRhs;
00039    std::vector<double>       rowLB;
00040    std::vector<double>       rowUB;
00041    std::vector<double>       colLB;
00042    std::vector<double>       colUB;
00043    std::vector<int>          integerVars;
00044    std::vector<char>         integerMark; //'C' = continuous, 'I' = integral
00045    std::vector<std::string>       colNames;
00046    std::vector<std::string>       rowNames;
00047    std::vector<int>          activeColumns; //if block, define the active columns
00048    std::set<int>             activeColumnsS;//if block, define the active columns
00049    std::vector<int>          masterOnlyCols;
00050    bool                 prepHasRun;
00051 
00052    //for storage of several rows of row-majored sparse matrix
00053    //  to be used with appendRows
00054    std::vector<CoinBigIndex> m_rowBeg;
00055    std::vector<int         > m_rowInd;
00056    std::vector<double      > m_rowVal;
00057 
00058    //for special case of sparse representation
00059    bool          m_isSparse;
00060    int           m_numColsOrig;
00061    std::map<int, int> m_origToSparse;
00062    std::map<int, int> m_sparseToOrig;
00063 
00064 public:
00065    inline void setSparse(const int numColsOrig) {
00066       m_numColsOrig = numColsOrig;
00067       m_isSparse    = true;
00068    }
00069    inline const bool isSparse() const {
00070       return m_origToSparse.size() ? true : false;
00071    };
00072    inline const CoinPackedMatrix* getMatrix() const {
00073       return M;
00074    };
00075    inline const int getNumRows() const {
00076       return M ? M->getNumRows() : static_cast<int>(rowLB.size());
00077    }
00078    inline const int getNumCols() const {
00079       return M ? M->getNumCols() : static_cast<int>(colLB.size());
00080    }
00081    inline const int getNumColsOrig() const {
00082       return isSparse() ? m_numColsOrig : getNumCols();
00083    };
00084    inline const int getNumInts() const {
00085       return static_cast<int>(integerVars.size());
00086    }
00087    inline const std::vector<int>&     getActiveColumns() const {
00088       return activeColumns;
00089    }
00090    inline const std::vector<std::string>& getRowNames() const {
00091       return rowNames;
00092    }
00093    inline const std::vector<std::string>& getColNames() const {
00094       return colNames;
00095    }
00096    inline std::vector<std::string>& getRowNamesMutable() {
00097       return rowNames;
00098    }
00099    inline std::vector<std::string>& getColNamesMutable() {
00100       return colNames;
00101    }
00102    inline const char*    getIntegerMark() {
00103       return &integerMark[0];
00104    }
00105    inline const int*     getIntegerVars() {
00106       return &integerVars[0];
00107    }
00108    inline const double* getColLB() const {
00109       return &colLB[0];
00110    };
00111    inline const double* getColUB() const {
00112       return &colUB[0];
00113    };
00114    inline const double* getRowLB() const {
00115       return &rowLB[0];
00116    };
00117    inline const double* getRowUB() const {
00118       return &rowUB[0];
00119    };
00120    inline const bool     hasPrepRun() const {
00121       return prepHasRun;
00122    };
00123    inline const std::map<int, int>& getMapOrigToSparse() const {
00124       return m_origToSparse;
00125    };
00126    inline const std::map<int, int>& getMapSparseToOrig() const {
00127       return m_sparseToOrig;
00128    };
00129    inline const std::vector<int>& getMasterOnlyCols() const {
00130       return masterOnlyCols;
00131    }
00132 
00133 
00134 public:
00135    void prepareModel(bool modelIsCore = false);
00136    void createRowHash();
00137    void checkSenseAndBound();
00138    void sensesToBounds();
00139    void boundsToSenses();
00140    void fixNonActiveColumns();
00141    CoinPackedMatrix* sparseToOrigMatrix();
00142 
00143    inline void appendRow(CoinPackedVector& row,
00144                          double             loBound,
00145                          double             upBound) {
00146       M->appendRow(row);
00147       rowLB.push_back(loBound);
00148       rowUB.push_back(upBound);
00149    }
00150    //inline void appendRow(CoinPackedVector & row,
00151    //        double             loBound,
00152    //        double             upBound,
00153    //        std::string      & rowName){
00154    //   appendRow(row, loBound, upBound);
00155    // rowNames.push_back(rowName);
00156    //}
00157    inline void appendRow(CoinPackedVector& row,
00158                          double             loBound,
00159                          double             upBound,
00160                          std::string        rowName) {
00161       appendRow(row, loBound, upBound);
00162       rowNames.push_back(rowName);
00163    }
00164 
00165    inline void pushCol(const double loBound,
00166                        const double upBound,
00167                        const bool   isInteger   = false,
00168                        const int    origIndex   = -1) {
00169       int index = static_cast<int>(colLB.size());
00170       colLB.push_back(loBound);
00171       colUB.push_back(upBound);
00172 
00173       if (isInteger) {
00174          if (std::find(integerVars.begin(), integerVars.end(), index)
00175                == integerVars.end()) {
00176             integerVars.push_back(index);
00177          }
00178       }
00179 
00180       assert(!(origIndex == -1 && m_isSparse));
00181 
00182       if (origIndex >= 0) {
00183          m_origToSparse.insert(std::make_pair(origIndex, index));
00184          m_sparseToOrig.insert(std::make_pair(index, origIndex));
00185       }
00186    }
00187 
00188    inline void reserve(const int nCols,
00189                        const int nRows) {
00190       M->reserve(nRows, nCols);
00191       rowLB.reserve(nRows);
00192       rowUB.reserve(nRows);
00193       colLB.reserve(nCols);
00194       colUB.reserve(nCols);
00195    }
00196 public:
00197    DecompConstraintSet() :
00198       M                (0),
00199       nBaseRowsOrig    (0),
00200       nBaseRows        (0),
00201       prepHasRun       (false),
00202       m_isSparse       (false),
00203       m_numColsOrig    (0) {
00204    };
00205 
00206    ~DecompConstraintSet() {
00207       UTIL_DELPTR(M);
00208    };
00209 };
00210 
00211 #endif

Generated on 12 Feb 2015 for Dip-All by  doxygen 1.6.1