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
00031
00032 {
00033 public:
00034 typedef map<int,CoinPackedVector *> SmiRowMap;
00035 typedef map<int,vector<double> *> SmiDenseRowMap;
00036 void setCoreNode();
00037
00038
00039
00040
00041
00042
00043 vector<double> * getDenseRow(int i);
00044
00045 inline SmiCoreData * getCore() { return core_;}
00046 inline int getStage() { return stg_;}
00047
00048 inline void setCoreCombineRule(SmiCoreCombineRule *r){combineRule_=r;}
00049 inline SmiCoreCombineRule * getCoreCombineRule() { return combineRule_;}
00050
00051 void copyRowLower(double * drlo);
00052 void copyRowUpper(double * drup);
00053 void copyColLower(double * dclo);
00054 void copyColUpper(double * dcup);
00055 void copyObjective(double * dobj);
00056
00057 const int getNumMatrixElements(){
00058 if (this->has_matrix_)
00059 return this->strt_[getMatEnd()]-this->strt_[getMatStart()];
00060 else
00061 return 0;
00062 }
00063 const int getRowLength(int irow){
00064 if (this->has_matrix_)
00065 return getLength(this->getMatStart()+irow-this->rowbeg_);
00066 else
00067 return 0;
00068 }
00069 const int getRowLowerLength() {return getLength(this->getRloStart());}
00070 const int getRowUpperLength() {return getLength(this->getRupStart());}
00071 const int getColLowerLength() {return getLength(this->getCloStart());}
00072 const int getColUpperLength() {return getLength(this->getCupStart());}
00073 const int getObjectiveLength() {return getLength(this->getObjStart());}
00074
00075 const int *getRowIndices(int irow){
00076 if (this->has_matrix_)
00077 return getIndices(this->getMatStart()+irow-this->rowbeg_);
00078 else
00079 return NULL;
00080 }
00081 int *getMutableRowIndices(int irow){
00082
00083 return const_cast<int *>(getRowIndices(irow));
00084 }
00085 const int *getRowLowerIndices() {return getIndices(this->getRloStart());}
00086 const int *getRowUpperIndices() {return getIndices(this->getRupStart());}
00087 const int *getColLowerIndices() {return getIndices(this->getCloStart());}
00088 const int *getColUpperIndices() {return getIndices(this->getCupStart());}
00089 const int *getObjectiveIndices() {return getIndices(this->getObjStart());}
00090
00091 const double *getRowElements(int irow){
00092 if (this->has_matrix_)
00093 return getElements(this->getMatStart()+irow-this->rowbeg_);
00094 else
00095 return NULL;
00096 }
00097 double *getMutableRowElements(int irow){
00098
00099 return const_cast<double *>(getRowElements(irow));
00100 }
00101 const double *getRowLowerElements() {return getElements(this->getRloStart());}
00102 const double *getRowUpperElements() {return getElements(this->getRupStart());}
00103 const double *getColLowerElements() {return getElements(this->getCloStart());}
00104 const double *getColUpperElements() {return getElements(this->getCupStart());}
00105 const double *getObjectiveElements() {return getElements(this->getObjStart());}
00106
00107
00108 CoinPackedVector * combineWithCoreRow(CoinPackedVector *cr, CoinPackedVector *nr);
00109 int combineWithDenseCoreRow(vector<double> *dr,CoinPackedVector *cpv,double *dels,int *indx);
00110 int combineWithDenseCoreRow(vector<double> *dr,const int nels,const int *inds, const double *dels, double *dest_dels,int *dest_indx);
00111
00112 SmiNodeData(SmiStageIndex stg, SmiCoreData *core,
00113 const CoinPackedMatrix *const matrix,
00114 CoinPackedVector *dclo,
00115 CoinPackedVector *dcup,
00116 CoinPackedVector *dobj,
00117 CoinPackedVector *drlo,
00118 CoinPackedVector *drup);
00119 ~SmiNodeData();
00120
00121 protected:
00122 void combineWithCoreDoubleArray(double *d_out, const CoinPackedVector &cpv, int o);
00123 void combineWithCoreDoubleArray(double *d_out, const int len, const int * inds, const double *dels, int o);
00124
00125 void assignMemory();
00126 void deleteMemory();
00127
00128
00129 const int getMatStart() { return mat_strt_;}
00130 const int getMatEnd() { return mat_strt_+nrow_;}
00131 const int getRloStart() { return rlo_strt_;}
00132 const int getRupStart() { return rup_strt_;}
00133 const int getCloStart() { return clo_strt_;}
00134 const int getCupStart() { return cup_strt_;}
00135 const int getObjStart() { return obj_strt_;}
00136
00137
00138 const int getLength (int istart){
00139 return this->strt_[istart+1] - this->strt_[istart];
00140 }
00141 const int * getIndices (int istart){
00142 return this->inds_+this->strt_[istart];
00143 }
00144 const double *getElements(int istart){
00145 return this->dels_+this->strt_[istart];
00146 }
00147
00148 private:
00149
00150 SmiStageIndex stg_;
00151 SmiRowMap rowMap;
00152 SmiDenseRowMap dRowMap;
00153
00154 SmiCoreData *core_;
00155 bool isCoreNode_;
00156 SmiCoreCombineRule *combineRule_;
00157
00158 int numarrays_;
00159 int nels_;
00160 int nrow_;
00161 int ncol_;
00162 int rowbeg_;
00163 int colbeg_;
00164 int nstrt_;
00165 bool has_matrix_;
00166 int mat_strt_;
00167 int clo_strt_;
00168 int cup_strt_;
00169 int obj_strt_;
00170 int rlo_strt_;
00171 int rup_strt_;
00172 double * dels_;
00173 int * inds_;
00174 int * strt_;
00175 };
00176
00177
00178 class SmiCoreData
00179 {
00180 public:
00181 inline int getNumCols(){ return ncol_;}
00182 inline int getNumRows(){ return nrow_;}
00183 inline int getNumStages(){ return nstag_;}
00184 inline int getNumCols(SmiStageIndex t){ return nColInStage_[t];}
00185 inline int getNumRows(SmiStageIndex t){ return nRowInStage_[t];}
00186 inline int getColStart(SmiStageIndex t){ return stageColPtr_[t];}
00187 inline int getRowStart(SmiStageIndex t){ return stageRowPtr_[t];}
00188 inline int getColStage(int i){ return colStage_[i];}
00189 inline int getRowStage(int i){ return rowStage_[i];}
00190 inline int getRowInternalIndex(int i){ return rowEx2In_[i];}
00191 inline int getColInternalIndex(int i){ return colEx2In_[i];}
00192 inline int getRowExternalIndex(int i){ return rowIn2Ex_[i];}
00193 inline int getColExternalIndex(int i){ return colIn2Ex_[i];}
00194
00195
00196
00197 inline const double * getDenseRowLower(SmiStageIndex t){return cdrlo_[t];}
00198 inline const double * getDenseRowUpper(SmiStageIndex t){return cdrup_[t];}
00199 inline const double * getDenseColLower(SmiStageIndex t){return cdclo_[t];}
00200 inline const double * getDenseColUpper(SmiStageIndex t){return cdcup_[t];}
00201 inline const double * getDenseObjCoefficients(SmiStageIndex t){return cdobj_[t];}
00202
00203 void copyRowLower(double * drlo,SmiStageIndex t );
00204 void copyRowUpper(double * drup,SmiStageIndex t);
00205 void copyColLower(double * dclo,SmiStageIndex t);
00206 void copyColUpper(double * dcup,SmiStageIndex t);
00207 void copyObjective(double * dobj,SmiStageIndex t);
00208
00209 inline SmiNodeData * getNode(SmiStageIndex t){return nodes_[t];}
00210 SmiCoreData(OsiSolverInterface *osi, int nstag, int *cstag, int *rstag);
00211 SmiCoreData(CoinMpsIO *cMps, int nstag, int *cstag, int *rstag);
00212 ~SmiCoreData();
00213
00214 private:
00215 void gutsOfConstructor(int nrow,int ncol,int nstag,
00216 int *cstag,int *rstag,
00217 CoinPackedMatrix *matrix,
00218 CoinPackedVector *dclo,
00219 CoinPackedVector *dcup,
00220 CoinPackedVector *dobj,
00221 CoinPackedVector *drlo,
00222 CoinPackedVector *drup);
00223 private:
00224 int nrow_;
00225 int ncol_;
00226 SmiStageIndex nstag_;
00227 int *nColInStage_;
00228 int *nRowInStage_;
00229 int *stageColPtr_;
00230 int *stageRowPtr_;
00231 int *colStage_;
00232 int *rowStage_;
00233 int *colEx2In_;
00234 int *rowEx2In_;
00235 int *colIn2Ex_;
00236 int *rowIn2Ex_;
00237 double **cdrlo_;
00238 double **cdrup_;
00239 double **cdobj_;
00240 double **cdclo_;
00241 double **cdcup_;
00242 vector<SmiNodeData*> nodes_;
00243 vector<double *> pDenseRow_;
00244 };
00245
00246 #endif //#define SmiScnData_HPP