00001
00002
00003
00004 #ifndef SmiScnData_HPP
00005 #define SmiScnData_HPP
00006
00007 #if defined(_MSC_VER)
00008
00009 # pragma warning(disable:4786)
00010 #endif
00011
00012 #include "OsiSolverInterface.hpp"
00013 #include "CoinPackedVector.hpp"
00014 #include "CoinMpsIO.hpp"
00015 #include "SmiCoreCombineRule.hpp"
00016 #include "SmiLinearData.hpp"
00017
00018 #include <map>
00019 #include <vector>
00020
00021 using namespace std;
00022
00023
00024 typedef int SmiCoreIndex;
00025 typedef int SmiScenarioIndex;
00026 typedef int SmiStageIndex;
00027
00028 class SmiCoreData;
00029
00030 class SmiNodeData : public SmiLinearData
00031 {
00032 public:
00033 typedef map<int,CoinPackedVector *> SmiRowMap;
00034 void setCoreNode();
00035 CoinPackedVector * getRow(int i) {
00036 SmiRowMap::iterator r=rowMap.find(i);
00037 if (r!=rowMap.end()) return r->second;
00038 else return NULL;}
00039 inline SmiCoreData * getCore() { return core_;}
00040 inline int getStage() { return stg_;}
00041 inline int getNumElements(){ return nels_; }
00042
00043 inline void setCoreCombineRule(SmiCoreCombineRule *r){combineRule_=r;}
00044 inline SmiCoreCombineRule * getCoreCombineRule() { return combineRule_;}
00045
00046 void copyRowLower(double * drlo);
00047 void copyRowUpper(double * drup);
00048 void copyColLower(double * dclo);
00049 void copyColUpper(double * dcup);
00050 void copyObjective(double * dobj);
00051
00052 CoinPackedVector * combineWithCoreRow(CoinPackedVector *cr, CoinPackedVector *nr);
00053
00054 SmiNodeData(SmiStageIndex stg, SmiCoreData *core,
00055 const CoinPackedMatrix *const matrix,
00056 CoinPackedVector *dclo,
00057 CoinPackedVector *dcup,
00058 CoinPackedVector *dobj,
00059 CoinPackedVector *drlo,
00060 CoinPackedVector *drup);
00061 ~SmiNodeData();
00062
00063 protected:
00064 void combineWithCoreDoubleArray(double *d_out, const CoinPackedVector &cpv, int o);
00065
00066 private:
00067 SmiStageIndex stg_;
00068 SmiRowMap rowMap;
00069 int nels_;
00070 SmiCoreData *core_;
00071 bool isCoreNode_;
00072 SmiCoreCombineRule *combineRule_;
00073 };
00074
00075
00076 class SmiCoreData
00077 {
00078 public:
00079 inline int getNumCols(){ return ncol_;}
00080 inline int getNumRows(){ return nrow_;}
00081 inline int getNumStages(){ return nstag_;}
00082 inline int getNumCols(SmiStageIndex t){ return nColInStage_[t];}
00083 inline int getNumRows(SmiStageIndex t){ return nRowInStage_[t];}
00084 inline int getColStart(SmiStageIndex t){ return stageColPtr_[t];}
00085 inline int getRowStart(SmiStageIndex t){ return stageRowPtr_[t];}
00086 inline int getColStage(int i){ return colStage_[i];}
00087 inline int getRowStage(int i){ return rowStage_[i];}
00088 inline int getRowInternalIndex(int i){ return rowEx2In_[i];}
00089 inline int getColInternalIndex(int i){ return colEx2In_[i];}
00090 inline int getRowExternalIndex(int i){ return rowIn2Ex_[i];}
00091 inline int getColExternalIndex(int i){ return colIn2Ex_[i];}
00092 inline CoinPackedVector * getMatrixRow(SmiStageIndex t, int i){ return nodes_[t]->getRow(i);}
00093 inline const CoinPackedVector &getRowLower(SmiStageIndex t){return nodes_[t]->getRowLower();}
00094 inline const CoinPackedVector &getRowUpper(SmiStageIndex t){return nodes_[t]->getRowUpper();}
00095 inline const CoinPackedVector &getColLower(SmiStageIndex t){return nodes_[t]->getColLower();}
00096 inline const CoinPackedVector &getColUpper(SmiStageIndex t){return nodes_[t]->getColUpper();}
00097 inline const CoinPackedVector &getObjCoefficients(SmiStageIndex t){return nodes_[t]->getObjective();}
00098
00099 void copyRowLower(double * drlo,SmiStageIndex t );
00100 void copyRowUpper(double * drup,SmiStageIndex t);
00101 void copyColLower(double * dclo,SmiStageIndex t);
00102 void copyColUpper(double * dcup,SmiStageIndex t);
00103 void copyObjective(double * dobj,SmiStageIndex t);
00104
00105 inline SmiNodeData * getNode(SmiStageIndex t){return nodes_[t];}
00106 SmiCoreData(OsiSolverInterface *osi, int nstag, int *cstag, int *rstag);
00107 SmiCoreData(CoinMpsIO *cMps, int nstag, int *cstag, int *rstag);
00108 ~SmiCoreData();
00109
00110 private:
00111 void gutsOfConstructor(int nrow,int ncol,int nstag,
00112 int *cstag,int *rstag,
00113 CoinPackedMatrix *matrix,
00114 CoinPackedVector *dclo,
00115 CoinPackedVector *dcup,
00116 CoinPackedVector *dobj,
00117 CoinPackedVector *drlo,
00118 CoinPackedVector *drup);
00119 private:
00120 int nrow_;
00121 int ncol_;
00122 SmiStageIndex nstag_;
00123 int *nColInStage_;
00124 int *nRowInStage_;
00125 int *stageColPtr_;
00126 int *stageRowPtr_;
00127 int *colStage_;
00128 int *rowStage_;
00129 int *colEx2In_;
00130 int *rowEx2In_;
00131 int *colIn2Ex_;
00132 int *rowIn2Ex_;
00133 double **cdrlo_;
00134 double **cdrup_;
00135 double **cdobj_;
00136 double **cdclo_;
00137 double **cdcup_;
00138 vector<SmiNodeData*> nodes_;
00139 };
00140
00141 #endif //#define SmiScnData_HPP