MyBonmin.cpp

Go to the documentation of this file.
00001 // (C) Copyright Carnegie Mellon University 2006
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 
00020 #include "IpoptInterface.hpp"
00021 #include "MyTMINLP.hpp"
00022 #include "CbcBonmin.hpp"
00023 
00024 
00025 
00026 int main (int argc, char *argv[])
00027 {
00028   using namespace Ipopt;
00029   SmartPtr<TMINLP> tminlp = new MyTMINLP;
00030   IpoptInterface nlpSolver(tminlp);
00031   
00032   //Option can be set here directly either to bonmin or ipopt
00033   nlpSolver.retrieve_options()->SetNumericValue("bonmin.time_limit", 1); //changes bonmin's time limit
00034   nlpSolver.retrieve_options()->SetStringValue("mu_oracle","loqo");
00035 
00036   // we can also try and read an option file (can eventually change options set before, option file always have priority)
00037   nlpSolver.readOptionFile("My_bonmin.opt");
00038 
00039   //Set up done, now let's branch and bound
00040   double time1 = CoinCpuTime();
00041   try {
00042     BonminCbcParam par;
00043     BonminBB bb;
00044     par(nlpSolver);
00045 
00046     bb(nlpSolver, par);//process parameter file using Ipopt and do branch and bound
00047 
00048     std::cout.precision(10);
00049 
00050     std::string message;
00051     if(bb.mipStatus()==BonminBB::FeasibleOptimal) {
00052       std::cout<<"\t\"Finished\"\t";
00053       message = "\nbonmin: Optimal";
00054     }
00055     else if(bb.mipStatus()==BonminBB::ProvenInfeasible) {
00056       std::cout<<"\t\"Finished\"\t";
00057       message = "\nbonmin: Infeasible problem";
00058     }
00059     else if(bb.mipStatus()==BonminBB::Feasible) {
00060       std::cout<<"\t\"Not finished\""<<"\t";
00061       message = "\n Optimization not finished.";
00062     }
00063     else if(bb.mipStatus()==BonminBB::NoSolutionKnown) {
00064       std::cout<<"\t\"Not finished\""<<"\t";
00065       message = "\n Optimization not finished.";
00066     }
00067     std::cout<<CoinCpuTime()-time1<<"\t"
00068     <<bb.bestObj()<<"\t"
00069     <<bb.numNodes()<<"\t"
00070     <<bb.iterationCount()<<"\t"
00071     <<std::endl;
00072 
00073   }
00074   catch(IpoptInterface::UnsolvedError &E) {
00075     //There has been a failure to solve a problem with Ipopt.
00076     std::cerr<<"Ipopt has failed to solve a problem"<<std::endl;
00077   }
00078   catch(IpoptInterface::SimpleError &E) {
00079     std::cerr<<E.className()<<"::"<<E.methodName()
00080              <<std::endl
00081              <<E.message()<<std::endl;
00082   }
00083   catch(CoinError &E) {
00084     std::cerr<<E.className()<<"::"<<E.methodName()
00085              <<std::endl
00086              <<E.message()<<std::endl;
00087   }
00088 
00089 
00090   return 0;
00091 }
00092 

Generated on Fri May 16 21:06:01 2008 for Bonmin by  doxygen 1.4.7