Bonmin  1.8.8
BonBabSetupBase.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 04/12/2007
9 
10 #ifndef BabSetupBase_H
11 #define BabSetupBase_H
12 
13 #include <string>
14 #include <list>
15 #include "CglCutGenerator.hpp"
16 #include "CbcHeuristic.hpp"
17 #include "OsiChooseVariable.hpp"
19 #include "IpSmartPtr.hpp"
20 #include "BonTMINLP2OsiLP.hpp"
21 
22 namespace Bonmin
23 {
26  {
27  public:
29  struct CuttingMethod
30  {
31  int frequency;
32  std::string id;
34  bool atSolution;
35  bool normal;
36  bool always;
38  atSolution(false),
39  normal(true),
40  always(false)
41  {}
42 
43  CuttingMethod(const CuttingMethod & other):
44  frequency(other.frequency),
45  id(other.id),
46  cgl(other.cgl),
47  atSolution(other.atSolution),
48  normal(other.normal),
49  always(other.always)
50  {}
51  };
54  {
55  std::string id;
56  CbcHeuristic* heuristic;
58  {}
59 
61  id(other.id),
62  heuristic(other.heuristic)
63  {}
64  };
65  typedef std::list<CuttingMethod> CuttingMethods;
66  typedef std::list<HeuristicMethod > HeuristicMethods;
67 
70  bestBound = 0 ,
71  DFS ,
72  BFS ,
73  dynamic ,
75  bestGuess
76  };
77 
85  };
86 
87 
93 #ifdef BONMIN_CURVATURE_BRANCHING
94  CURVATURE_ESTIMATOR,
95 #endif
101  RANDOM
102  };
103 
110  MaxInfeasible ,
123  };
124 
125 
135  };
136 
138  BabSetupBase(const CoinMessageHandler * handler = NULL);
139 
141  BabSetupBase(Ipopt::SmartPtr<TMINLP> tminlp, const CoinMessageHandler * handler = NULL);
148  OsiTMINLPInterface &nlp);
149 
152  OsiTMINLPInterface &nlp,
153  const std::string &prefix);
154 
156  BabSetupBase(const BabSetupBase & other);
157 
159  virtual BabSetupBase * clone() const = 0;
160 
164  virtual ~BabSetupBase();
165 
169  void use(const OsiTMINLPInterface& nlp);
176  {
177  nonlinearSolver_ = s;
178  }
184  virtual void registerOptions();
187  {}
190 
192  virtual void readOptionsFile()
193  {
194  if (readOptions_) return;
195  readOptionsFile("bonmin.opt");
196  }
197 
199  void readOptionsFile(std::string fileName);
200 
202  void readOptionsString(std::string opt_string);
203 
205  void readOptionsStream(std::istream& is);
206 
208  void mayPrintDoc();
209 
210 
212  const char * prefix() const {
213  return prefix_.c_str();
214  }
215 
220  {
221  options_ = options;
224  }
225 
234  {
235  return nonlinearSolver_;
236  }
239  {
240  return continuousSolver_;
241  }
244  {
245  return cutGenerators_;
246  }
249  {
250  return heuristics_;
251  }
254  {
255  return branchingMethod_;
256  }
259  {
260  return nodeComparisonMethod_;
261  }
264  {
265  return treeTraversalMethod_;
266  }
268  int getIntParameter(const IntParameter &p) const
269  {
270  return intParam_[p];
271  }
273  double getDoubleParameter(const DoubleParameter &p) const
274  {
275  return doubleParam_[p];
276  }
278  void setIntParameter(const IntParameter &p, const int v)
279  {
280  intParam_[p] = v;
281  }
283  void setDoubleParameter(const DoubleParameter &p, const double v)
284  {
285  doubleParam_[p] = v;
286  }
291  {
293  }
298  {
299  return journalist_;
300  }
301 
304  {
305  return options_;
306  }
307 
310  {
311  return roptions_;
312  }
313 
316  {
317  return objects_;
318  }
319 
322  {
323  return objects_;
324  }
325 
327  cutGenerators_.push_back(cg);
328  }
329 
330  void set_linearizer(TMINLP2OsiLP * linearizer){
331  linearizer_ = linearizer;
332  }
333 
334  protected:
338  void addSos();
339 
366 
367 
370 
373 
376 
382  std::string prefix_;
383  };
384 }/* End namespace Bonmin. */
385 #endif
386 
A class to have all elements necessary to setup a branch-and-bound.
void gatherParametersValues()
Get the values of base parameters from the options stored.
HeuristicMethods & heuristics()
list of Heuristic methods to use.
virtual void readOptionsFile()
Get the options from default text file (bonmin.opt) if don't already have them.
OsiChooseVariable * branchingMethod_
Branching method.
void mayPrintDoc()
May print documentation of options if options print_options_documentation is set to yes.
void setPriorities()
Set the priorities into OsiTMINLPInterface when needed.
CuttingMethods cutGenerators_
Cut generation methods.
static double defaultDoubleParam_[NumberDoubleParam]
default values for double parameters.
vector< OsiObject * > objects_
Extra object to add to Cbc (not OsiObjects).
void initializeOptionsAndJournalist()
Initialize the options and the journalist.
void readOptionsStream(std::istream &is)
Get the options from stream.
BabSetupBase(const BabSetupBase &setup, OsiTMINLPInterface &nlp, const std::string &prefix)
Copy but uses an other nlp.
BabSetupBase(const OsiTMINLPInterface &nlp)
Construct from existing TMINLP interface.
OsiSolverInterface * continuousSolver()
Pointer to the continuous solver to use for relaxations.
TreeTraversal treeTraversalMethod_
Tree traversal method.
double getDoubleParameter(const DoubleParameter &p) const
Return value of double parameter.
BabSetupBase(const CoinMessageHandler *handler=NULL)
Default constructor.
OsiTMINLPInterface * nonlinearSolver_
Storage of the non-linear solver used.
void readOptionsFile(std::string fileName)
Get the options from given fileName.
BabSetupBase(Ipopt::SmartPtr< TNLPSolver > app)
Construct from existing application.
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Acces storage of Journalist for output.
std::string prefix_
Prefix to use when reading options.
int getIntParameter(const IntParameter &p) const
Return value of integer parameter.
const vector< OsiObject * > & objects() const
Access to extra objects.
BabSetupBase(Ipopt::SmartPtr< TMINLP > tminlp, const CoinMessageHandler *handler=NULL)
Construct from existing tminlp.
void use(Ipopt::SmartPtr< TMINLP > tminlp)
Read options (if not done before) and create interface using tminlp.
OsiChooseVariable * branchingMethod()
branching method to use.
void setNonlinearSolver(OsiTMINLPInterface *s)
Set the non-linear solver used.
void set_linearizer(TMINLP2OsiLP *linearizer)
CuttingMethods & cutGenerators()
list of cutting planes methods to apply with their frequencies.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
void gatherParametersValues(Ipopt::SmartPtr< Ipopt::OptionsList > options)
Get the values of the base parameters from the passed options.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Access registered Options.
bool readOptions_
flag to say if option file was read.
BabSetupBase(const BabSetupBase &setup, OsiTMINLPInterface &nlp)
Copy but uses an other nlp.
virtual BabSetupBase * clone(OsiTMINLPInterface &nlp) const
Make a copy with solver replace by one passed .
NodeComparison nodeComparisonMethod_
Node comparison method.
OsiSolverInterface * continuousSolver_
Storage of continuous solver.
HeuristicMethods heuristics_
Heuristic methods.
OsiTMINLPInterface * nonlinearSolver()
Pointer to the non-linear solver used.
void addSos()
Add SOS constraints to OsiTMINLPInterface when needed.
Ipopt::SmartPtr< TMINLP2OsiLP > linearizer_
Method to linearize MINLPs.
NodeComparison
Strategies for comparing the nodes on the heap.
@ BFS
Best First Search.
@ dynamic
Dynamic strategy, see CbcBranchActual.hpp for explanations.
@ bestGuess
Best guessed integer solution is subtree below, based on pseudo costs.
@ DFS
Depth First Search.
virtual void setBabDefaultOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Setup the defaults options for this algorithm.
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
int intParam_[NumberIntParam]
storage of integer parameters.
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
static void registerAllOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register all the options for this algorithm instance.
void addCutGenerator(CuttingMethod &cg)
void use(Ipopt::SmartPtr< TMINLP2TNLP > prob)
use specific instanciation of a TMINLP2TNLP.
void setOptionsAndJournalist(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist)
Set the value for options, output...
void use(const OsiTMINLPInterface &nlp)
use existing TMINLP interface (containing the options).
IntParameter
Parameters represented by an integer.
@ MinReliability
Minimum reliability before trust pseudo-costs.
@ RootLogLevel
Log level for root relaxation.
@ DisableSos
Consider or not SOS constraints.
@ MaxFailures
Max number of failures in a branch.
@ MaxInfeasible
Max number of consecutive infeasible problem in a branch before fathoming.
@ MaxIterations
Global iteration limit.
@ NumCutPassesAtRoot
Number of cut passes at nodes.
@ MaxSolutions
limit on number of integer feasible solution.
@ SpecialOption
Spetial option in particular for Cbc.
@ NumberIntParam
Dummy end to size table.
@ MaxNodes
Global node limit.
@ BabLogInterval
Display information every logIntervval nodes.
@ FailureBehavior
Behavior of the algorithm in the case of a failure.
@ NumberStrong
Number of candidates for strong branching.
@ NumCutPasses
Number of cut passes at nodes.
DoubleParameter
Parameters represented by a double.
@ NumberDoubleParam
Dummy end to size table.
@ IntTol
Integer tolerance.
@ MaxTime
Global time limit.
@ AllowableGap
Stop if absolute gap is less than this.
@ AllowableFractionGap
Stop if relative gap is less than this.
std::list< HeuristicMethod > HeuristicMethods
virtual void registerOptions()
Register all the options for this algorithm instance.
BabSetupBase(const BabSetupBase &other)
Copy constructor.
virtual ~BabSetupBase()
Virtual destructor.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
TreeTraversal treeTraversalMethod()
Method used to traverse tree.
const char * prefix() const
Get prefix to use for options.
double doubleParam_[NumberDoubleParam]
storage of double parameters.
std::list< CuttingMethod > CuttingMethods
vector< OsiObject * > & objects()
Access to extra objects.
NodeComparison & nodeComparisonMethod()
Method used to compare nodes.
CoinMessageHandler * messageHandler_
separate message handler.
void readOptionsString(std::string opt_string)
Get the options from long string containing all.
TreeTraversal
Strategies for traversing the tree.
@ DfsDiveFromBest
dive from top node of the heap with more elaborate strategy (see options doc).
@ DiveFromBest
dive from top node of the heap untill it gets to a leaf of the tree.
@ ProbedDive
Eplore two kids before following on dive.
@ DfsDiveDynamic
Same as DfsDiveFromBest, but after a prescribed number of integer solution are found switch to best-b...
static int defaultIntParam_[NumberIntParam]
default values for int parameters.
virtual BabSetupBase * clone() const =0
virtual copy constructor.
void setDoubleParameter(const DoubleParameter &p, const double v)
Return value of double parameter.
void setIntParameter(const IntParameter &p, const int v)
Return value of integer parameter.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
A transformer class to build outer approximations i.e.
(C) Copyright International Business Machines Corporation 2007
Type for cut generation method with its frequency and string identification.
CuttingMethod(const CuttingMethod &other)
Type for heuristic method with its string identification.
HeuristicMethod(const HeuristicMethod &other)