Bonmin  1.7
BonOaDecBase.hpp
Go to the documentation of this file.
00001 // (C) Copyright International Business Machines (IBM) 2006
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // P. Bonami, International Business Machines
00007 //
00008 // Date :  12/07/2006
00009 #ifndef BonOaDecBase_HPP
00010 #define BonOaDecBase_HPP
00011 #include "BonSubMipSolver.hpp"
00012 #include "CglCutGenerator.hpp"
00013 #include "BonBabSetupBase.hpp"
00014 #include "BonOAMessages.hpp"
00015 #include "CbcModel.hpp"
00016 
00017 #include "CbcStrategy.hpp"
00018 
00019 #include "CoinTime.hpp"
00020 #include "OsiAuxInfo.hpp"
00021 #include "OsiBranchingObject.hpp"
00022 #include <iostream>
00023 #include "BonBabInfos.hpp"
00024 namespace Bonmin
00025 {
00027   class OaDecompositionBase : public CglCutGenerator
00028   {
00029   public:
00030 
00031 
00034     class solverManip
00035     {
00036     public:
00038       solverManip(OsiSolverInterface *si , bool saveNumRows=true,
00039           bool saveBasis=true, bool saveBounds=false,
00040           bool saveCutoff = false, bool resolve=true);
00041 
00043       solverManip(const OsiSolverInterface & si);
00045       ~solverManip();
00047       void restore();
00048       
00050       OsiSolverInterface * si()
00051       {
00052         return si_;
00053       }
00054 
00056       void setObjects(OsiObject ** objects, int nObjects)
00057       {
00058         objects_ = objects;
00059         nObjects_ = nObjects;
00060       }
00061 
00062     private:
00064       OsiSolverInterface * si_;
00066       int initialNumberRows_;
00067 
00069       double * colLower_;
00070 
00072       double * colUpper_;
00073 
00075       CoinWarmStart * warm_;
00076 
00078       double cutoff_;
00079 
00081       bool deleteSolver_;
00082 
00084       OsiObject * * objects_;
00086       int nObjects_;
00090       int numcols_;
00092       int numrows_;
00094       const double * siColLower_;
00096       const double * siColUpper_;
00097 
00098       void getCached();
00100     };
00101 
00103     OaDecompositionBase(BabSetupBase &b, bool leaveSiUnchanged,
00104         bool reassignLpsolver);
00105 
00107     OaDecompositionBase(const OaDecompositionBase & copy);
00108 
00109 
00111     virtual ~OaDecompositionBase();
00112 
00114     virtual void generateCuts(const OsiSolverInterface &si,  OsiCuts & cs,
00115         const CglTreeInfo info = CglTreeInfo());
00116 
00118     void assignNlpInterface(OsiTMINLPInterface * nlp)
00119     {
00120       nlp_ = nlp;
00121     }
00122 
00124     void assignLpInterface(OsiSolverInterface * si)
00125     {
00126       lp_ = si;
00127     }
00128 
00129     bool reassignLpsolver()
00130     {
00131       return reassignLpsolver_;
00132     }
00134     void setObjects(OsiObject ** objects, int nObjects)
00135     {
00136       objects_ = objects;
00137       nObjects_ = nObjects;
00138     }
00140     inline void setLeaveSiUnchanged(bool yesno)
00141     {
00142       leaveSiUnchanged_ = yesno;
00143     }
00144 
00146     struct Parameters
00147     {
00149       bool global_;
00151       bool addOnlyViolated_;
00153       double cbcCutoffIncrement_;
00155       double cbcIntegerTolerance_; 
00157       double gap_tol_;
00159       int maxLocalSearch_;
00161       double maxLocalSearchTime_;
00163       int subMilpLogLevel_;
00165       int maxSols_;
00167       double logFrequency_;
00168      
00169       
00171       Parameters();
00172 
00174       Parameters(const Parameters & other);
00175 
00177       ~Parameters()
00178       {
00179         if (strategy_) delete strategy_;
00180       }
00181 
00183       void setStrategy(const CbcStrategy & strategy)
00184       {
00185         if (strategy_) delete strategy_;
00186         strategy_ = strategy.clone();
00187       }
00188 
00189       const CbcStrategy * strategy() const
00190       {
00191         return strategy_;
00192       }
00193 
00194 private:
00196       CbcStrategy * strategy_;
00197 
00198     };
00199 
00200     Parameters& parameter()
00201     {
00202       return parameters_;
00203     }
00204 
00205     const Parameters& parameter()const
00206     {
00207       return parameters_;
00208     }
00209 
00210     void setLogLevel(int level)
00211     {
00212       handler_->setLogLevel(level);
00213     }
00214 
00215     void setReassignLpSolver(bool v){
00216       reassignLpsolver_ = v;
00217     }
00218     void passInMessageHandler(CoinMessageHandler * handler);
00219   protected:
00220       void setupMipSolver(BabSetupBase &b, const std::string &prefix);
00222 
00226     bool post_nlp_solve(BabInfo * babInfo, double cutoff) const;
00229 
00230     virtual double performOa(OsiCuts &cs, solverManip &lpManip,
00231                              BabInfo * babInfo, double &, const CglTreeInfo & info) const = 0;
00233     virtual bool doLocalSearch(BabInfo * babInfo) const = 0;
00234 
00236 
00237 
00238     mutable OsiTMINLPInterface * nlp_;
00240     BabSetupBase * s_;
00242     mutable int nSolve_;
00244     mutable OsiSolverInterface * lp_;
00246     OsiObject * * objects_;
00248     int nObjects_;
00250     mutable int nLocalSearch_;
00252     CoinMessageHandler * handler_;
00254     CoinMessages messages_;
00256     bool leaveSiUnchanged_;
00258     bool reassignLpsolver_;
00260     double timeBegin_;
00262     mutable int numSols_;
00263     
00265     Parameters parameters_;
00266 
00270     mutable OsiCuts savedCuts_;
00272     mutable int currentNodeNumber_;
00275 #ifdef OA_DEBUG
00276     class OaDebug
00277     {
00278       public:
00279       bool checkInteger(const OsiSolverInterface&nlp, std::ostream & os) const;
00280 
00281       void printEndOfProcedureDebugMessage(const OsiCuts &cs,
00282           bool foundSolution,
00283           double solValue,
00284           double milpBound,
00285           bool isInteger,
00286           bool feasible,
00287           std::ostream & os) const;
00288     };
00289 
00291     OaDebug debug_;
00292 
00293 #endif
00294   };
00295 }
00296 #endif
00297