BonMin.cpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006, 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Andreas Waechter, International Business Machines Corporation
7 // Pierre Bonami, Carnegie Mellon University,
8 //
9 // Date : 02/15/2006
10 
11 
12 #include <iomanip>
13 #include <fstream>
14 
15 #include "CoinPragma.hpp"
16 #include "BonminConfig.h"
17 #include "IpoptConfig.h"
18 #include "CbcConfig.h"
19 #include "CoinTime.hpp"
20 #include "BonAmplSetup.hpp"
21 #include "BonCbc.hpp"
22 
23 #ifndef NDEBUG
24 #define CATCH_ERRORS
25 #endif
26 
27 using namespace Bonmin;
28 int main (int argc, char *argv[])
29 {
30  using namespace Ipopt;
31  char * pbName = NULL;
32 
33  std::cout<<"Bonmin "
34  <<BONMIN_VERSION;
35  std::cout<<" using Cbc "
36  <<CBC_VERSION;
37  std::cout<<" and Ipopt "
38  <<IPOPT_VERSION<<std::endl;
39  if(argc > 1) {
40  pbName = new char[strlen(argv[1])+1];
41  strcpy(pbName, argv[1]);
42  }
43 #define CATCH_ERRORS
44 #ifdef CATCH_ERRORS
45  try
46 #endif
47  {
48 
49  //FILE * fp = fopen("log","w");
50  BonminAmplSetup bonmin;
51  bonmin.initialize(argv);
52 
53  {
54  Bab bb;
55 
56  bb(bonmin);//do branch and bound
57  }
58  }
59 #ifdef CATCH_ERRORS
60  catch(TNLPSolver::UnsolvedError *E) {
61  E->writeDiffFiles();
62  E->printError(std::cerr);
63  //There has been a failure to solve a problem with Ipopt.
64  //And we will output file with information on what has been changed in the problem to make it fail.
65  //Now depending on what algorithm has been called (B-BB or other) the failed problem may be at different place.
66  // const OsiSolverInterface &si1 = (algo > 0) ? nlpSolver : *model.solver();
67  }
69  std::cerr<<E.className()<<"::"<<E.methodName()
70  <<std::endl
71  <<E.message()<<std::endl;
72  }
73  catch(CoinError &E) {
74  std::cerr<<E.className()<<"::"<<E.methodName()
75  <<std::endl
76  <<E.message()<<std::endl;
77  }
78  catch (Ipopt::OPTION_INVALID &E)
79  {
80  std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl;
81  }
82  catch (Ipopt::IpoptException &E)
83  {
84  std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl;
85  }
86 #ifndef NO_CATCH_ALL
87  catch(...) {
88  std::cerr<<pbName<<" unrecognized exception"<<std::endl;
89  std::cerr<<pbName<<"\t Finished \t exception"<<std::endl;
90  throw;
91  }
92 #endif
93 #endif
94 
95  delete [] pbName;
96  return 0;
97 }
98 
void initialize(char **&argv)
initialize bonmin with ampl model using the command line arguments.
int main(int argc, char *argv[])
Definition: BB_tm.cpp:32
void writeDiffFiles(const std::string prefix=std::string()) const
write files with differences between input model and this one
Error class to throw exceptions from OsiTMINLPInterface.
void printError(std::ostream &os)
Print error message.
We will throw this error when a problem is not solved.
#define BONMIN_VERSION