DecompAlgo.old.h

Go to the documentation of this file.
00001 //===========================================================================//
00002 // This file is part of the Decomp Solver Framework.                         //
00003 //                                                                           //
00004 // Decomp is distributed under the Common Public License as part of the      //
00005 // COIN-OR repository (http://www.coin-or.org).                              //
00006 //                                                                           //
00007 // Author: Matthew Galati, Lehigh University                                 //
00008 //                                                                           //
00009 // Copyright (C) 2002-2007, Lehigh University, Matthew Galati, and Ted Ralphs//
00010 // All Rights Reserved.                                                      //
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 //class DecompStats;
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;     //"who am i"
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    //THINK: naming outer, inner?? - will work across all?
00065 
00066    //solver interface for subproblem (P')  
00067    map<int, OsiSolverInterface*>   m_subprobSI;
00068 
00069    //solver interface for master (Q")
00070    OsiSolverInterface          * m_masterSI;
00071 
00072 #ifdef __DECOMP_LP_CLP__
00073    //THINK: so we don't freecached when getModelPtr - do once... 
00074    //makes it so that we are stuck with CLP - also need to support CPX
00075    ClpModel                    * m_masterCLP;
00076 #endif
00077 
00078 
00079    //m_vars and m_cuts have no destructor, but they are list of ptrs
00080    //the memory they point to needs to be deleted.
00081   
00082    //member of app or member of algo?
00083    DecompVarList           m_vars;          //list of vars added to master
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;//known opt
00092 
00093    double                  * m_xhat;
00094    
00095    //think about do we want a solution pool?
00096    //for now, just keep the best and toss the rest
00097    vector<DecompSolution*>   m_xhatIPFeas;
00098    DecompSolution          * m_xhatIPBest;
00099 
00100    int m_numOrigCols; //DECOMP
00101 
00102    vector< vector<double> > m_optPoint;
00103 
00104    //stabilization techniques
00105    double * m_piEstimate;
00106    vector<bool> isStab;
00107 
00108  public:
00109    //these are just pointers into app
00110    DecompConstraintSet * m_modelCore;
00111    DecompConstraintSet * m_modelRelax;
00112 
00113    DecompStats           m_stats;
00114 
00115  public:
00116    //helper functions
00117    OsiSolverInterface * initSolverInterface(); 
00118   
00119    //TODO: functions in alphabetical order??
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    //TODO: should not call these LB UB
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    //helper functions - DecompDebug.cpp
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    //pure virtual methods
00188 
00189 
00190 
00191 
00192    virtual void createMasterProblem(DecompVarList & initVars) = 0;
00193 
00194    //possible base is enough here too... think at least for PC and C 
00195    //seem to be ok
00196 
00197    //just base is enough for PC and C here
00198    virtual DecompStat solutionUpdate(const DecompPhase phase,
00199                                      const int         maxInnerIter,
00200                                      const int         maxOuterIter);
00201 
00202    //just base is enough?
00203    virtual DecompPhase phaseUpdate(const DecompPhase   phase,
00204                                    const DecompStat    stat);
00205   
00206  public:
00207    //virtual methods
00208    //all this mess, just so that we don't use m_masterSI for RC??
00209    //doesn't make alot of sense to me... THINK
00210   
00211    //just feed u vector in rowPrice in OSI???
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];//THINK
00239       //return m_masterSI->getRightHandSide();
00240    }
00241    virtual const char * getRowSense() const {
00242       return &m_modelCore->rowSense[0];//THINK - should be SI?
00243       //return m_masterSI->getRowSense();
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    //different name? set x vector? and maybe base just memcpy
00256    //while PC does recompose then copies in? 
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    //will never get called in C, yet PC specific, do nothing in base
00267    //and move to PC?
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    //different for C and PC, pure virtual for now
00280    virtual void addCutsToPool(const double  *  x,
00281                               DecompCutList & newCuts,
00282                               int           & n_newCuts);
00283    virtual int addCutsFromPool();
00284 
00285    //DecompBranch.cpp
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    //process node? or just process?
00294 
00295 
00296    /*helper functions*/
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),//TODO
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       //THINK - if was class, the std::list<T*> would be cleaner?
00360       //let T's destructor do the work? the way cutpool manages that?
00361       //should m_cuts and m_vars be pools anyway? vector to waiting row
00362       //or list of waiting row pts?
00363       UtilDeleteListPtr(m_cuts);
00364       UtilDeleteListPtr(m_vars);
00365 
00366       //THINK - m_initVars always (?) gets pushed into m_vars -
00367       //so if we free here we'll double free?
00368       //UtilDeleteListPtr(m_initVars);
00369 
00370 
00371 
00372       //?? who deletes m_var, m_cuts????
00373    };
00374 };
00375 
00376 #endif
00377         

Generated on 3 Jun 2015 for Dip-All by  doxygen 1.6.1