/home/coin/SVN-release/OS-2.1.1/Bonmin/src/Algorithms/BonBabSetupBase.hpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation 2007
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, International Business Machines Corporation
00007 //
00008 // Date : 04/12/2007
00009 
00010 #ifndef BabSetupBase_H
00011 #define BabSetupBase_H
00012 
00013 #include <string>
00014 #include <list>
00015 #include "CglCutGenerator.hpp"
00016 #include "CbcHeuristic.hpp"
00017 #include "OsiChooseVariable.hpp"
00018 #include "BonOsiTMINLPInterface.hpp"
00019 namespace Bonmin
00020 {
00022   class BabSetupBase
00023   {
00024   public:
00026     struct CuttingMethod 
00027     {
00028       int frequency;
00029       std::string id;
00030       CglCutGenerator * cgl;
00031       bool atSolution;
00032       bool normal;
00033       CuttingMethod():
00034           atSolution(false),
00035           normal(true)
00036       {}
00037 
00038       CuttingMethod(const CuttingMethod & other):
00039           frequency(other.frequency),
00040           id(other.id),
00041           cgl(other.cgl),
00042           atSolution(other.atSolution),
00043           normal(other.normal)
00044       {}
00045     };
00047     struct HeuristicMethod
00048     {
00049       std::string id;
00050       CbcHeuristic* heuristic;
00051       HeuristicMethod()
00052       {}
00053 
00054       HeuristicMethod(const HeuristicMethod & other):
00055           id(other.id),
00056           heuristic(other.heuristic)
00057       {}
00058     };
00059     typedef std::list<CuttingMethod> CuttingMethods;
00060     typedef std::list<HeuristicMethod  > HeuristicMethods;
00061 
00063     enum NodeComparison {
00064       bestBound = 0 ,
00065       DFS ,
00066       BFS ,
00067       dynamic ,
00069       bestGuess 
00070     };
00071 
00073     enum TreeTraversal {
00074       HeapOnly=0 ,
00075       DiveFromBest ,
00076       ProbedDive ,
00077       DfsDiveFromBest ,
00078       DfsDiveDynamic 
00079     };
00080 
00081 
00083     enum VarSelectStra_Enum {
00084       MOST_FRACTIONAL=0,
00085       STRONG_BRANCHING,
00086       RELIABILITY_BRANCHING,
00087       CURVATURE_ESTIMATOR,
00088       QP_STRONG_BRANCHING,
00089       LP_STRONG_BRANCHING,
00090       NLP_STRONG_BRANCHING,
00091       OSI_SIMPLE,
00092       OSI_STRONG,
00093       RANDOM
00094     };
00095 
00097     enum IntParameter{
00098       BabLogLevel = 0 ,
00099       BabLogInterval,
00100       MaxFailures ,
00101       FailureBehavior ,
00102       MaxInfeasible ,
00104       NumberStrong ,
00105       MinReliability ,
00106       MaxNodes ,
00107       MaxSolutions ,
00108       MaxIterations ,
00109       SpecialOption ,
00110       DisableSos ,
00111       NumCutPasses,
00112       NumCutPassesAtRoot,
00113       RootLogLevel,
00114       NumberIntParam 
00115     };
00116 
00117 
00119     enum DoubleParameter{
00120       CutoffDecr = 0 ,
00121       Cutoff ,
00122       AllowableGap ,
00123       AllowableFractionGap ,
00124       IntTol ,
00125       MaxTime ,
00126       NumberDoubleParam 
00127     };
00128 
00130     BabSetupBase(const CoinMessageHandler * handler = NULL);
00131 
00133     BabSetupBase(Ipopt::SmartPtr<TMINLP> tminlp, const CoinMessageHandler * handler = NULL);
00135     BabSetupBase(Ipopt::SmartPtr<TNLPSolver> app);
00137     BabSetupBase(const OsiTMINLPInterface& nlp);
00139     BabSetupBase(const BabSetupBase &setup,
00140                  OsiTMINLPInterface &nlp);
00141 
00143     BabSetupBase(const BabSetupBase &setup,
00144                  OsiTMINLPInterface &nlp,
00145                  const std::string &prefix);
00146 
00148     BabSetupBase(const BabSetupBase & other);
00149 
00151     virtual BabSetupBase * clone() const = 0;
00152 
00154     virtual BabSetupBase *clone(OsiTMINLPInterface&nlp)const;
00156     virtual ~BabSetupBase();
00157 
00161     void use(const OsiTMINLPInterface& nlp);
00163     void use(Ipopt::SmartPtr<TMINLP> tminlp );
00165     void use(Ipopt::SmartPtr<TMINLP2TNLP> prob);
00167     void setNonlinearSolver(OsiTMINLPInterface * s)
00168     {
00169       nonlinearSolver_ = s;
00170     }
00176     virtual void registerOptions();
00178     virtual void setBabDefaultOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
00179     {}
00181     static void registerAllOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
00182 
00184     virtual void readOptionsFile()
00185     {
00186       if (readOptions_) return;
00187       readOptionsFile("bonmin.opt");
00188     }
00189 
00191     void readOptionsFile(std::string fileName);
00192 
00194     void readOptionsString(std::string opt_string);
00195 
00197     void readOptionsStream(std::istream& is);
00198 
00200     void mayPrintDoc();
00201 
00202 
00204     const char * prefix() const {
00205       return prefix_.c_str();
00206     }
00207 
00209     void setOptionsAndJournalist(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00210         Ipopt::SmartPtr<Ipopt::OptionsList> options,
00211         Ipopt::SmartPtr<Ipopt::Journalist> journalist)
00212     {
00213       options_ = options;
00214       roptions_ = roptions;
00215       journalist_ = journalist;
00216     }
00217 
00219     void initializeOptionsAndJournalist();
00225     OsiTMINLPInterface * nonlinearSolver()
00226     {
00227       return nonlinearSolver_;
00228     }
00230     OsiSolverInterface * continuousSolver()
00231     {
00232       return continuousSolver_;
00233     }
00235     CuttingMethods& cutGenerators()
00236     {
00237       return cutGenerators_;
00238     }
00240     HeuristicMethods& heuristics()
00241     {
00242       return heuristics_;
00243     }
00245     OsiChooseVariable * branchingMethod()
00246     {
00247       return branchingMethod_;
00248     }
00250     NodeComparison nodeComparisonMethod()
00251     {
00252       return nodeComparisonMethod_;
00253     }
00255     TreeTraversal treeTraversalMethod()
00256     {
00257       return treeTraversalMethod_;
00258     }
00260     int getIntParameter(const IntParameter &p) const
00261     {
00262       return intParam_[p];
00263     }
00265     double getDoubleParameter(const DoubleParameter &p) const
00266     {
00267       return doubleParam_[p];
00268     }
00270     void setIntParameter(const IntParameter &p, const int v)
00271     {
00272       intParam_[p] = v;
00273     }
00275     void setDoubleParameter(const DoubleParameter &p, const double v)
00276     {
00277       doubleParam_[p] = v;
00278     }
00282     void gatherParametersValues()
00283     {
00284       gatherParametersValues(options_);
00285     }
00287     void gatherParametersValues(Ipopt::SmartPtr<OptionsList> options);
00289     Ipopt::SmartPtr<Ipopt::Journalist> journalist()
00290     {
00291       return journalist_;
00292     }
00293 
00295     Ipopt::SmartPtr<Ipopt::OptionsList> options()
00296     {
00297       return options_;
00298     }
00299 
00301     Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions()
00302     {
00303       return roptions_;
00304     }
00305 
00307     const vector<OsiObject *>& objects() const
00308     {
00309       return objects_;
00310     }
00311 
00313     vector<OsiObject *>& objects()
00314     {
00315       return objects_;
00316     }
00317    
00318   protected:
00320     void setPriorities();
00322     void addSos();
00323 
00325     int intParam_[NumberIntParam];
00327     static int defaultIntParam_[NumberIntParam];
00329     double doubleParam_[NumberDoubleParam];
00331     static double defaultDoubleParam_[NumberDoubleParam];
00333     OsiTMINLPInterface * nonlinearSolver_;
00335     OsiSolverInterface * continuousSolver_;
00337     CuttingMethods cutGenerators_;
00339     HeuristicMethods heuristics_;
00341     OsiChooseVariable * branchingMethod_;
00343     NodeComparison nodeComparisonMethod_;
00345     TreeTraversal treeTraversalMethod_;
00347     vector<OsiObject *> objects_;
00348     
00349 
00351     Ipopt::SmartPtr<Ipopt::Journalist> journalist_;
00352 
00354     Ipopt::SmartPtr<Ipopt::OptionsList> options_;
00355 
00357     Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions_;
00358 
00360     bool readOptions_;
00362     CoinMessageHandler * messageHandler_;
00364     std::string prefix_;
00365   };
00366 }/* End namespace Bonmin. */
00367 #endif
00368 

Generated on Mon May 3 03:05:13 2010 by  doxygen 1.4.7