00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef DECOMP_ALGO_INCLUDED
00014 #define DECOMP_ALGO_INCLUDED
00015
00016 #define EXPLICIT_BOUNDS
00017
00018 #include "DecompConstraintSet.h"
00019 #include "DecompSolution.h"
00020 #include "DecompMemPool.h"
00021 #include "DecompVarPool.h"
00022 #include "DecompCutPool.h"
00023 #include "DecompStats.h"
00024
00025 class DecompApp;
00026 class ClpModel;
00027
00028
00029 #include "OsiSolverInterface.hpp"
00030
00031
00032
00033
00034 class DecompAlgo{
00035 private:
00036 DecompAlgo(const DecompAlgo &);
00037 DecompAlgo & operator=(const DecompAlgo &);
00038
00039 private:
00040 static const char * m_classTag;
00041 static const char * versionTag;
00042 DecompAlgoType m_algo;
00043
00044 protected:
00045 DecompMemPool m_auxMemPool;
00046 DecompApp * m_app;
00047
00048 int m_nodeIndex;
00049 int m_whichModel;
00050 int m_whichCoreModel;
00051 int m_priceCallsRound;
00052 int m_priceCallsTotal;
00053 int m_cutCallsRound;
00054 int m_cutCallsTotal;
00055 int m_varsThisRound;
00056 int m_cutsThisRound;
00057 int m_varsThisCall;
00058 int m_cutsThisCall;
00059
00060 int m_isTightenAlgo;
00061
00062 ostream * m_osLog;
00063
00064
00065
00066
00067 map<int, OsiSolverInterface*> m_subprobSI;
00068
00069
00070 OsiSolverInterface * m_masterSI;
00071
00072 #ifdef __DECOMP_LP_CLP__
00073
00074
00075 ClpModel * m_masterCLP;
00076 #endif
00077
00078
00079
00080
00081
00082
00083 DecompVarList m_vars;
00084 DecompVarList m_initVars;
00085 DecompCutList m_cuts;
00086 DecompVarPool m_varpool;
00087 DecompCutPool m_cutpool;
00088
00089 double m_tlb;
00090 double m_tub;
00091 double m_bestUpperBound;
00092
00093 double * m_xhat;
00094
00095
00096
00097 vector<DecompSolution*> m_xhatIPFeas;
00098 DecompSolution * m_xhatIPBest;
00099
00100 int m_numOrigCols;
00101
00102 vector< vector<double> > m_optPoint;
00103
00104
00105 double * m_piEstimate;
00106 vector<bool> isStab;
00107
00108 public:
00109
00110 DecompConstraintSet * m_modelCore;
00111 DecompConstraintSet * m_modelRelax;
00112
00113 DecompStats m_stats;
00114
00115 public:
00116
00117 OsiSolverInterface * initSolverInterface();
00118
00119
00120 void startupLog();
00121 void initSetup(int whichModel = 1);
00122
00123 void tighten(int whichModel);
00124 inline double getTrueLowerBound(){
00125 return m_tlb;
00126 }
00127 inline double getTrueUpperBound(){
00128 return m_tub;
00129 }
00130
00131
00132 void setTrueLowerBound(const double mostNegReducedCost);
00133 void setTrueUpperBound(const double ub){
00134 m_tub = ub;
00135 };
00136 double calcConstant(const int m,
00137 const double * u);
00138
00139
00140 bool isDualRayInfProof(const double * dualRay,
00141 const CoinPackedMatrix * rowMatrix,
00142 const double * colLB,
00143 const double * colUB,
00144 const double * rowRhs,
00145 ostream * os = 0);
00146 void printBasisInfo(OsiSolverInterface * si,
00147 ostream * os);
00148 void printCurrentProblem(const OsiSolverInterface * si,
00149 const string baseName,
00150 const int nodeIndex,
00151 const int cutPass,
00152 const int pricePass,
00153 const bool printMps = true,
00154 const bool printLp = true);
00155 void printCurrentProblem(const OsiSolverInterface * si,
00156 const string fileName,
00157 const bool printMps = true,
00158 const bool printLp = true);
00159
00160 void printVars(ostream * os = &cout);
00161 void printCuts(ostream * os = &cout);
00162
00163 void solveBruteForce();
00164 void createFullMps(const string filename);
00165 vector<double*> getDualRays(int maxNumRays);
00166
00167 inline void setApp(DecompApp * app){
00168 m_app = app;
00169 }
00170
00171
00172 inline void setBestUpperBound(const double bestUpperBound){
00173 m_bestUpperBound = bestUpperBound;
00174 }
00175
00176 DecompStat solveRelaxed(const int whichModel,
00177 const double * redCostX,
00178 const double * origCost,
00179 const double alpha,
00180 const int n_origCols,
00181 const bool checkRC,
00182 const bool checkDup,
00183 OsiSolverInterface * m_subprobSI,
00184 list<DecompVar*> & vars);
00185
00186 public:
00187
00188
00189
00190
00191
00192 virtual void createMasterProblem(DecompVarList & initVars) = 0;
00193
00194
00195
00196
00197
00198 virtual DecompStat solutionUpdate(const DecompPhase phase,
00199 const int maxInnerIter,
00200 const int maxOuterIter);
00201
00202
00203 virtual DecompPhase phaseUpdate(const DecompPhase phase,
00204 const DecompStat stat);
00205
00206 public:
00207
00208
00209
00210
00211
00212
00213 virtual void setMasterBounds(const double * lbs,
00214 const double * ubs);
00215
00216 OsiSolverInterface * getMasterSolverInterface(){
00217 return m_masterSI;
00218 }
00219
00220 virtual const double * getRowPrice() const {
00221 return m_masterSI->getRowPrice();
00222 }
00223
00224 inline const double * getX(){
00225 return m_xhat;
00226 }
00227
00228 inline DecompApp * getApp(){
00229 return m_app;
00230 }
00231
00232 inline const DecompSolution * getXhatIPBest(){
00233 return m_xhatIPBest;
00234 }
00235
00236 #if 1
00237 virtual const double * getRightHandSide() const {
00238 return &m_modelCore->rowRhs[0];
00239
00240 }
00241 virtual const char * getRowSense() const {
00242 return &m_modelCore->rowSense[0];
00243
00244 }
00245 #endif
00246
00247 int heuristics(const double * xhat,
00248 vector<DecompSolution*> & xhatIPFeas);
00249
00250 virtual int generateVars(const DecompStat stat,
00251 DecompVarList & newVars,
00252 double & mostNegReducedCost);
00253 virtual int generateCuts(DecompCutList & newCuts);
00254
00255
00256
00257 virtual void recomposeSolution(const double * solution,
00258 double * rsolution){
00259 printf("\nbase recomposeSolution does nothing.");
00260 };
00261
00262 virtual int generateInitVars(DecompVarList & initVars);
00263 virtual bool isDone() { return false; };
00264
00265
00266
00267
00268 void addVarsToPool(DecompVarList & newVars);
00269 void addVarsFromPool();
00270
00271
00272 bool isIPFeasible(const double * x,
00273 const double feasTol = 1.0e-4,
00274 const double intTol = 1.0e-4);
00275 bool isLPFeasible(const double * x,
00276 const double feasTol = 1.0e-4);
00277
00278
00279
00280 virtual void addCutsToPool(const double * x,
00281 DecompCutList & newCuts,
00282 int & n_newCuts);
00283 virtual int addCutsFromPool();
00284
00285
00286 int chooseBranchVar(int & branchedOnIndex,
00287 double & branchedOnValue);
00288 virtual int branch(int branchedOnIndex,
00289 double branchedOnValue);
00290 DecompStat processNode(const int nodeIndex = 0,
00291 const double globalLB = -DecompInf,
00292 const double globalUB = DecompInf);
00293
00294
00295
00296
00297 inline void appendVars(DecompVar * var){
00298 m_vars.push_back(var);
00299 }
00300 inline void appendVars(DecompVarList & varList){
00301 copy(varList.begin(), varList.end(), back_inserter(m_vars));
00302 #if 0
00303 if(m_vars.empty()){
00304 m_vars = varList;
00305 }
00306 else
00307 m_vars.insert(m_vars.end(), varList.begin(), varList.end());
00308 #endif
00309 }
00310
00311
00312
00313 public:
00314 DecompAlgo(const DecompAlgoType algo,
00315 DecompApp * app) :
00316 m_algo(algo),
00317 m_auxMemPool(),
00318 m_app(app),
00319 m_whichModel(-1),
00320 m_whichCoreModel(-1),
00321 m_nodeIndex(0),
00322 m_priceCallsRound(0),
00323 m_priceCallsTotal(0),
00324 m_cutCallsRound(0),
00325 m_cutCallsTotal(0),
00326 m_varsThisRound(0),
00327 m_cutsThisRound(0),
00328 m_varsThisCall(0),
00329 m_cutsThisCall(0),
00330 m_isTightenAlgo(0),
00331 m_osLog(&cout),
00332 m_masterSI(0),
00333 m_vars(),
00334 m_initVars(),
00335 m_cuts(),
00336 m_varpool(),
00337 m_cutpool(),
00338 m_tlb(-DecompInf),
00339 m_tub( DecompInf),
00340 m_bestUpperBound(DecompInf),
00341 m_xhat(0),
00342 m_xhatIPBest(0),
00343 m_piEstimate(0)
00344 {
00345 (*m_osLog).setf(ios::fixed);
00346 };
00347
00348 virtual ~DecompAlgo(){
00349 map<int, OsiSolverInterface*>::iterator it;
00350 for(it = m_subprobSI.begin();
00351 it != m_subprobSI.end(); it++){
00352 if(it->second)
00353 UTIL_DELPTR(it->second);
00354 }
00355 UTIL_DELPTR(m_masterSI);
00356 UTIL_DELARR(m_xhat);
00357 UtilDeleteVectorPtr(m_xhatIPFeas);
00358
00359
00360
00361
00362
00363 UtilDeleteListPtr(m_cuts);
00364 UtilDeleteListPtr(m_vars);
00365
00366
00367
00368
00369
00370
00371
00372
00373 };
00374 };
00375
00376 #endif
00377