Bonmin
1.7
|
00001 // (C) Copyright Carnegie Mellon University 2006, 2007 00002 // All Rights Reserved. 00003 // This code is published under the Common Public License. 00004 // 00005 // Authors : 00006 // P. Bonami, Carnegie Mellon University 00007 // 00008 // Date : 03/17/2006 00009 00010 00011 #include <iomanip> 00012 #include <fstream> 00013 00014 #include "CoinPragma.hpp" 00015 #include "CoinTime.hpp" 00016 #include "CoinError.hpp" 00017 00018 #include "BonOsiTMINLPInterface.hpp" 00019 #include "BonIpoptSolver.hpp" 00020 #include "MyTMINLP.hpp" 00021 #include "BonCbc.hpp" 00022 #include "BonBonminSetup.hpp" 00023 00024 #include "BonOACutGenerator2.hpp" 00025 #include "BonEcpCuts.hpp" 00026 #include "BonOaNlpOptim.hpp" 00027 //#define REDIRECT 00028 00029 int main (int argc, char *argv[]) 00030 { 00031 WindowsErrorPopupBlocker(); 00032 00033 using namespace Ipopt; 00034 using namespace Bonmin; 00035 SmartPtr<MyTMINLP> tminlp = new MyTMINLP; 00036 00037 #ifdef REDIRECT 00038 FILE * fp = fopen("log.out","w"); 00039 CoinMessageHandler handler(fp); 00040 BonminSetup bonmin(&handler); 00041 #else 00042 BonminSetup bonmin; 00043 #endif 00044 bonmin.initializeOptionsAndJournalist(); 00045 //Register an additional option 00046 bonmin.roptions()->AddStringOption2("print_solution","Do we print the solution or not?", 00047 "yes", 00048 "no", "No, we don't.", 00049 "yes", "Yes, we do.", 00050 "A longer comment can be put here"); 00051 00052 00053 00054 // Here we can change the default value of some Bonmin or Ipopt option 00055 bonmin.options()->SetNumericValue("bonmin.time_limit", 5); //changes bonmin's time limit 00056 bonmin.options()->SetStringValue("mu_oracle","loqo"); 00057 00058 //Here we read several option files 00059 bonmin.readOptionsFile("Mybonmin.opt"); 00060 bonmin.readOptionsFile();// This reads the default file "bonmin.opt" 00061 00062 // Options can also be set by using a string with a format similar to the bonmin.opt file 00063 bonmin.readOptionsString("bonmin.algorithm B-BB\n"); 00064 00065 // Now we can obtain the value of the new option 00066 int printSolution; 00067 bonmin.options()->GetEnumValue("print_solution", printSolution,""); 00068 if(printSolution == 1){ 00069 tminlp->printSolutionAtEndOfAlgorithm(); 00070 } 00071 00072 //Now initialize from tminlp 00073 bonmin.initialize(GetRawPtr(tminlp)); 00074 00075 00076 00077 //Set up done, now let's branch and bound 00078 try { 00079 Bab bb; 00080 bb(bonmin);//process parameter file using Ipopt and do branch and bound using Cbc 00081 00082 00083 } 00084 catch(TNLPSolver::UnsolvedError *E) { 00085 //There has been a failure to solve a problem with Ipopt. 00086 std::cerr<<"Ipopt has failed to solve a problem"<<std::endl; 00087 } 00088 catch(OsiTMINLPInterface::SimpleError &E) { 00089 std::cerr<<E.className()<<"::"<<E.methodName() 00090 <<std::endl 00091 <<E.message()<<std::endl; 00092 } 00093 catch(CoinError &E) { 00094 std::cerr<<E.className()<<"::"<<E.methodName() 00095 <<std::endl 00096 <<E.message()<<std::endl; 00097 } 00098 00099 00100 return 0; 00101 } 00102