BonBabSetupBase.cpp
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 #include "BonminConfig.h"
11 #ifdef COIN_HAS_FILTERSQP
12 # include "BonFilterSolver.hpp"
13 #endif
14 #include "BonBabSetupBase.hpp"
15 #include <climits>
16 #include <fstream>
17 #include <sstream>
18 
19 #include "BonDiver.hpp"
20 #include "BonQpBranchingSolver.hpp"
21 #include "BonLpBranchingSolver.hpp"
22 #include "BonChooseVariable.hpp"
23 #include "BonTMINLP2Quad.hpp"
24 #include "BonTMINLPLinObj.hpp"
25 namespace Bonmin
26 {
28  1 /* BabLogLevel*/,
29  100 /* BabLogInterval*/,
30  2 /* MaxFailures.*/,
31  0 /* FailureBehavior.*/,
32  0 /* MaxInfeasible*/,
33  5 /*NumberStrong*/,
34  2 /* MinReliability*/,
35  COIN_INT_MAX /* MaxNodes*/,
36  COIN_INT_MAX /* MaxSolutions*/,
37  COIN_INT_MAX /* MaxIterations*/,
38  0 /* SpecialOption*/,
39  0 /* DisableSos.*/,
40  1 /* numCutPasses.*/,
41  20 /* numCutPassesAtRoot.*/,
42  0 /* log level at root.*/
43  };
44 
45 
47  0 /* CutoffDecr*/,
48  COIN_DBL_MAX /* Cutoff*/,
49  0 /* AllowableGap*/,
50  0 /*AllowableFractionGap*/,
51  1e-09 /*IntTol*/,
52  COIN_DBL_MAX /* MaxTime*/,
53  };
54 
55  BabSetupBase::BabSetupBase(const CoinMessageHandler * handler):
56  nonlinearSolver_(NULL),
57  continuousSolver_(NULL),
58  linearizer_(NULL),
59  cutGenerators_(),
60  heuristics_(),
61  branchingMethod_(NULL),
62  nodeComparisonMethod_(),
63  treeTraversalMethod_(),
64  objects_(0),
65  journalist_(NULL),
66  options_(NULL),
67  roptions_(NULL),
68  readOptions_(false),
69  messageHandler_(NULL),
70  prefix_("bonmin.")
71  {
74  if(handler) messageHandler_ = handler->clone();
75  }
76 
79  nonlinearSolver_(NULL),
80  continuousSolver_(NULL),
81  linearizer_(other.linearizer_),
82  cutGenerators_(),
83  heuristics_(),
84  branchingMethod_(NULL),
85  nodeComparisonMethod_(other.nodeComparisonMethod_),
86  treeTraversalMethod_(other.treeTraversalMethod_),
87  objects_(other.objects_),
88  journalist_(other.journalist_),
89  options_(NULL),
90  roptions_(other.roptions_),
91  readOptions_(other.readOptions_),
92  messageHandler_(NULL),
93  prefix_(other.prefix_)
94  {
95  if (other.nonlinearSolver_) {
96  nonlinearSolver_ = static_cast<OsiTMINLPInterface *>(other.nonlinearSolver_->clone());
97  }
98  if (other.continuousSolver_) {
99  continuousSolver_ = other.continuousSolver_->clone();
100  }
101  if (other.messageHandler_) {
102  messageHandler_ = other.messageHandler_->clone();
103  continuousSolver_->passInMessageHandler(messageHandler_);
104  }
105  for (CuttingMethods::const_iterator i = other.cutGenerators_.begin() ; i != other.cutGenerators_.end() ; i++) {
106  cutGenerators_.push_back(*i);
107  cutGenerators_.back().cgl = cutGenerators_.back().cgl->clone();
108  }
109 
110  for (HeuristicMethods::iterator i = heuristics_.begin() ; i != heuristics_.end() ; i++) {
111  heuristics_.push_back(*i);
112  heuristics_.back().heuristic = i->heuristic->clone();
113  }
114 
115  if(other.branchingMethod_ != NULL)
116  branchingMethod_ = other.branchingMethod_->clone();
117  if (IsValid(other.options_)) {
118  options_ = new Ipopt::OptionsList;
119  *options_ = *other.options_;
120  }
121  CoinCopyN(other.intParam_, NumberIntParam, intParam_);
122  CoinCopyN(other.doubleParam_, NumberDoubleParam, doubleParam_);
123  for (unsigned int i = 0 ; i < objects_.size() ; i++) {
124  objects_[i]->clone();
125  }
126  }
127 
130  OsiTMINLPInterface &nlp):
131  nonlinearSolver_(NULL),
132  continuousSolver_(NULL),
133  linearizer_(other.linearizer_),
134  cutGenerators_(),
135  heuristics_(),
136  branchingMethod_(NULL),
137  nodeComparisonMethod_(other.nodeComparisonMethod_),
138  treeTraversalMethod_(other.treeTraversalMethod_),
139  objects_(other.objects_),
140  journalist_(other.journalist_),
141  options_(NULL),
142  roptions_(other.roptions_),
143  readOptions_(other.readOptions_),
144  messageHandler_(NULL),
145  prefix_(other.prefix_)
146  {
147  nonlinearSolver_ = &nlp;
148  if (other.continuousSolver_ != other.nonlinearSolver_) {
149  continuousSolver_ = NULL;
150  }
151  else
153  if (other.messageHandler_) {
154  messageHandler_ = other.messageHandler_->clone();
155  continuousSolver_->passInMessageHandler(messageHandler_);
156  }
157  for (CuttingMethods::const_iterator i = other.cutGenerators_.begin() ; i != other.cutGenerators_.end() ; i++) {
158  cutGenerators_.push_back(*i);
159  cutGenerators_.back().cgl = cutGenerators_.back().cgl->clone();
160  }
161 
162  for (HeuristicMethods::iterator i = heuristics_.begin() ; i != heuristics_.end() ; i++) {
163  heuristics_.push_back(*i);
164  heuristics_.back().heuristic = i->heuristic->clone();
165  }
166 
167  if(other.branchingMethod_ != NULL)
168  branchingMethod_ = other.branchingMethod_->clone();
169  if (IsValid(other.options_)) {
170  options_ = new Ipopt::OptionsList;
171  *options_ = *other.options_;
172  }
173  CoinCopyN(other.intParam_, NumberIntParam, intParam_);
174  CoinCopyN(other.doubleParam_, NumberDoubleParam, doubleParam_);
175  for (unsigned int i = 0 ; i < objects_.size() ; i++) {
176  objects_[i]->clone();
177  }
178  }
181  OsiTMINLPInterface &nlp,
182  const std::string & prefix):
183  nonlinearSolver_(other.nonlinearSolver_),
184  continuousSolver_(NULL),
185  linearizer_(other.linearizer_),
186  cutGenerators_(),
187  heuristics_(),
188  branchingMethod_(NULL),
189  nodeComparisonMethod_(),
190  treeTraversalMethod_(),
191  objects_(other.objects_),
192  journalist_(other.journalist_),
193  options_(NULL),
194  roptions_(other.roptions_),
195  readOptions_(other.readOptions_),
196  messageHandler_(NULL),
197  prefix_(prefix)
198  {
199  nonlinearSolver_ = &nlp;
200  if (IsValid(other.options_)) {
201  options_ = new Ipopt::OptionsList;
202  *options_ = *other.options_;
203  }
204  if (other.messageHandler_) {
205  messageHandler_ = other.messageHandler_->clone();
206  nonlinearSolver_->passInMessageHandler(messageHandler_);
207  }
211  for (unsigned int i = 0 ; i < objects_.size() ; i++) {
212  objects_[i]->clone();
213  }
214  }
215 
216  BabSetupBase::BabSetupBase(Ipopt::SmartPtr<TMINLP> tminlp, const CoinMessageHandler * handler):
217  nonlinearSolver_(NULL),
218  continuousSolver_(NULL),
219  linearizer_(NULL),
220  cutGenerators_(),
221  heuristics_(),
222  branchingMethod_(NULL),
223  nodeComparisonMethod_(),
224  treeTraversalMethod_(),
225  objects_(0),
226  readOptions_(false),
227  messageHandler_(NULL),
228  prefix_("bonmin.")
229  {
232  if(handler) messageHandler_ = handler->clone();
233  use(tminlp);
234  }
235 
236 
238  BabSetupBase *
240  throw(CoinError("BabSetupBase", "CloneWithOtherNlp","Not implemented"));
241  }
242 
243 
244  void
246  {
247  readOptionsFile();
248  assert(IsValid(tminlp));
250  int ival;
251  options_->GetEnumValue("enable_dynamic_nlp", ival, "bonmin.");
252  if(ival && ! tminlp->hasLinearObjective()){
255  linObj->setTminlp(GetRawPtr(tminlp));
256  tminlp = GetRawPtr(linObj);
257  }
259  if(messageHandler_ != NULL)
260  nonlinearSolver_->passInMessageHandler(messageHandler_);
261  else
262  messageHandler_ = nonlinearSolver_->messageHandler()->clone();
263  if (ival){
265  }
266  }
267 
269  nonlinearSolver_(NULL),
270  continuousSolver_(NULL),
271  linearizer_(NULL),
272  cutGenerators_(),
273  heuristics_(),
274  branchingMethod_(NULL),
275  nodeComparisonMethod_(),
276  treeTraversalMethod_(),
277  objects_(0),
278  journalist_(NULL),
279  options_(NULL),
280  roptions_(NULL),
281  readOptions_(false),
282  messageHandler_(NULL),
283  prefix_("bonmin.")
284  {
287  use(nlp);
288  }
289 
290  void
292  {
293  nonlinearSolver_ = dynamic_cast<OsiTMINLPInterface *>(nlp.clone());
297  if(messageHandler_ != NULL ) delete messageHandler_;
298  messageHandler_ = nlp.messageHandler()->clone();
299  readOptions_ = true;
300  }
301 
303  nonlinearSolver_(NULL),
304  continuousSolver_(NULL),
305  linearizer_(NULL),
306  cutGenerators_(),
307  heuristics_(),
308  branchingMethod_(NULL),
309  nodeComparisonMethod_(),
310  treeTraversalMethod_(),
311  objects_(0),
312  journalist_(app->journalist()),
313  options_(app->options()),
314  roptions_(app->roptions()),
315  readOptions_(true),
316  messageHandler_(NULL),
317  prefix_("bonmin.")
318  {
321  }
322 
323 
325  {
327  delete nonlinearSolver_;
328  }
329  delete continuousSolver_;
330  delete branchingMethod_;
331  for (CuttingMethods::iterator i = cutGenerators_.begin() ; i != cutGenerators_.end() ; i++) {
332  delete i->cgl;
333  i->cgl = NULL;
334  }
335 
336  for (HeuristicMethods::iterator i = heuristics_.begin() ; i != heuristics_.end() ; i++) {
337  delete i->heuristic;
338  }
339 
340  for (unsigned int i = 0 ; i < objects_.size() ; i++) {
341  delete objects_[i];
342  }
343 
344  if(messageHandler_)
345  delete messageHandler_;
346  }
347 
348 
349  void
351  {
352 
353  options->GetIntegerValue("bb_log_level",intParam_[BabLogLevel],prefix_.c_str());
354  options->GetIntegerValue("bb_log_interval",intParam_[BabLogInterval],prefix_.c_str());
355  options->GetIntegerValue("max_consecutive_failures",intParam_[MaxFailures],prefix_.c_str());
356  options->GetEnumValue("nlp_failure_behavior",intParam_[FailureBehavior],prefix_.c_str());
357  options->GetIntegerValue("max_consecutive_infeasible",intParam_[MaxInfeasible],prefix_.c_str());
358  options->GetIntegerValue("number_strong_branch",intParam_[NumberStrong],prefix_.c_str());
359  options->GetIntegerValue("number_before_trust",intParam_[MinReliability],prefix_.c_str());
360  options->GetIntegerValue("node_limit",intParam_[MaxNodes],prefix_.c_str());
361  options->GetIntegerValue("solution_limit",intParam_[MaxSolutions],prefix_.c_str());
362  options->GetIntegerValue("iteration_limit",intParam_[MaxIterations],prefix_.c_str());
363  options->GetEnumValue("sos_constraints",intParam_[DisableSos],prefix_.c_str());
364  options->GetIntegerValue("num_cut_passes",intParam_[NumCutPasses],prefix_.c_str());
365  options->GetIntegerValue("num_cut_passes_at_root",intParam_[NumCutPassesAtRoot],prefix_.c_str());
366  options->GetIntegerValue("nlp_log_at_root",intParam_[RootLogLevel],prefix_.c_str());
367 
368  options->GetNumericValue("cutoff_decr",doubleParam_[CutoffDecr],prefix_.c_str());
369  options->GetNumericValue("cutoff",doubleParam_[Cutoff],prefix_.c_str());
370  options->GetNumericValue("allowable_gap",doubleParam_[AllowableGap],prefix_.c_str());
371  options->GetNumericValue("allowable_fraction_gap",doubleParam_[AllowableFractionGap],prefix_.c_str());
372  options->GetNumericValue("integer_tolerance",doubleParam_[IntTol],prefix_.c_str());
373  options->GetNumericValue("time_limit", doubleParam_[MaxTime],prefix_.c_str());
374 
375  int ival;
376  int seed = 0;
377  ival = options->GetIntegerValue("random_generator_seed",seed,prefix_.c_str());
378  if(seed == -1)
379  CoinSeedRandom((int)CoinGetTimeOfDay());
380  else if (ival != 0) CoinSeedRandom(seed);
381 
382  options->GetEnumValue("node_comparison",ival,prefix_.c_str());
384 
385  options->GetEnumValue("tree_search_strategy", ival, prefix_.c_str());
387 
388  int varSelection;
389  options->GetEnumValue("variable_selection",varSelection,prefix_.c_str());
390  // Set branching strategy
391  if (varSelection == MOST_FRACTIONAL) {
392  intParam_[NumberStrong] = 0;
394  options_->SetIntegerValue("bonmin.number_strong_branch",intParam_[BabSetupBase::NumberStrong],true,true);
395  options_->SetIntegerValue("bonmin.number_before_trust",intParam_[BabSetupBase::MinReliability],true,true);
396  }
397  else if (varSelection == RELIABILITY_BRANCHING) {
399  options_->SetIntegerValue("bonmin.number_before_trust",intParam_[BabSetupBase::MinReliability],true,true);
400  }
401  }
402 
403  void
405  {
407  }
408 
409  void
411  {
412  OsiTMINLPInterface::registerOptions(roptions);
413  /* BabSetup options.*/
414  roptions->SetRegisteringCategory("Output and Loglevel", RegisteredOptions::BonminCategory);
415 
416  roptions->AddBoundedIntegerOption("bb_log_level",
417  "specify main branch-and-bound log level.",
418  0,5,1,
419  "Set the level of output of the branch-and-bound : "
420  "0 - none, 1 - minimal, 2 - normal low, 3 - normal high"
421  );
422  roptions->setOptionExtraInfo("bb_log_level", 127);
423 
424  roptions->AddLowerBoundedIntegerOption("bb_log_interval",
425  "Interval at which node level output is printed.",
426  0,100,
427  "Set the interval (in terms of number of nodes) at which "
428  "a log on node resolutions (consisting of lower and upper bounds) is given.");
429  roptions->setOptionExtraInfo("bb_log_interval", 127);
430 
431  roptions->AddBoundedIntegerOption("lp_log_level",
432  "specify LP log level.",
433  0,4,0,
434  "Set the level of output of the linear programming sub-solver in B-Hyb or B-QG : "
435  "0 - none, 1 - minimal, 2 - normal low, 3 - normal high, 4 - verbose"
436  );
437  roptions->setOptionExtraInfo("lp_log_level", 119);
438 
439  roptions->AddBoundedIntegerOption("nlp_log_at_root","specify a different log level "
440  "for root relaxation.",
441  0,12,0,
442  "");
443  roptions->setOptionExtraInfo("nlp_log_at_root",63);
444 
445  roptions->SetRegisteringCategory("Branch-and-bound options", RegisteredOptions::BonminCategory);
446 
447  roptions->AddLowerBoundedIntegerOption
448  ("random_generator_seed",
449  "Set seed for random number generator (a value of -1 sets seeds to time since Epoch).",
450  -1,0,
451  "");
452  roptions->setOptionExtraInfo("random_generator_seed",127);
453 
454  roptions->AddLowerBoundedNumberOption("time_limit",
455  "Set the global maximum computation time (in secs) for the algorithm.",
456  0.,0,1e10,
457  "");
458  roptions->setOptionExtraInfo("time_limit", 127);
459 
460  roptions->AddLowerBoundedIntegerOption("node_limit",
461  "Set the maximum number of nodes explored in the branch-and-bound search.",
462  0,COIN_INT_MAX,
463  "");
464  roptions->setOptionExtraInfo("node_limit", 127);
465 
466  roptions->AddLowerBoundedIntegerOption("iteration_limit",
467  "Set the cumulative maximum number of iteration in the algorithm used to process nodes continuous relaxations in the branch-and-bound.",
468  0,COIN_INT_MAX,
469  "value 0 deactivates option.");
470  roptions->setOptionExtraInfo("iteration_limit", 127);
471 
472  roptions->AddLowerBoundedIntegerOption("solution_limit",
473  "Abort after that much integer feasible solution have been found by algorithm",
474  0,COIN_INT_MAX,
475  "value 0 deactivates option");
476  roptions->setOptionExtraInfo("solution_limit", 127);
477 
478  roptions->AddLowerBoundedNumberOption("integer_tolerance",
479  "Set integer tolerance.",
480  0.,1,1e-06,
481  "Any number within that value of an integer is considered integer.");
482  roptions->setOptionExtraInfo("integer_tolerance", 127);
483 
484  roptions->AddBoundedNumberOption("allowable_gap",
485  "Specify the value of absolute gap under which the algorithm stops.",
486  -1.e20,0,1.e20,0,0.,
487  "Stop the tree search when the gap between the objective value of the best known solution"
488  " and the best bound on the objective of any solution is less than this.");
489  roptions->setOptionExtraInfo("allowable_gap", 127);
490 
491  roptions->AddBoundedNumberOption("allowable_fraction_gap",
492  "Specify the value of relative gap under which the algorithm stops.",
493  -1.e20,0,1.e20,0,0.0,
494  "Stop the tree search when the gap between the objective value of the best known solution "
495  "and the best bound on the objective of any solution is less than this "
496  "fraction of the absolute value of the best known solution value.");
497  roptions->setOptionExtraInfo("allowable_fraction_gap", 127);
498 
499  roptions->AddBoundedNumberOption("cutoff",
500  "Specify cutoff value.",
501  -1e100,0,1e100,0,1e100,
502  "cutoff should be the value of a feasible solution known by the user "
503  "(if any). The algorithm will only look for solutions better than cutoff.");
504  roptions->setOptionExtraInfo("cutoff", 127);
505 
506 
507  roptions->AddBoundedNumberOption("cutoff_decr",
508  "Specify cutoff decrement.",
509  -1e10,0,1e10,0,1e-05,
510  "Specify the amount by which cutoff is decremented below "
511  "a new best upper-bound"
512  " (usually a small positive value but in non-convex problems it may be a negative value).");
513  roptions->setOptionExtraInfo("cutoff_decr", 127);
514 
515 
516  roptions->AddStringOption5("node_comparison",
517  "Choose the node selection strategy.",
518  "best-bound",
519  "best-bound", "choose node with the smallest bound,",
520  "depth-first", "Perform depth first search,",
521  "breadth-first", "Perform breadth first search,",
522  "dynamic", "Cbc dynamic strategy (starts with a depth first search and turn to best bound after 3 "
523  "integer feasible solutions have been found).",
524  "best-guess", "choose node with smallest guessed integer solution",
525  "Choose the strategy for selecting the next node to be processed.");
526  roptions->setOptionExtraInfo("node_comparison", 63);
527 
528  roptions->AddStringOption5("tree_search_strategy",
529  "Pick a strategy for traversing the tree",
530  "probed-dive",
531  "top-node"," Always pick the top node as sorted by the node comparison function",
532  "dive","Dive in the tree if possible, otherwise pick top node as sorted by the tree comparison function.",
533  "probed-dive","Dive in the tree exploring two children before continuing the dive at each level.",
534  "dfs-dive","Dive in the tree if possible doing a depth first search. "
535  "Backtrack on leaves or when a prescribed depth is attained or "
536  "when estimate of best possible integer feasible solution in subtree "
537  "is worst than cutoff. "
538  "Once a prescribed limit of backtracks is attained pick top node "
539  "as sorted by the tree comparison function",
540  "dfs-dive-dynamic","Same as dfs-dive but once enough solution are found switch to best-bound and if too many nodes switch to depth-first.",
541  "All strategies can be used in conjunction with any of the node comparison functions. "
542  "Options which affect dfs-dive are max-backtracks-in-dive and max-dive-depth. "
543  "The dfs-dive won't work in a non-convex problem where objective does not decrease down branches."
544  );
545  roptions->setOptionExtraInfo("tree_search_strategy", 63);
546 
547  roptions->AddLowerBoundedIntegerOption("number_strong_branch",
548  "Choose the maximum number of variables considered for strong branching.",
549  0,20,
550  "Set the number of variables on which to do strong branching.");
551  roptions->setOptionExtraInfo("number_strong_branch", 127);
552 
553 
554  roptions->AddLowerBoundedIntegerOption
555  ("number_before_trust",
556  "Set the number of branches on a variable before its pseudo costs are to be believed "
557  "in dynamic strong branching.",
558  0,8,
559  "A value of 0 disables pseudo costs.");
560  roptions->setOptionExtraInfo("number_before_trust", 127);
561 
562  roptions->AddStringOption2("nlp_failure_behavior",
563  "Set the behavior when an NLP or a series of NLP are unsolved by Ipopt (we call unsolved an NLP for which Ipopt is not "
564  "able to guarantee optimality within the specified tolerances).",
565  "stop",
566  "stop", "Stop when failure happens.",
567  "fathom", "Continue when failure happens.",
568  "If set to \"fathom\", the algorithm will fathom the node when Ipopt fails to find a solution to the nlp "
569  "at that node within the specified tolerances. "
570  "The algorithm then becomes a heuristic, and the user will be warned that the solution might not be optimal.");
571  roptions->setOptionExtraInfo("nlp_failure_behavior", 8);
572 
573  roptions->AddStringOption2("sos_constraints",
574  "Whether or not to activate SOS constraints.",
575  "enable",
576  "enable","",
577  "disable","",
578  "(only type 1 SOS are supported at the moment)");
579  roptions->setOptionExtraInfo("sos_constraints", 63);
580 
581 #ifdef BONMIN_CURVATURE_BRANCHING
582  roptions->AddStringOption10("variable_selection",
583 #else
584  roptions->AddStringOption9("variable_selection",
585 #endif
586  "Chooses variable selection strategy",
587  "strong-branching",
588  "most-fractional", "Choose most fractional variable",
589  "strong-branching", "Perform strong branching",
590  "reliability-branching", "Use reliability branching",
591 #ifdef BONMIN_CURVATURE_BRANCHING
592  "curvature-estimator", "Use curvature estimation to select branching variable",
593 #endif
594  "qp-strong-branching", "Perform strong branching with QP approximation",
595  "lp-strong-branching", "Perform strong branching with LP approximation",
596  "nlp-strong-branching", "Perform strong branching with NLP approximation",
597  "osi-simple", "Osi method to do simple branching",
598  "osi-strong", "Osi method to do strong branching",
599  "random", "Method to choose branching variable randomly");
600 
601  roptions->setOptionExtraInfo("variable_selection", 27);
602 
603  roptions->AddLowerBoundedIntegerOption("num_cut_passes",
604  "Set the maximum number of cut passes at regular nodes of the branch-and-cut.",
605  0,1,
606  "");
607  roptions->setOptionExtraInfo("num_cut_passes", 19);
608 
609  roptions->AddLowerBoundedIntegerOption("num_cut_passes_at_root",
610  "Set the maximum number of cut passes at regular nodes of the branch-and-cut.",
611  0,20,
612  "");
613  roptions->setOptionExtraInfo("num_cut_passes_at_root", 19);
614 
615  roptions->AddStringOption2("enable_dynamic_nlp",
616  "Enable dynamic linear and quadratic rows addition in nlp",
617  "no",
618  "no", "",
619  "yes", "",
620  "");
621  roptions->setOptionExtraInfo("enable_dynamic_nlp", 19);
622 
623 
624  //roptions->SetRegisteringCategory("Debugging",RegisteredOptions::UndocumentedCategory);
625  roptions->AddStringOption2("read_solution_file",
626  "Read a file with the optimal solution to test if algorithms cuts it.",
627  "no",
628  "no","",
629  "yes","",
630  "For Debugging purposes only.");
631  roptions->setOptionExtraInfo("enable_dynamic_nlp", 8);
632 
633  /* Branching options.*/
635 
636 #ifdef COIN_HAS_FILTERSQP
638  BqpdSolver::registerOptions(roptions);
639 #endif
640  CbcDiver::registerOptions(roptions);
643  }
644 
645 
647  void
649  {
650  options_ = new Ipopt::OptionsList();
651 
652  journalist_= new Ipopt::Journalist();
654 
655  try {
656  Ipopt::SmartPtr<Ipopt::Journal> stdout_journal =
657  journalist_->AddFileJournal("console", "stdout", Ipopt::J_ITERSUMMARY);
658 
659  options_->SetJournalist(journalist_);
660  options_->SetRegisteredOptions(GetRawPtr(roptions_));
661  }
662  catch (Ipopt::IpoptException &E) {
663  E.ReportException(*journalist_);
664  throw E;
665  }
666  catch (std::bad_alloc) {
667  journalist_->Printf(Ipopt::J_ERROR, Ipopt::J_MAIN, "\n Not enough memory .... EXIT\n");
668  throw -1;
669  }
670 #ifndef NO_CATCH_ALL
671  catch (...) {
672  Ipopt::IpoptException E("Uncaught exception in FilterSolver::FilterSolver()",
673  "BonFilterSolver.cpp",-1);
674  throw E;
675  }
676 #endif
677 
678  registerOptions();
679  }
680 
682  void
683  BabSetupBase::readOptionsFile(std::string fileName)
684  {
685  if (GetRawPtr(options_) == NULL || GetRawPtr(roptions_) == NULL || GetRawPtr(journalist_) == NULL)
687  std::ifstream is;
688  if (fileName != "") {
689  try {
690  is.open(fileName.c_str());
691  }
692  catch (std::bad_alloc) {
693  journalist_->Printf(Ipopt::J_SUMMARY, Ipopt::J_MAIN, "\nEXIT: Not enough memory.\n");
694  throw -1;
695  }
696 #ifndef NO_CATCH_ALL
697  catch (...) {
698  Ipopt::IpoptException E("Unknown Exception caught in ipopt", "Unknown File", -1);
699  E.ReportException(*journalist_);
700  throw -1;
701  }
702 #endif
703  }
704  readOptionsStream(is);
705  if (is) {
706  is.close();
707  }
708  }
709 
711  void
712  BabSetupBase::readOptionsString(std::string opt_string)
713  {
714  if (GetRawPtr(options_) == NULL || GetRawPtr(roptions_) == NULL || GetRawPtr(journalist_) == NULL)
716  std::stringstream is(opt_string.c_str());
717  readOptionsStream(is);
718  }
719 
720 
721  void
723  {
724  if (GetRawPtr(options_) == NULL || GetRawPtr(roptions_) == NULL || GetRawPtr(journalist_) == NULL)
726  if (is.good()) {
727  try {
728  options_->ReadFromStream(*journalist_, is);
729  }
730  catch (Ipopt::IpoptException &E) {
731  E.ReportException(*journalist_);
732  throw E;
733  }
734  }
735  mayPrintDoc();
736  readOptions_=true;
737  }
738 
740  void
742  {
743  bool print_options_documentation;
744  options_->GetBoolValue("print_options_documentation",
745  print_options_documentation, "");
746  if (print_options_documentation) {
747  std::list<std::string> categories;
748  categories.push_back("Algorithm choice");
749  categories.push_back("Branch-and-bound options");
750  categories.push_back("ECP cuts generation");
751  categories.push_back("Feasibility checker using OA cuts");
752  categories.push_back("MILP Solver");
753  categories.push_back("MILP cutting planes in hybrid algorithm");
754  categories.push_back("Primal Heuristics");
755  categories.push_back("NLP interface");
756  categories.push_back("NLP solution robustness");
757  categories.push_back("NLP solves in hybrid algorithm");
758  categories.push_back("Nonconvex problems");
759  categories.push_back("Outer Approximation Decomposition (B-OA)");
760  categories.push_back("Outer Approximation cuts generation");
761  categories.push_back("Output and Loglevel");
762  categories.push_back("Strong branching setup");
763  // Undocumented categories
764  categories.push_back("Diving options");
765  categories.push_back("ECP based strong branching");
766  categories.push_back("Primal Heuristics (undocumented)");
767  categories.push_back("Outer Approximation strengthening");
768 #ifdef COIN_HAS_FILTERSQP
769  categories.push_back("FilterSQP options");
770 #endif
771  // roptions->OutputLatexOptionDocumentation2(*app_->Jnlst(),categories);
772  roptions_->OutputOptionDocumentation(*(journalist_),categories);
773  }
774  }
775 
776  void
778  {
779  const int * priorities = nonlinearSolver()->getPriorities();
780  const double * upPsCosts = nonlinearSolver()->getUpPsCosts();
781  const int * directions = nonlinearSolver()->getBranchingDirections();
782  bool hasPseudo = (upPsCosts!=NULL);
783  if (priorities == NULL && directions && NULL && hasPseudo)
784  return;
785  int n = nonlinearSolver()->numberObjects();
786  OsiObject ** objects = nonlinearSolver()->objects();
787  for (int i = 0 ; i < n; i++) {
788  OsiObject2 * object = dynamic_cast<OsiObject2 *>(objects[i]);
789  int iCol = objects[i]->columnNumber();
790  if (iCol < 0) {
791  throw CoinError("BabSetupBase","setPriorities",
792  "Don't know how to set priority for non-column object.");
793  }
794  if (priorities) {
795  objects[i]->setPriority(priorities[iCol]);
796  }
797  if (directions) {
798  if (object == NULL) {
799  throw CoinError("BabSetupBase","setPriorities",
800  "Don't know how to set preferred way for object.");
801  }
802  object->setPreferredWay(directions[iCol]);
803  }
804  if (upPsCosts) {
805  throw CoinError("BabSetupBase","setPriorities",
806  "Can not handle user set pseudo-costs with OsiObjects\n"
807  "You should use one of the Cbc branching rules:\n"
808  "most-fractional or strong-branching.");
809  }
810  }
811  }
812 
813  void
815  {
816 
817  // pass user set Sos constraints (code inspired from CoinSolve.cpp)
818  const TMINLP::SosInfo * sos = nonlinearSolver()->model()->sosConstraints();
819  if (!getIntParameter(BabSetupBase::DisableSos) && sos && sos->num > 0) //we have some sos constraints
820  {
821  const int & numSos = sos->num;
822  OsiObject ** objects = new OsiObject*[numSos];
823  const int * starts = sos->starts;
824  const int * indices = sos->indices;
825  const char * types = sos->types;
826  const double * weights = sos->weights;
827  bool hasPriorities = false;
828  const int * varPriorities = nonlinearSolver()->getPriorities();
829  int numberObjects = nonlinearSolver()->numberObjects();
830  if (varPriorities)
831  {
832  for (int i = 0 ; i < numberObjects ; i++) {
833  if (varPriorities[i]) {
834  hasPriorities = true;
835  break;
836  }
837  }
838  }
839  const int * sosPriorities = sos->priorities;
840  if (sosPriorities)
841  {
842  for (int i = 0 ; i < numSos ; i++) {
843  if (sosPriorities[i]) {
844  hasPriorities = true;
845  break;
846  }
847  }
848  }
849  for (int i = 0 ; i < numSos ; i++)
850  {
851  int start = starts[i];
852  int length = starts[i + 1] - start;
853  objects[i] = new OsiSOS(nonlinearSolver(), length, &indices[start],
854  &weights[start], (int) types[i]);
855 
856  objects[i]->setPriority(10);
857  if (hasPriorities && sosPriorities && sosPriorities[i]) {
858  objects[i]->setPriority(sosPriorities[i]);
859  }
860  }
861  nonlinearSolver()->addObjects(numSos, objects);
862  for (int i = 0 ; i < numSos ; i++)
863  delete objects[i];
864  delete [] objects;
865  }
866  }
867 
868 
869 }/* End namespace Bonmin.*/
870 
int getIntParameter(const IntParameter &p) const
Return value of integer parameter.
Behavior of the algorithm in the case of a failure.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
void readOptionsStream(std::istream &is)
Get the options from stream.
Max number of failures in a branch.
const vector< OsiObject * > & objects() const
Access to extra objects.
int intParam_[NumberIntParam]
storage of integer parameters.
CuttingMethods cutGenerators_
Cut generation methods.
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Get a pointer to a journalist.
virtual void registerOptions()
Register all the options for this algorithm instance.
int num
Number of SOS constraints.
Definition: BonTMINLP.hpp:75
void use(const OsiTMINLPInterface &nlp)
use existing TMINLP interface (containing the options).
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Get a pointer to RegisteredOptions (generally used to add new ones)
const double * getUpPsCosts() const
Get number of columns.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
Stop if relative gap is less than this.
virtual const SosInfo * sosConstraints() const =0
HeuristicMethods heuristics_
Heuristic methods.
vector< OsiObject * > objects_
Extra object to add to Cbc (not OsiObjects).
OsiSolverInterface * clone(bool copyData=true) const
Virtual copy constructor.
static double defaultDoubleParam_[NumberDoubleParam]
default values for double parameters.
bool IsValid(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:465
Number of candidates for strong branching.
TreeTraversal treeTraversalMethod_
Tree traversal method.
void use(Ipopt::SmartPtr< TMINLP2TNLP > tminlp2tnlp)
Sets the TMINLP2TNLP to be used by the interface.
Class to store sos constraints for model.
Definition: BonTMINLP.hpp:72
bool readOptions_
flag to say if option file was read.
BabSetupBase(const CoinMessageHandler *handler=NULL)
Default constructor.
void setPriorities()
Set the priorities into OsiTMINLPInterface when needed.
const int * getBranchingDirections() const
get prefered branching directions
OsiTMINLPInterface * nonlinearSolver_
Storage of the non-linear solver used.
const int * getPriorities() const
Get priorities on integer variables.
Minimum reliability before trust pseudo-costs.
From a TMINLP, this class adapts to another TMINLP where the original objective is transformed into a...
const Bonmin::TNLPSolver * solver() const
OsiChooseVariable * branchingMethod_
Branching method.
int * starts
For 0 &lt;= i &lt; nums, start[i] gives the indice of indices and weights arrays at which the description o...
Definition: BonTMINLP.hpp:86
void fint fint fint real fint real real real real real real real real real * e
the MaxTime class.
Definition: OSOption.h:668
A class to have all elements necessary to setup a branch-and-bound.
limit on number of integer feasible solution.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options of the method.
Definition: BonDiver.cpp:729
NodeComparison nodeComparisonMethod_
Node comparison method.
static int defaultIntParam_[NumberIntParam]
default values for int parameters.
virtual BabSetupBase * clone() const =0
virtual copy constructor.
TreeTraversal
Strategies for traversing the tree.
void registerOptions()
Register this solver options into passed roptions.
int * priorities
priorities of sos constraints.
Definition: BonTMINLP.hpp:79
Display information every logIntervval nodes.
void addSos()
Add SOS constraints to OsiTMINLPInterface when needed.
char * types
Type of sos.
Definition: BonTMINLP.hpp:77
Max number of consecutive infeasible problem in a branch before fathoming.
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:452
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
Consider or not SOS constraints.
Log level for root relaxation.
void initializeOptionsAndJournalist()
Initialize the options and the journalist.
This is a derived class fro TMINLP2TNLP to handle adding quadratic cuts.
Number of cut passes at nodes.
static void registerAllOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register all the options for this algorithm instance.
double doubleParam_[NumberDoubleParam]
storage of double parameters.
NodeComparison
Strategies for comparing the nodes on the heap.
std::string prefix_
Prefix to use when reading options.
int * indices
indices of elements belonging to the SOS.
Definition: BonTMINLP.hpp:88
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
Ipopt::SmartPtr< const Ipopt::OptionsList > options() const
Get the options (for getting their values).
OsiTMINLPInterface * nonlinearSolver()
Pointer to the non-linear solver used.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options of the method.
Definition: BonDiver.cpp:169
void gatherParametersValues()
Get the values of base parameters from the options stored.
void registerOptions()
Register this solver options into passed roptions.
static char prefix[100]
Definition: BM_lp.cpp:26
Number of cut passes at nodes.
CoinMessageHandler * messageHandler_
separate message handler.
void initialize(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist, const std::string &prefix, Ipopt::SmartPtr< TMINLP > tminlp)
Facilitator to initialize interface.
virtual ~BabSetupBase()
Virtual destructor.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
void fint * n
void mayPrintDoc()
May print documentation of options if options print_options_documentation is set to yes...
virtual void readOptionsFile()
Get the options from default text file (bonmin.opt) if don&#39;t already have them.
OsiSolverInterface * continuousSolver_
Storage of continuous solver.
const char * prefix() const
Get prefix to use for options.
Stop if absolute gap is less than this.
double * weights
weights of the elements of the SOS.
Definition: BonTMINLP.hpp:90
void readOptionsString(std::string opt_string)
Get the options from long string containing all.
Class to add a few more information to Ipopt::RegisteredOptions.