Bonmin  1.8.8
MyBonmin.cpp
Go to the documentation of this file.
1 // (C) Copyright Carnegie Mellon University 2006, 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // P. Bonami, Carnegie Mellon University
7 //
8 // Date : 03/17/2006
9 
10 
11 #include <iomanip>
12 #include <fstream>
13 
14 #include "CoinPragma.hpp"
15 #include "CoinTime.hpp"
16 #include "CoinError.hpp"
17 
19 #include "BonIpoptSolver.hpp"
20 #include "MyTMINLP.hpp"
21 #include "BonCbc.hpp"
22 #include "BonBonminSetup.hpp"
23 
24 #include "BonOACutGenerator2.hpp"
25 #include "BonEcpCuts.hpp"
26 #include "BonOaNlpOptim.hpp"
27 //#define REDIRECT
28 
29 int main (int argc, char *argv[])
30 {
31  WindowsErrorPopupBlocker();
32 
33  using namespace Ipopt;
34  using namespace Bonmin;
35  SmartPtr<MyTMINLP> tminlp = new MyTMINLP;
36 
37 #ifdef REDIRECT
38  FILE * fp = fopen("log.out","w");
39  CoinMessageHandler handler(fp);
40  BonminSetup bonmin(&handler);
41 #else
42  BonminSetup bonmin;
43 #endif
45  //Register an additional option
46  bonmin.roptions()->AddStringOption2("print_solution","Do we print the solution or not?",
47  "yes",
48  "no", "No, we don't.",
49  "yes", "Yes, we do.",
50  "A longer comment can be put here");
51 
52 
53 
54  // Here we can change the default value of some Bonmin or Ipopt option
55  bonmin.options()->SetNumericValue("bonmin.time_limit", 5); //changes bonmin's time limit
56  bonmin.options()->SetStringValue("mu_oracle","loqo");
57 
58  //Here we read several option files
59  bonmin.readOptionsFile("Mybonmin.opt");
60  bonmin.readOptionsFile();// This reads the default file "bonmin.opt"
61 
62  // Options can also be set by using a string with a format similar to the bonmin.opt file
63  bonmin.readOptionsString("bonmin.algorithm B-BB\n");
64 
65  // Now we can obtain the value of the new option
66  int printSolution;
67  bonmin.options()->GetEnumValue("print_solution", printSolution,"");
68  if(printSolution == 1){
69  tminlp->printSolutionAtEndOfAlgorithm();
70  }
71 
72  //Now initialize from tminlp
73  bonmin.initialize(GetRawPtr(tminlp));
74 
75 
76 
77  //Set up done, now let's branch and bound
78  try {
79  Bab bb;
80  bb(bonmin);//process parameter file using Ipopt and do branch and bound using Cbc
81 
82 
83  }
84  catch(TNLPSolver::UnsolvedError *E) {
85  //There has been a failure to solve a problem with Ipopt.
86  std::cerr<<"Ipopt has failed to solve a problem"<<std::endl;
87  }
89  std::cerr<<E.className()<<"::"<<E.methodName()
90  <<std::endl
91  <<E.message()<<std::endl;
92  }
93  catch(CoinError &E) {
94  std::cerr<<E.className()<<"::"<<E.methodName()
95  <<std::endl
96  <<E.message()<<std::endl;
97  }
98 
99 
100  return 0;
101 }
102 
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Access registered Options.
int main(int argc, char *argv[])
Definition: MyBonmin.cpp:29
Error class to throw exceptions from OsiTMINLPInterface.
A C++ example for interfacing an MINLP with bonmin.
Definition: MyTMINLP.hpp:28
void initializeOptionsAndJournalist()
Initialize the options and the journalist.
We will throw this error when a problem is not solved.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
virtual void readOptionsFile()
Get the options from default text file (bonmin.opt) if don&#39;t already have them.
void readOptionsString(std::string opt_string)
Get the options from long string containing all.
void initialize(Ipopt::SmartPtr< TMINLP > tminlp, bool createContinuousSolver=true)
Initialize, read options and create appropriate bonmin setup.