/home/coin/SVN-release/OS-2.0.0/Bonmin/examples/CppExample/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 
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 
00041   BonminSetup bonmin;
00042   bonmin.initializeOptionsAndJournalist();
00043   //Register an additional option
00044   bonmin.roptions()->AddStringOption2("print_solution","Do we print the solution or not?",
00045                                  "yes",
00046                                  "no", "No, we don't.",
00047                                  "yes", "Yes, we do.",
00048                                  "A longer comment can be put here");
00049   
00050   
00051   
00052   // Here we can change the default value of some Bonmin or Ipopt option
00053   bonmin.options()->SetNumericValue("bonmin.time_limit", 5); //changes bonmin's time limit
00054   bonmin.options()->SetStringValue("mu_oracle","loqo");
00055   
00056   //Here we read several option files
00057   bonmin.readOptionsFile("Mybonmin.opt");
00058   bonmin.readOptionsFile();// This reads the default file "bonmin.opt"
00059   
00060   // Options can also be set by using a string with a format similar to the bonmin.opt file
00061 //  bonmin.readOptionsString("bonmin.algorithm B-BB\n");
00062   
00063   // Now we can obtain the value of the new option
00064   int printSolution;
00065   bonmin.options()->GetEnumValue("print_solution", printSolution,"");
00066   if(printSolution == 1){
00067     tminlp->printSolutionAtEndOfAlgorithm();
00068   }
00069 
00070   //Now initialize from tminlp
00071   bonmin.initialize(GetRawPtr(tminlp));
00072 
00073 
00074 
00075   //Set up done, now let's branch and bound
00076   double time1 = CoinCpuTime();
00077   try {
00078     Bab bb;
00079     bb(bonmin);//process parameter file using Ipopt and do branch and bound using Cbc
00080 
00081 
00082   }
00083   catch(TNLPSolver::UnsolvedError *E) {
00084     //There has been a failure to solve a problem with Ipopt.
00085     std::cerr<<"Ipopt has failed to solve a problem"<<std::endl;
00086   }
00087   catch(OsiTMINLPInterface::SimpleError &E) {
00088     std::cerr<<E.className()<<"::"<<E.methodName()
00089              <<std::endl
00090              <<E.message()<<std::endl;
00091   }
00092   catch(CoinError &E) {
00093     std::cerr<<E.className()<<"::"<<E.methodName()
00094              <<std::endl
00095              <<E.message()<<std::endl;
00096   }
00097 
00098 
00099   return 0;
00100 }
00101 

Generated on Mon Aug 3 03:02:16 2009 by  doxygen 1.4.7