00001
00002
00003
00004 #ifndef SmiScnData_HPP
00005 #define SmiScnData_HPP
00006
00007 #include "CoinPragma.hpp"
00008 #include "OsiSolverInterface.hpp"
00009 #include "CoinPackedVector.hpp"
00010 #include "CoinMpsIO.hpp"
00011 #include "SmiCoreCombineRule.hpp"
00012
00013
00014 #include <map>
00015 #include <vector>
00016
00017
00018 typedef int SmiCoreIndex;
00019 typedef int SmiScenarioIndex;
00020 typedef int SmiStageIndex;
00021
00022 class SmiCoreData;
00023
00024 class SmiNodeData
00025
00026 {
00027 public:
00028 typedef std::map<int,CoinPackedVector *> SmiRowMap;
00029 typedef std::map<int,double *> SmiDenseRowMap;
00030 void setCoreNode();
00031
00032
00033
00034
00035
00036
00037 double * getDenseRow(int i);
00038
00039 inline SmiCoreData * getCore() { return core_;}
00040 inline int getStage() { return stg_;}
00041
00042 inline void setCoreCombineRule(SmiCoreCombineRule *r){combineRule_=r;}
00043 inline SmiCoreCombineRule * getCoreCombineRule() { return combineRule_;}
00044
00045 void copyRowLower(double * drlo);
00046 void copyRowUpper(double * drup);
00047 void copyColLower(double * dclo);
00048 void copyColUpper(double * dcup);
00049 void copyObjective(double * dobj);
00050
00051 const int getNumMatrixElements(){
00052 if (this->has_matrix_)
00053 return this->strt_[getMatEnd()]-this->strt_[getMatStart()];
00054 else
00055 return 0;
00056 }
00057 const int getRowLength(int irow){
00058 if (this->has_matrix_)
00059 return getLength(this->getMatStart()+irow-this->rowbeg_);
00060 else
00061 return 0;
00062 }
00063 const int getRowLowerLength() {return getLength(this->getRloStart());}
00064 const int getRowUpperLength() {return getLength(this->getRupStart());}
00065 const int getColLowerLength() {return getLength(this->getCloStart());}
00066 const int getColUpperLength() {return getLength(this->getCupStart());}
00067 const int getObjectiveLength() {return getLength(this->getObjStart());}
00068 const bool isCoreNode() { return isCoreNode_; }
00069
00070 const int *getRowIndices(int irow){
00071 if (this->has_matrix_)
00072 return getIndices(this->getMatStart()+irow-this->rowbeg_);
00073 else
00074 return NULL;
00075 }
00076 int *getMutableRowIndices(int irow){
00077
00078 return const_cast<int *>(getRowIndices(irow));
00079 }
00080 const int *getRowLowerIndices() {return getIndices(this->getRloStart());}
00081 const int *getRowUpperIndices() {return getIndices(this->getRupStart());}
00082 const int *getColLowerIndices() {return getIndices(this->getCloStart());}
00083 const int *getColUpperIndices() {return getIndices(this->getCupStart());}
00084 const int *getObjectiveIndices() {return getIndices(this->getObjStart());}
00085
00086 const double *getRowElements(int irow){
00087 if (this->has_matrix_)
00088 return getElements(this->getMatStart()+irow-this->rowbeg_);
00089 else
00090 return NULL;
00091 }
00092
00093 const int *getRowStarts(int irow){
00094 if (this->has_matrix_)
00095 return &strt_[this->getMatStart()+irow-this->rowbeg_];
00096 else
00097 return NULL;
00098 }
00099 double *getMutableRowElements(int irow){
00100
00101 return const_cast<double *>(getRowElements(irow));
00102 }
00103 const double *getRowLowerElements() {return getElements(this->getRloStart());}
00104 const double *getRowUpperElements() {return getElements(this->getRupStart());}
00105 const double *getColLowerElements() {return getElements(this->getCloStart());}
00106 const double *getColUpperElements() {return getElements(this->getCupStart());}
00107 const double *getObjectiveElements() {return getElements(this->getObjStart());}
00108
00109
00110 CoinPackedVector * combineWithCoreRow(CoinPackedVector *cr, CoinPackedVector *nr);
00111 int combineWithDenseCoreRow(double *dr,CoinPackedVector *cpv,double *dels,int *indx);
00112 int combineWithDenseCoreRow(double *dr,const int nels,const int *inds, const double *dels, double *dest_dels,int *dest_indx);
00113
00114 SmiNodeData(SmiStageIndex stg, SmiCoreData *core,
00115 const CoinPackedMatrix *const matrix,
00116 CoinPackedVector *dclo,
00117 CoinPackedVector *dcup,
00118 CoinPackedVector *dobj,
00119 CoinPackedVector *drlo,
00120 CoinPackedVector *drup);
00121
00122 int addPtr() { return ++ptr_count; }
00123
00124 ~SmiNodeData();
00125
00126 protected:
00127 void combineWithCoreDoubleArray(double *d_out, const CoinPackedVector &cpv, int o);
00128 void combineWithCoreDoubleArray(double *d_out, const int len, const int * inds, const double *dels, int o);
00129
00130 void assignMemory();
00131 void deleteMemory();
00132
00133
00134 const int getMatStart() { return mat_strt_;}
00135 const int getMatEnd() { return mat_strt_+nrow_;}
00136 const int getRloStart() { return rlo_strt_;}
00137 const int getRupStart() { return rup_strt_;}
00138 const int getCloStart() { return clo_strt_;}
00139 const int getCupStart() { return cup_strt_;}
00140 const int getObjStart() { return obj_strt_;}
00141
00142
00143
00144 const int getLength (int istart){
00145 return this->strt_[istart+1] - this->strt_[istart];
00146 }
00147
00148 const int * getIndices (int istart){
00149 return this->inds_+this->strt_[istart];
00150 }
00151
00152 const double *getElements(int istart){
00153 return this->dels_+this->strt_[istart];
00154 }
00155
00156
00157 private:
00158
00159 SmiStageIndex stg_;
00160 SmiRowMap rowMap;
00161 SmiDenseRowMap dRowMap;
00162
00163 SmiCoreData *core_;
00164 bool isCoreNode_;
00165 SmiCoreCombineRule *combineRule_;
00166
00167 int numarrays_;
00168 int nels_;
00169 int nrow_;
00170 int ncol_;
00171 int rowbeg_;
00172 int colbeg_;
00173 int nstrt_;
00174 bool has_matrix_;
00175 int mat_strt_;
00176 int clo_strt_;
00177 int cup_strt_;
00178 int obj_strt_;
00179 int rlo_strt_;
00180 int rup_strt_;
00181 double * dels_;
00182 int * inds_;
00183 int * strt_;
00184
00185 int ptr_count;
00186 };
00187
00188
00189 class SmiCoreData
00190 {
00191 public:
00192 inline int getNumCols(){ return ncol_;}
00193 inline int getNumRows(){ return nrow_;}
00194 inline int getNumElements(){ return nz_;}
00195 inline int getNumStages(){ return nstag_;}
00196 inline int getNumCols(SmiStageIndex t){ return nColInStage_[t];}
00197 inline int getNumRows(SmiStageIndex t){ return nRowInStage_[t];}
00198 inline int getColStart(SmiStageIndex t){ return stageColPtr_[t];}
00199 inline int getRowStart(SmiStageIndex t){ return stageRowPtr_[t];}
00200 inline int getColStage(int i){ return colStage_[i];}
00201 inline int getRowStage(int i){ return rowStage_[i];}
00202
00203 inline int getRowInternalIndex(int i){ return rowEx2In_[i];}
00204 inline int getColInternalIndex(int i){ return colEx2In_[i];}
00205 inline int getRowExternalIndex(int i){ return rowIn2Ex_[i];}
00206 inline int getColExternalIndex(int i){ return colIn2Ex_[i];}
00207
00208
00209
00210 inline const double * getDenseRowLower(SmiStageIndex t){return cdrlo_[t];}
00211 inline const double * getDenseRowUpper(SmiStageIndex t){return cdrup_[t];}
00212 inline const double * getDenseColLower(SmiStageIndex t){return cdclo_[t];}
00213 inline const double * getDenseColUpper(SmiStageIndex t){return cdcup_[t];}
00214 inline const double * getDenseObjCoefficients(SmiStageIndex t){return cdobj_[t];}
00215
00216 inline std::vector<int> getIntCols(int stage) { return intColsStagewise[stage]; };
00217 inline int* getIntegerIndices() { return integerIndices_; }
00218 inline int getIntegerLength() { return integerLength_; }
00219 inline int* getBinaryIndices() { return binaryIndices_; }
00220 inline int getBinaryLength() { return binaryLength_; }
00221 inline double getInfinity() { return infinity_; }
00222
00223 void copyRowLower(double * drlo,SmiStageIndex t );
00224 void copyRowUpper(double * drup,SmiStageIndex t);
00225 void copyColLower(double * dclo,SmiStageIndex t);
00226 void copyColUpper(double * dcup,SmiStageIndex t);
00227 void copyObjective(double * dobj,SmiStageIndex t);
00228
00229 inline SmiNodeData * getNode(SmiStageIndex t){return nodes_[t];}
00230
00231 inline void setColumnNames(char** namesStrict, char** namesFree) { this->colNamesStrict = namesStrict; this->colNamesFree = namesFree; }
00232 inline char** getColumnNames(bool strictFormat = true) { if (strictFormat) return this->colNamesStrict; else return this->colNamesFree; }
00233
00234 SmiCoreData(CoinMpsIO *cMps, int nstag, int *cstag, int *rstag,int *integerIndices = 0, int integerLength = 0, int *binaryIndices = 0, int binaryLength = 0);
00235 SmiCoreData(OsiSolverInterface *osi, int nstag, int *cstag, int *rstag,int *integerIndices = 0, int integerLength = 0, int *binaryIndices = 0, int binaryLength = 0);
00236
00237 ~SmiCoreData();
00238
00239 private:
00240
00241
00242
00243 void gutsOfConstructor(int nrow,int ncol,int nstag, int *cstag,int *rstag, CoinPackedMatrix *matrix, CoinPackedVector *dclo, CoinPackedVector *dcup, CoinPackedVector *dobj, CoinPackedVector *drlo, CoinPackedVector *drup, int* integerIndices = 0,int integerLength = 0,int* binaryIndices = 0,int binaryLength = 0);
00244
00245 OsiSolverInterface* generateCoreProblem(OsiSolverInterface* osi);
00246
00247
00248 private:
00249 int nrow_;
00250 int ncol_;
00251 int nz_;
00252 SmiStageIndex nstag_;
00253 int *nColInStage_;
00254 int *nRowInStage_;
00255 int *stageColPtr_;
00256 int *stageRowPtr_;
00257 int *colStage_;
00258 int *rowStage_;
00259 int *colEx2In_;
00260 int *rowEx2In_;
00261 int *colIn2Ex_;
00262 int *rowIn2Ex_;
00263 int *integerIndices_;
00264 int integerLength_;
00265 int *binaryIndices_;
00266 int binaryLength_;
00267 double infinity_;
00268 double **cdrlo_;
00269 double **cdrup_;
00270 double **cdobj_;
00271 double **cdclo_;
00272 double **cdcup_;
00273 std::vector<SmiNodeData*> nodes_;
00274 std::vector<double *> pDenseRow_;
00275 std::vector< std::vector<int> > intColsStagewise;
00276 char **colNamesStrict;
00277 char **colNamesFree;
00278 };
00279
00280 #endif //#define SmiScnData_HPP