/home/coin/SVN-release/OS-2.0.1/Bonmin/src/Algorithms/OaGenerators/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 
00010 #ifndef BonOaDecBase_HPP
00011 #define BonOaDecBase_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 
00023 
00024 /* forward declarations.*/
00025 class OsiClpSolverInterface;
00026 class OsiCpxSolverInterface;
00027 
00028 namespace Bonmin
00029 {
00031   class OaDecompositionBase : public CglCutGenerator
00032   {
00033   public:
00035     class SubMipSolver
00036     {
00037     public:
00039       SubMipSolver(OsiSolverInterface * lp = NULL,
00040           const CbcStrategy * strategy = NULL);
00041 
00042       ~SubMipSolver();
00043 
00045       void setLpSolver(OsiSolverInterface * lp);
00046 
00048       void setStrategy(CbcStrategy * strategy)
00049       {
00050         if (strategy_) delete strategy_;
00051         strategy_ = strategy->clone();
00052       }
00054       const double * getLastSolution()
00055       {
00056         return integerSolution_;
00057       }
00058 
00059       double getLowerBound()
00060       {
00061         return lowBound_;
00062       }
00064       void performLocalSearch(double cutoff,
00065           int loglevel,
00066           double maxTime,
00067           int maxNodes);
00068 
00070       inline double lowBound()
00071       {
00072         return lowBound_;
00073       }
00074 
00076       inline bool optimal()
00077       {
00078         return optimal_;
00079       }
00080 
00082       inline int nodeCount()
00083       {
00084         return nodeCount_;
00085       }
00086 
00088       inline int iterationCount()
00089       {
00090         return iterationCount_;
00091       }
00092 
00093 
00095       void registerOptions(Ipopt::SmartPtr<Ipopt::RegisteredOptions> roptions)
00096       {}
00097     private:
00099       OsiSolverInterface * lp_;
00101       OsiClpSolverInterface *clp_;
00103       OsiCpxSolverInterface * cpx_;
00105       CbcModel * cbc_;
00107       double lowBound_;
00109       bool optimal_;
00111       double * integerSolution_;
00113       CbcStrategy * strategy_;
00115       int nodeCount_;
00117       int iterationCount_;
00118     };
00119 
00122     class solverManip
00123     {
00124     public:
00126       solverManip(OsiSolverInterface *si , bool saveNumRows=true,
00127           bool saveBasis=true, bool saveBounds=false,
00128           bool saveCutoff = false, bool resolve=true);
00129 
00131       solverManip(const OsiSolverInterface & si);
00133       ~solverManip();
00135       void restore();
00136 
00138       void cloneOther(const OsiSolverInterface &si);
00141       bool integerFeasible(const OsiBranchingInformation & info) const;
00142 
00146       void fixIntegers(const OsiBranchingInformation & info);
00147 
00149       bool isDifferentOnIntegers(const double * colsol);
00150 
00152       bool isDifferentOnIntegers(const double * colsol, const double * other);
00153 
00155       void installCuts(const OsiCuts& cs, int numberCuts);
00156 
00158       OsiSolverInterface * si()
00159       {
00160         return si_;
00161       }
00162 
00164       void setObjects(OsiObject ** objects, int nObjects)
00165       {
00166         objects_ = objects;
00167         nObjects_ = nObjects;
00168       }
00169 
00170       void setIntegerTolerance(double v)
00171       {
00172         integerTolerance_ = v;
00173       }
00174     private:
00176       OsiSolverInterface * si_;
00178       int initialNumberRows_;
00179 
00181       double * colLower_;
00182 
00184       double * colUpper_;
00185 
00187       CoinWarmStart * warm_;
00188 
00190       double cutoff_;
00191 
00193       bool deleteSolver_;
00194 
00196       OsiObject * * objects_;
00198       int nObjects_;
00202       int numcols_;
00204       int numrows_;
00206       const double * siColLower_;
00208       const double * siColUpper_;
00209 
00210       void getCached();
00212       double integerTolerance_;
00213     };
00215     OaDecompositionBase(OsiTMINLPInterface * nlp = NULL,
00216         OsiSolverInterface * si = NULL,
00217         CbcStrategy * strategy = NULL,
00218         double cbcCutoffIncrement_=1e-07,
00219         double cbcIntegerTolerance = 1e-05,
00220         bool leaveSiUnchanged = 0
00221                        );
00223     OaDecompositionBase(BabSetupBase &b, bool leaveSiUnchanged,
00224         bool reassignLpsolver);
00225 
00227     OaDecompositionBase(const OaDecompositionBase & copy);
00228 
00229 
00231     virtual ~OaDecompositionBase();
00232 
00234     virtual void generateCuts(const OsiSolverInterface &si,  OsiCuts & cs,
00235         const CglTreeInfo info = CglTreeInfo()) const;
00236 
00238     void assignNlpInterface(OsiTMINLPInterface * nlp)
00239     {
00240       nlp_ = nlp;
00241     }
00242 
00244     void assignLpInterface(OsiSolverInterface * si)
00245     {
00246       lp_ = si;
00247     }
00248 
00249     bool reassignLpsolver()
00250     {
00251       return reassignLpsolver_;
00252     }
00254     void setObjects(OsiObject ** objects, int nObjects)
00255     {
00256       objects_ = objects;
00257       nObjects_ = nObjects;
00258     }
00260     inline void setLeaveSiUnchanged(bool yesno)
00261     {
00262       leaveSiUnchanged_ = yesno;
00263     }
00264 
00266     struct Parameters
00267     {
00269       bool global_;
00271       bool addOnlyViolated_;
00273       double cbcCutoffIncrement_;
00275       double cbcIntegerTolerance_;
00277       int localSearchNodeLimit_;
00279       int maxLocalSearchPerNode_;
00281       int maxLocalSearch_;
00283       double maxLocalSearchTime_;
00285       int subMilpLogLevel_;
00287       double logFrequency_;
00288 
00290       Parameters();
00291 
00293       Parameters(const Parameters & other);
00294 
00296       ~Parameters()
00297       {
00298         if (!strategy_) delete strategy_;
00299       }
00300 
00302       void setStrategy(const CbcStrategy & strategy)
00303       {
00304         if (strategy_) delete strategy_;
00305         strategy_ = strategy.clone();
00306       }
00307 
00308       const CbcStrategy * strategy() const
00309       {
00310         return strategy_;
00311       }
00312 private:
00314       CbcStrategy * strategy_;
00315 
00316     };
00317 
00318     Parameters& parameter()
00319     {
00320       return parameters_;
00321     }
00322 
00323     const Parameters& parameter()const
00324     {
00325       return parameters_;
00326     }
00327 
00328     void setLogLevel(int level)
00329     {
00330       handler_->setLogLevel(level);
00331     }
00332 
00333     void passInMessageHandler(CoinMessageHandler * handler);
00334   protected:
00336 
00340     bool solveNlp(OsiBabSolver * babInfo, double cutoff) const;
00343 
00344     virtual double performOa(OsiCuts &cs, solverManip &nlpManip, solverManip &lpManip,
00345         SubMipSolver * &subMip, OsiBabSolver * babInfo, double &) const = 0;
00347     virtual bool doLocalSearch() const = 0;
00348 
00350 
00351 
00352     mutable OsiTMINLPInterface * nlp_;
00354     mutable int nSolve_;
00356     mutable OsiSolverInterface * lp_;
00358     OsiObject * * objects_;
00360     int nObjects_;
00362     mutable int nLocalSearch_;
00364     CoinMessageHandler * handler_;
00366     CoinMessages messages_;
00368     bool leaveSiUnchanged_;
00370     bool reassignLpsolver_;
00372     double timeBegin_;
00373 
00375     Parameters parameters_;
00376 
00379 #ifdef OA_DEBUG
00380     class OaDebug
00381     {
00382       public:
00383       bool checkInteger(const OsiSolverInterface&nlp, std::ostream & os) const;
00384 
00385       void printEndOfProcedureDebugMessage(const OsiCuts &cs,
00386           bool foundSolution,
00387           double solValue,
00388           double milpBound,
00389           bool isInteger,
00390           bool feasible,
00391           std::ostream & os) const;
00392     };
00393 
00395     OaDebug debug_;
00396 
00397 #endif
00398   };
00399 }
00400 #endif
00401 

Generated on Thu Oct 8 03:02:54 2009 by  doxygen 1.4.7