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