Bonmin
1.7
|
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 #include "IpSmartPtr.hpp" 00020 #include "BonTMINLP2OsiLP.hpp" 00021 00022 namespace Bonmin 00023 { 00025 class BabSetupBase 00026 { 00027 public: 00029 struct CuttingMethod 00030 { 00031 int frequency; 00032 std::string id; 00033 CglCutGenerator * cgl; 00034 bool atSolution; 00035 bool normal; 00036 bool always; 00037 CuttingMethod(): 00038 atSolution(false), 00039 normal(true), 00040 always(false) 00041 {} 00042 00043 CuttingMethod(const CuttingMethod & other): 00044 frequency(other.frequency), 00045 id(other.id), 00046 cgl(other.cgl), 00047 atSolution(other.atSolution), 00048 normal(other.normal), 00049 always(other.always) 00050 {} 00051 }; 00053 struct HeuristicMethod 00054 { 00055 std::string id; 00056 CbcHeuristic* heuristic; 00057 HeuristicMethod() 00058 {} 00059 00060 HeuristicMethod(const HeuristicMethod & other): 00061 id(other.id), 00062 heuristic(other.heuristic) 00063 {} 00064 }; 00065 typedef std::list<CuttingMethod> CuttingMethods; 00066 typedef std::list<HeuristicMethod > HeuristicMethods; 00067 00069 enum NodeComparison { 00070 bestBound = 0 , 00071 DFS , 00072 BFS , 00073 dynamic , 00075 bestGuess 00076 }; 00077 00079 enum TreeTraversal { 00080 HeapOnly=0 , 00081 DiveFromBest , 00082 ProbedDive , 00083 DfsDiveFromBest , 00084 DfsDiveDynamic 00085 }; 00086 00087 00089 enum VarSelectStra_Enum { 00090 MOST_FRACTIONAL=0, 00091 STRONG_BRANCHING, 00092 RELIABILITY_BRANCHING, 00093 #ifdef BONMIN_CURVATURE_BRANCHING 00094 CURVATURE_ESTIMATOR, 00095 #endif 00096 QP_STRONG_BRANCHING, 00097 LP_STRONG_BRANCHING, 00098 NLP_STRONG_BRANCHING, 00099 OSI_SIMPLE, 00100 OSI_STRONG, 00101 RANDOM 00102 }; 00103 00105 enum IntParameter{ 00106 BabLogLevel = 0 , 00107 BabLogInterval, 00108 MaxFailures , 00109 FailureBehavior , 00110 MaxInfeasible , 00112 NumberStrong , 00113 MinReliability , 00114 MaxNodes , 00115 MaxSolutions , 00116 MaxIterations , 00117 SpecialOption , 00118 DisableSos , 00119 NumCutPasses, 00120 NumCutPassesAtRoot, 00121 RootLogLevel, 00122 NumberIntParam 00123 }; 00124 00125 00127 enum DoubleParameter{ 00128 CutoffDecr = 0 , 00129 Cutoff , 00130 AllowableGap , 00131 AllowableFractionGap , 00132 IntTol , 00133 MaxTime , 00134 NumberDoubleParam 00135 }; 00136 00138 BabSetupBase(const CoinMessageHandler * handler = NULL); 00139 00141 BabSetupBase(Ipopt::SmartPtr<TMINLP> tminlp, const CoinMessageHandler * handler = NULL); 00143 BabSetupBase(Ipopt::SmartPtr<TNLPSolver> app); 00145 BabSetupBase(const OsiTMINLPInterface& nlp); 00147 BabSetupBase(const BabSetupBase &setup, 00148 OsiTMINLPInterface &nlp); 00149 00151 BabSetupBase(const BabSetupBase &setup, 00152 OsiTMINLPInterface &nlp, 00153 const std::string &prefix); 00154 00156 BabSetupBase(const BabSetupBase & other); 00157 00159 virtual BabSetupBase * clone() const = 0; 00160 00162 virtual BabSetupBase *clone(OsiTMINLPInterface&nlp)const; 00164 virtual ~BabSetupBase(); 00165 00169 void use(const OsiTMINLPInterface& nlp); 00171 void use(Ipopt::SmartPtr<TMINLP> tminlp ); 00173 void use(Ipopt::SmartPtr<TMINLP2TNLP> prob); 00175 void setNonlinearSolver(OsiTMINLPInterface * s) 00176 { 00177 nonlinearSolver_ = s; 00178 } 00184 virtual void registerOptions(); 00186 virtual void setBabDefaultOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions) 00187 {} 00189 static void registerAllOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions); 00190 00192 virtual void readOptionsFile() 00193 { 00194 if (readOptions_) return; 00195 readOptionsFile("bonmin.opt"); 00196 } 00197 00199 void readOptionsFile(std::string fileName); 00200 00202 void readOptionsString(std::string opt_string); 00203 00205 void readOptionsStream(std::istream& is); 00206 00208 void mayPrintDoc(); 00209 00210 00212 const char * prefix() const { 00213 return prefix_.c_str(); 00214 } 00215 00217 void setOptionsAndJournalist(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions, 00218 Ipopt::SmartPtr<Ipopt::OptionsList> options, 00219 Ipopt::SmartPtr<Ipopt::Journalist> journalist) 00220 { 00221 options_ = options; 00222 roptions_ = roptions; 00223 journalist_ = journalist; 00224 } 00225 00227 void initializeOptionsAndJournalist(); 00233 OsiTMINLPInterface * nonlinearSolver() 00234 { 00235 return nonlinearSolver_; 00236 } 00238 OsiSolverInterface * continuousSolver() 00239 { 00240 return continuousSolver_; 00241 } 00243 CuttingMethods& cutGenerators() 00244 { 00245 return cutGenerators_; 00246 } 00248 HeuristicMethods& heuristics() 00249 { 00250 return heuristics_; 00251 } 00253 OsiChooseVariable * branchingMethod() 00254 { 00255 return branchingMethod_; 00256 } 00258 NodeComparison& nodeComparisonMethod() 00259 { 00260 return nodeComparisonMethod_; 00261 } 00263 TreeTraversal treeTraversalMethod() 00264 { 00265 return treeTraversalMethod_; 00266 } 00268 int getIntParameter(const IntParameter &p) const 00269 { 00270 return intParam_[p]; 00271 } 00273 double getDoubleParameter(const DoubleParameter &p) const 00274 { 00275 return doubleParam_[p]; 00276 } 00278 void setIntParameter(const IntParameter &p, const int v) 00279 { 00280 intParam_[p] = v; 00281 } 00283 void setDoubleParameter(const DoubleParameter &p, const double v) 00284 { 00285 doubleParam_[p] = v; 00286 } 00290 void gatherParametersValues() 00291 { 00292 gatherParametersValues(options_); 00293 } 00295 void gatherParametersValues(Ipopt::SmartPtr<Ipopt::OptionsList> options); 00297 Ipopt::SmartPtr<Ipopt::Journalist> journalist() 00298 { 00299 return journalist_; 00300 } 00301 00303 Ipopt::SmartPtr<Ipopt::OptionsList> options() 00304 { 00305 return options_; 00306 } 00307 00309 Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions() 00310 { 00311 return roptions_; 00312 } 00313 00315 const vector<OsiObject *>& objects() const 00316 { 00317 return objects_; 00318 } 00319 00321 vector<OsiObject *>& objects() 00322 { 00323 return objects_; 00324 } 00325 00326 void addCutGenerator(CuttingMethod & cg){ 00327 cutGenerators_.push_back(cg); 00328 } 00329 00330 void set_linearizer(TMINLP2OsiLP * linearizer){ 00331 linearizer_ = linearizer; 00332 } 00333 00334 protected: 00336 void setPriorities(); 00338 void addSos(); 00339 00341 int intParam_[NumberIntParam]; 00343 static int defaultIntParam_[NumberIntParam]; 00345 double doubleParam_[NumberDoubleParam]; 00347 static double defaultDoubleParam_[NumberDoubleParam]; 00349 OsiTMINLPInterface * nonlinearSolver_; 00351 OsiSolverInterface * continuousSolver_; 00353 Ipopt::SmartPtr<TMINLP2OsiLP> linearizer_; 00355 CuttingMethods cutGenerators_; 00357 HeuristicMethods heuristics_; 00359 OsiChooseVariable * branchingMethod_; 00361 NodeComparison nodeComparisonMethod_; 00363 TreeTraversal treeTraversalMethod_; 00365 vector<OsiObject *> objects_; 00366 00367 00369 Ipopt::SmartPtr<Ipopt::Journalist> journalist_; 00370 00372 Ipopt::SmartPtr<Ipopt::OptionsList> options_; 00373 00375 Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions_; 00376 00378 bool readOptions_; 00380 CoinMessageHandler * messageHandler_; 00382 std::string prefix_; 00383 }; 00384 }/* End namespace Bonmin. */ 00385 #endif 00386