DecompVar.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, Ted Ralphs    //
00013 // All Rights Reserved.                                                      //
00014 //===========================================================================//
00015 
00016 //this is a lambda_s variable
00017 //assumption throughout is lambda is {0,1}
00018 
00019 #ifndef DECOMP_VAR_INCLUDED
00020 #define DECOMP_VAR_INCLUDED
00021 
00022 #include "Decomp.h"
00023 #include "UtilHash.h"
00024 #include "UtilMacrosDecomp.h"
00025 
00026 class DecompApp;
00027 class DecompAlgoModel;
00028 
00029 // --------------------------------------------------------------------- //
00030 class DecompVar {
00031 public:
00032    //THINK: or user overriden way to store it (like a tree)
00033    //and a function which says expandVarToCol - just as in cuts
00034    CoinPackedVector m_s;//this is the var in terms of x-space
00035 
00036 private:
00037    //TODO: lb, ub, "type"?
00038    DecompVarType    m_varType;
00039    double           m_origCost;
00040    double           m_redCost; //(c - uA'')s - alpha
00041    int              m_effCnt;  //effectiveness counter
00042    std::string           m_strHash;
00043    int              m_blockId;
00044    int              m_colMasterIndex;
00045    double           m_norm;
00046 
00047 public:
00048    inline DecompVarType getVarType()   const {
00049       return m_varType;
00050    }
00051    inline double getOriginalCost()   const {
00052       return m_origCost;
00053    }
00054    inline double getReducedCost()    const {
00055       return m_redCost;
00056    }
00057    inline int    getEffectiveness()  const {
00058       return m_effCnt;
00059    }
00060    inline double getLowerBound()     const {
00061       return 0.0;         //TODO
00062    }
00063    inline double getUpperBound()     const {
00064       return DecompInf;   //TODO
00065    }
00066    inline std::string getStrHash()        const {
00067       return m_strHash;
00068    }
00069    inline int    getBlockId()        const {
00070       return m_blockId;
00071    }
00072    inline int    getColMasterIndex() const {
00073       return m_colMasterIndex;
00074    }
00075    inline double getNorm()           const {
00076       return m_norm;
00077    }
00078 
00079    inline void   setVarType(const DecompVarType varType)  {
00080       m_varType = varType;
00081    }
00082    inline void   setColMasterIndex(const int colIndex)  {
00083       m_colMasterIndex = colIndex;
00084    }
00085    inline void   setBlockId (const int blockId)  {
00086       m_blockId = blockId;
00087    }
00088    inline void   setReducedCost (const double redCost)  {
00089       m_redCost = redCost;
00090    }
00091    inline void   setOriginalCost(const double origCost) {
00092       m_origCost = origCost;
00093    }
00094 
00095    inline void resetEffectiveness() {
00096       m_effCnt = 0;
00097    }
00098 
00101    inline void increaseEffCnt() {
00102       m_effCnt = m_effCnt <= 0 ? 1 : m_effCnt + 1;
00103    }
00104 
00107    inline void decreaseEffCnt() {
00108       m_effCnt = m_effCnt >= 0 ? -1 : m_effCnt - 1;
00109    }
00110 
00111    inline double calcNorm() {
00112       return m_norm = m_s.twoNorm();
00113    }
00114 
00115    inline void sortVar() {
00116       m_s.sortIncrIndex();
00117    }
00118 
00119    bool   isEquivalent(const DecompVar& dvar) {
00120       return m_s.isEquivalent(dvar.m_s);
00121    }
00122 
00123    bool isDuplicate(const DecompVarList& vars) {
00124       DecompVarList::const_iterator vi;
00125 
00126       for (vi = vars.begin(); vi != vars.end(); vi++) {
00127          if ((*vi)->getStrHash() == this->getStrHash()) {
00128             return true;
00129          }
00130       }
00131 
00132       return false;
00133    }
00134 
00135    bool doesSatisfyBounds(int                     denseLen,
00136                           double*                 denseArr,
00137                           const DecompAlgoModel& model,
00138                           const double*           lbs,
00139                           const double*           ubs);
00140 
00141    void fillDenseArr(int      len,
00142                      double* arr);
00143 
00144 public:
00145    virtual void  print(std::ostream*    os  = &std::cout,
00146                        DecompApp* app = 0) const;
00147    virtual void  print(std::ostream*               os,
00148                        const std::vector<std::string>& colNames,
00149                        const double*          value    = NULL) const;
00150 
00151 public:
00153    DecompVar(const DecompVar& source) :
00154       m_s       (source.m_s),
00155       m_varType (source.m_varType),
00156       m_origCost(source.m_origCost),
00157       m_effCnt  (source.m_effCnt),
00158       m_strHash (source.m_strHash),
00159       m_blockId (source.m_blockId),
00160       m_colMasterIndex (source.m_colMasterIndex),
00161       m_norm    (source.m_norm) {
00162    }
00163 
00164    DecompVar& operator=(const DecompVar& rhs) {
00165       if (this != &rhs) {
00166          m_s        = rhs.m_s;
00167          m_varType  = rhs.m_varType;
00168          m_origCost = rhs.m_origCost;
00169          m_redCost  = rhs.m_redCost;
00170          m_effCnt   = rhs.m_effCnt;
00171          m_strHash  = rhs.m_strHash;
00172          m_blockId  = rhs.m_blockId;
00173          m_colMasterIndex = rhs.m_colMasterIndex;
00174       }
00175 
00176       return *this;
00177    }
00178 
00179    DecompVar():
00180       m_s       (),
00181       m_varType (DecompVar_Point),
00182       m_origCost(0.0),
00183       m_redCost (0.0),
00184       m_effCnt  (0),
00185       m_strHash (),
00186       m_blockId (0),
00187       m_colMasterIndex(-1),
00188       m_norm    (0.0) {
00189       }
00190 
00191    DecompVar(const std::vector<int>&     ind,
00192              const double           els,
00193              const double           redCost,
00194              const double           origCost,
00195              const DecompVarType    varType) :
00196       m_s       (),
00197       m_varType (varType),
00198       m_origCost(origCost),
00199       m_redCost (redCost),
00200       m_effCnt  (0),
00201       m_strHash (),
00202       m_blockId (0),
00203       m_colMasterIndex(-1),
00204       m_norm    (0.0) {
00205      //m_varType = varType;
00206      if (ind.size() > 0) {
00207         m_s.setConstant(static_cast<int>(ind.size()),
00208                 &ind[0], els, DECOMP_TEST_DUPINDEX);
00209         m_strHash = UtilCreateStringHash(static_cast<int>(ind.size()),
00210                          &ind[0], els);
00211         m_norm    = calcNorm();
00212         sortVar();
00213      }
00214       }
00215 
00216    DecompVar(const std::vector<int>&     ind,
00217              const std::vector<double>& els,
00218              const double           redCost,
00219              const double           origCost) :
00220       m_s       (),
00221       m_varType (DecompVar_Point),
00222       m_origCost(origCost),
00223       m_redCost (redCost),
00224       m_effCnt  (0),
00225       m_strHash (),
00226       m_blockId (0),
00227       m_colMasterIndex(-1),
00228       m_norm    (0.0) {
00229      //m_varType = DecompVar_Point;
00230      if (ind.size() > 0) {
00231         m_s.setVector(static_cast<int>(ind.size()),
00232               &ind[0], &els[0], DECOMP_TEST_DUPINDEX);
00233         m_strHash = UtilCreateStringHash(static_cast<int>(ind.size()),
00234                          &ind[0], &els[0]);
00235         m_norm    = calcNorm();
00236         sortVar();
00237      }
00238       }
00239 
00240    DecompVar(const std::vector<int>&     ind,
00241              const std::vector<double>& els,
00242              const double           redCost,
00243              const double           origCost,
00244              const DecompVarType    varType) :
00245       m_s       (),
00246       m_varType (varType),
00247       m_origCost(origCost),
00248       m_redCost (redCost),
00249       m_effCnt  (0),
00250       m_strHash (),
00251       m_blockId (0),
00252       m_colMasterIndex(-1),
00253       m_norm    (0.0) {
00254      //m_varType = varType;
00255      if (ind.size() > 0) {
00256         m_s.setVector(static_cast<int>(ind.size()),
00257               &ind[0], &els[0], DECOMP_TEST_DUPINDEX);
00258         m_strHash = UtilCreateStringHash(static_cast<int>(ind.size()),
00259                          &ind[0], &els[0]);
00260         m_norm    = calcNorm();
00261         sortVar();
00262      }
00263       }
00264 
00265    DecompVar(const int              len,
00266              const int*             ind,
00267              const double*          els,
00268              const double           origCost) :
00269       m_s       (),
00270       m_varType (DecompVar_Point),
00271       m_origCost(origCost),
00272       m_redCost (0.0),
00273       m_effCnt  (0),
00274       m_strHash (),
00275       m_blockId (0),
00276       m_colMasterIndex(-1),
00277       m_norm    (0.0) {
00278      if (len > 0) {
00279         m_s.setVector(len, ind, els, DECOMP_TEST_DUPINDEX);
00280         m_strHash = UtilCreateStringHash(len, ind, els);
00281         m_norm    = calcNorm();
00282         sortVar();
00283      }
00284       }
00285 
00286    DecompVar(const int              len,
00287              const int*             ind,
00288              const double*          els,
00289              const double           origCost,
00290              const DecompVarType    varType) :
00291       m_s       (),
00292       m_varType (varType),
00293       m_origCost(origCost),
00294       m_redCost (0.0),
00295       m_effCnt  (0),
00296       m_strHash (),
00297       m_blockId (0),
00298       m_colMasterIndex(-1),
00299       m_norm    (0.0) {
00300      if (len > 0) {
00301         m_s.setVector(len, ind, els, DECOMP_TEST_DUPINDEX);
00302         m_strHash = UtilCreateStringHash(len, ind, els);
00303         m_norm    = calcNorm();
00304         sortVar();
00305      }
00306       }
00307 
00308    DecompVar(const int              len,
00309              const int*             ind,
00310              const double           els,
00311              const double           origCost) :
00312       m_s       (),
00313       m_varType (DecompVar_Point),
00314       m_origCost(origCost),
00315       m_redCost (0.0),
00316       m_effCnt  (0),
00317       m_strHash (),
00318       m_blockId (0),
00319       m_colMasterIndex(-1),
00320       m_norm    (0.0) {
00321      if (len > 0) {
00322         m_s.setConstant(len, ind, els, DECOMP_TEST_DUPINDEX);
00323         m_strHash = UtilCreateStringHash(len, ind, els);
00324         m_norm    = calcNorm();
00325         sortVar();
00326      }
00327       }
00328 
00329    DecompVar(const int              len,
00330              const int*             ind,
00331              const double           els,
00332              const double           origCost,
00333              const DecompVarType    varType) :
00334       m_s       (),
00335       m_varType (varType),
00336       m_origCost(origCost),
00337       m_redCost (0.0),
00338       m_effCnt  (0),
00339       m_strHash (),
00340       m_blockId (0),
00341       m_colMasterIndex(-1),
00342       m_norm    (0.0) {
00343      if (len > 0) {
00344         m_s.setConstant(len, ind, els, DECOMP_TEST_DUPINDEX);
00345         m_strHash = UtilCreateStringHash(len, ind, els);
00346         m_norm    = calcNorm();
00347         sortVar();
00348      }
00349       }
00350 
00351    DecompVar(const int              len,
00352              const int*             ind,
00353              const double*          els,
00354              const double           redCost,
00355              const double           origCost) :
00356       m_s       (),
00357       m_varType (DecompVar_Point),
00358       m_origCost(origCost),
00359       m_redCost (redCost),
00360       m_effCnt  (0),
00361       m_strHash (),
00362       m_blockId (0),
00363       m_colMasterIndex(-1),
00364       m_norm    (0.0) {
00365      if (len > 0) {
00366         m_s.setVector(len, ind, els, DECOMP_TEST_DUPINDEX);
00367         m_strHash = UtilCreateStringHash(len, ind, els);
00368         m_norm    = calcNorm();
00369         sortVar();
00370      }
00371       }
00372 
00373    DecompVar(const int              len,
00374              const int*             ind,
00375              const double*          els,
00376              const double           redCost,
00377              const double           origCost,
00378              const DecompVarType    varType) :
00379       m_s       (),
00380       m_varType (varType),
00381       m_origCost(origCost),
00382       m_redCost (redCost),
00383       m_effCnt  (0),
00384       m_strHash (),
00385       m_blockId (0),
00386       m_colMasterIndex(-1),
00387       m_norm    (0.0) {
00388      if (len > 0) {
00389         m_s.setVector(len, ind, els, DECOMP_TEST_DUPINDEX);
00390         m_strHash = UtilCreateStringHash(len, ind, els);
00391         m_norm    = calcNorm();
00392         sortVar();
00393      }
00394       }
00395 
00396    DecompVar(const int              denseLen,
00397              const double*          denseArray,
00398              const double           redCost,
00399              const double           origCost,
00400              const DecompVarType    varType) :
00401       m_s       (DECOMP_TEST_DUPINDEX),
00402       m_varType (varType),
00403       m_origCost(origCost),
00404       m_redCost (redCost),
00405       m_effCnt  (0),
00406       m_strHash (),
00407       m_blockId (0),
00408       m_colMasterIndex(-1),
00409       m_norm    (0.0) {
00410      UtilPackedVectorFromDense(denseLen, denseArray, DecompEpsilon, m_s);
00411      
00412      if (m_s.getNumElements() > 0) {
00413         m_strHash = UtilCreateStringHash(denseLen, denseArray);
00414         m_norm    = calcNorm();
00415         sortVar();
00416      }
00417       }
00418 
00419    virtual ~DecompVar() {};
00420 };
00421 
00422 #endif

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