00001
00002
00003
00004
00005
00006
00007
00008
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 bool always;
00034 CuttingMethod():
00035 atSolution(false),
00036 normal(true),
00037 always(false)
00038 {}
00039
00040 CuttingMethod(const CuttingMethod & other):
00041 frequency(other.frequency),
00042 id(other.id),
00043 cgl(other.cgl),
00044 atSolution(other.atSolution),
00045 normal(other.normal),
00046 always(other.always)
00047 {}
00048 };
00050 struct HeuristicMethod
00051 {
00052 std::string id;
00053 CbcHeuristic* heuristic;
00054 HeuristicMethod()
00055 {}
00056
00057 HeuristicMethod(const HeuristicMethod & other):
00058 id(other.id),
00059 heuristic(other.heuristic)
00060 {}
00061 };
00062 typedef std::list<CuttingMethod> CuttingMethods;
00063 typedef std::list<HeuristicMethod > HeuristicMethods;
00064
00066 enum NodeComparison {
00067 bestBound = 0 ,
00068 DFS ,
00069 BFS ,
00070 dynamic ,
00072 bestGuess
00073 };
00074
00076 enum TreeTraversal {
00077 HeapOnly=0 ,
00078 DiveFromBest ,
00079 ProbedDive ,
00080 DfsDiveFromBest ,
00081 DfsDiveDynamic
00082 };
00083
00084
00086 enum VarSelectStra_Enum {
00087 MOST_FRACTIONAL=0,
00088 STRONG_BRANCHING,
00089 RELIABILITY_BRANCHING,
00090 #ifdef BONMIN_CURVATURE_BRANCHING
00091 CURVATURE_ESTIMATOR,
00092 #endif
00093 QP_STRONG_BRANCHING,
00094 LP_STRONG_BRANCHING,
00095 NLP_STRONG_BRANCHING,
00096 OSI_SIMPLE,
00097 OSI_STRONG,
00098 RANDOM
00099 };
00100
00102 enum IntParameter{
00103 BabLogLevel = 0 ,
00104 BabLogInterval,
00105 MaxFailures ,
00106 FailureBehavior ,
00107 MaxInfeasible ,
00109 NumberStrong ,
00110 MinReliability ,
00111 MaxNodes ,
00112 MaxSolutions ,
00113 MaxIterations ,
00114 SpecialOption ,
00115 DisableSos ,
00116 NumCutPasses,
00117 NumCutPassesAtRoot,
00118 RootLogLevel,
00119 NumberIntParam
00120 };
00121
00122
00124 enum DoubleParameter{
00125 CutoffDecr = 0 ,
00126 Cutoff ,
00127 AllowableGap ,
00128 AllowableFractionGap ,
00129 IntTol ,
00130 MaxTime ,
00131 NumberDoubleParam
00132 };
00133
00135 BabSetupBase(const CoinMessageHandler * handler = NULL);
00136
00138 BabSetupBase(Ipopt::SmartPtr<TMINLP> tminlp, const CoinMessageHandler * handler = NULL);
00140 BabSetupBase(Ipopt::SmartPtr<TNLPSolver> app);
00142 BabSetupBase(const OsiTMINLPInterface& nlp);
00144 BabSetupBase(const BabSetupBase &setup,
00145 OsiTMINLPInterface &nlp);
00146
00148 BabSetupBase(const BabSetupBase &setup,
00149 OsiTMINLPInterface &nlp,
00150 const std::string &prefix);
00151
00153 BabSetupBase(const BabSetupBase & other);
00154
00156 virtual BabSetupBase * clone() const = 0;
00157
00159 virtual BabSetupBase *clone(OsiTMINLPInterface&nlp)const;
00161 virtual ~BabSetupBase();
00162
00166 void use(const OsiTMINLPInterface& nlp);
00168 void use(Ipopt::SmartPtr<TMINLP> tminlp );
00170 void use(Ipopt::SmartPtr<TMINLP2TNLP> prob);
00172 void setNonlinearSolver(OsiTMINLPInterface * s)
00173 {
00174 nonlinearSolver_ = s;
00175 }
00181 virtual void registerOptions();
00183 virtual void setBabDefaultOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
00184 {}
00186 static void registerAllOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
00187
00189 virtual void readOptionsFile()
00190 {
00191 if (readOptions_) return;
00192 readOptionsFile("bonmin.opt");
00193 }
00194
00196 void readOptionsFile(std::string fileName);
00197
00199 void readOptionsString(std::string opt_string);
00200
00202 void readOptionsStream(std::istream& is);
00203
00205 void mayPrintDoc();
00206
00207
00209 const char * prefix() const {
00210 return prefix_.c_str();
00211 }
00212
00214 void setOptionsAndJournalist(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
00215 Ipopt::SmartPtr<Ipopt::OptionsList> options,
00216 Ipopt::SmartPtr<Ipopt::Journalist> journalist)
00217 {
00218 options_ = options;
00219 roptions_ = roptions;
00220 journalist_ = journalist;
00221 }
00222
00224 void initializeOptionsAndJournalist();
00230 OsiTMINLPInterface * nonlinearSolver()
00231 {
00232 return nonlinearSolver_;
00233 }
00235 OsiSolverInterface * continuousSolver()
00236 {
00237 return continuousSolver_;
00238 }
00240 CuttingMethods& cutGenerators()
00241 {
00242 return cutGenerators_;
00243 }
00245 HeuristicMethods& heuristics()
00246 {
00247 return heuristics_;
00248 }
00250 OsiChooseVariable * branchingMethod()
00251 {
00252 return branchingMethod_;
00253 }
00255 NodeComparison& nodeComparisonMethod()
00256 {
00257 return nodeComparisonMethod_;
00258 }
00260 TreeTraversal treeTraversalMethod()
00261 {
00262 return treeTraversalMethod_;
00263 }
00265 int getIntParameter(const IntParameter &p) const
00266 {
00267 return intParam_[p];
00268 }
00270 double getDoubleParameter(const DoubleParameter &p) const
00271 {
00272 return doubleParam_[p];
00273 }
00275 void setIntParameter(const IntParameter &p, const int v)
00276 {
00277 intParam_[p] = v;
00278 }
00280 void setDoubleParameter(const DoubleParameter &p, const double v)
00281 {
00282 doubleParam_[p] = v;
00283 }
00287 void gatherParametersValues()
00288 {
00289 gatherParametersValues(options_);
00290 }
00292 void gatherParametersValues(Ipopt::SmartPtr<Ipopt::OptionsList> options);
00294 Ipopt::SmartPtr<Ipopt::Journalist> journalist()
00295 {
00296 return journalist_;
00297 }
00298
00300 Ipopt::SmartPtr<Ipopt::OptionsList> options()
00301 {
00302 return options_;
00303 }
00304
00306 Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions()
00307 {
00308 return roptions_;
00309 }
00310
00312 const vector<OsiObject *>& objects() const
00313 {
00314 return objects_;
00315 }
00316
00318 vector<OsiObject *>& objects()
00319 {
00320 return objects_;
00321 }
00322
00323 void addCutGenerator(CuttingMethod & cg){
00324 cutGenerators_.push_back(cg);
00325 }
00326 protected:
00328 void setPriorities();
00330 void addSos();
00331
00333 int intParam_[NumberIntParam];
00335 static int defaultIntParam_[NumberIntParam];
00337 double doubleParam_[NumberDoubleParam];
00339 static double defaultDoubleParam_[NumberDoubleParam];
00341 OsiTMINLPInterface * nonlinearSolver_;
00343 OsiSolverInterface * continuousSolver_;
00345 CuttingMethods cutGenerators_;
00347 HeuristicMethods heuristics_;
00349 OsiChooseVariable * branchingMethod_;
00351 NodeComparison nodeComparisonMethod_;
00353 TreeTraversal treeTraversalMethod_;
00355 vector<OsiObject *> objects_;
00356
00357
00359 Ipopt::SmartPtr<Ipopt::Journalist> journalist_;
00360
00362 Ipopt::SmartPtr<Ipopt::OptionsList> options_;
00363
00365 Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions_;
00366
00368 bool readOptions_;
00370 CoinMessageHandler * messageHandler_;
00372 std::string prefix_;
00373 };
00374 }
00375 #endif
00376