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