/home/coin/SVN-release/OS-2.0.0/Bonmin/experimental/NotConvex/BonCouenne.cpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006, 2007
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pietro Belotti, Carnegie Mellon University,
00007 // Pierre Bonami, International Business Machines Corporation
00008 //
00009 // Date : 12/19/2006
00010 
00011 
00012 #if defined(_MSC_VER)
00013 // Turn off compiler warning about long names
00014 #  pragma warning(disable:4786)
00015 #endif
00016 #include <iomanip>
00017 #include <fstream>
00018 
00019 #include <stdlib.h>
00020 
00021 #include "CoinTime.hpp"
00022 #include "BonminConfig.h"
00023 #include "BonCouenneInterface.hpp"
00024 #include "BonIpoptSolver.hpp"
00025 
00026 #include "BonCouenneSetup.hpp"
00027 
00028 #include "BonCbc.hpp"
00029 #ifdef COIN_HAS_FILTERSQP
00030 #include "BonFilterSolver.hpp"
00031 #endif
00032 
00033 #include "CbcCutGenerator.hpp"
00034 #include "CouenneProblem.hpp"
00035 #include "CouenneCutGenerator.hpp"
00036 
00037 using namespace Bonmin;
00038 
00039 int main (int argc, char *argv[])
00040 {
00041   using namespace Ipopt;
00042 
00043   char * pbName = NULL;
00044   double time_start = CoinCpuTime();
00045 
00046   try {
00047 
00048     Bab bb;
00049     bb.setUsingCouenne (true);
00050 
00051     CouenneSetup bonmin;
00052     bonmin.InitializeCouenne (argv);
00053 
00054 #if 0
00055     CouenneFeasibility feasibility;
00056     bb.model().setProblemFeasibility (feasibility);
00057 #endif
00058 
00060     double timeLimit = 0;
00061     bonmin.options () -> GetNumericValue ("time_limit", timeLimit, "bonmin.");
00062     bonmin.setDoubleParameter (BabSetupBase::MaxTime, 
00063                                timeLimit - (time_start = (CoinCpuTime () - time_start)));
00064 
00066 
00067     bb (bonmin); // do branch and bound
00068 
00070 
00071     std::cout.precision (10);
00072 
00073     /*std::string message, status;
00074 
00075     if(bb.mipStatus()==Bab::FeasibleOptimal) {
00076       status = "\t\"Finished\"";
00077       message = "\nbonmin: Optimal";
00078     }
00079     else if(bb.mipStatus()==Bab::ProvenInfeasible) {
00080       status = "\t\"Finished\"";
00081       message = "\nbonmin: Infeasible problem";
00082     }
00083     else if(bb.mipStatus()==Bab::Feasible) {
00084       status = "\t\"Not finished\"";
00085       message = "\n Optimization not finished.";
00086     }
00087     else if(bb.mipStatus()==Bab::NoSolutionKnown) {
00088       status = "\t\"Not finished\"";
00089       message = "\n Optimization not finished.";
00090       }*/
00091 
00092     if (bonmin.displayStats ()) { // print statistics
00093 
00095       int nr=-1, nt=-1;
00096       double st=-1;
00097 
00098       // CAUTION: assuming first cut generator is our CouenneCutGenerator
00099 
00100       CouenneCutGenerator *cg = NULL;
00101 
00102       if (bb.model (). cutGenerators ())
00103         cg = dynamic_cast <CouenneCutGenerator *> 
00104           (bb.model (). cutGenerators () [0] -> generator ());
00105 
00106       if (cg) cg -> getStats (nr, nt, st);
00107       else printf ("Warning, could not get pointer to CouenneCutGenerator\n");
00108 
00109       CouenneProblem *cp = cg ? cg -> Problem () : NULL;
00110 
00111       if (cg && !cp) printf ("Warning, could not get pointer to problem\n");
00112       else
00113         printf ("Stats: %-15s %4d [var] %4d [int] %4d [con] %4d [aux] "
00114                 "%6d [root] %8d [tot] %6g [sep] %8g [time] %8g [bb] "
00115                 "%20e [lower] %20e [upper] %7d [nodes]\n",// %s %s\n",
00116                 cp ? cp -> problemName ().c_str () : "unknown",
00117                 (cp) ? cp -> nOrigVars     () : -1, 
00118                 (cp) ? cp -> nOrigIntVars  () : -1, 
00119                 (cp) ? cp -> nOrigCons     () : -1,
00120                 (cp) ? (cp -> nVars     () - 
00121                         cp -> nOrigVars ()): -1,
00122                 nr, nt, st, 
00123                 CoinCpuTime () - time_start,
00124                 cg ? (CoinCpuTime () - cg -> rootTime ()) : CoinCpuTime (),
00125                 bb.model (). getBestPossibleObjValue (),
00126                 bb.model (). getObjValue (),
00127                 //bb.bestBound (),
00128                 //bb.bestObj (),
00129                 bb.numNodes ());
00130                 //bb.iterationCount ());
00131                 //status.c_str (), message.c_str ());
00132 
00133       /*
00135 
00136       double timeLimit = 0, obj = bb.model (). getObjValue ();
00137       bonmin.options() -> GetNumericValue ("time_limit", timeLimit, "bonmin.");
00138 
00139       if (CoinCpuTime () - time_start > timeLimit) {
00140 
00141         // time limit reached, print upper and (in brackets) lower
00142 
00143         double obj = bb.model (). getObjValue ();
00144 
00145         if (fabs (obj) < 9e12) 
00146           printf    ("%18.9f &", bb.bestObj ());
00147         else printf (" %8s     &", "inf_prim");
00148 
00149         if (fabs (bb.bestBound()) < 9e12) 
00150           printf    (" (%18.9f) &", bb.bestBound ());
00151         else printf (" %8s       &", "inf_dual");
00152       }
00153       else {
00154         // time limit not reached, print upper and time
00155 
00156         if (fabs (obj) < 9e12) 
00157           printf    (" %18.9f &", bb.bestObj ());
00158         else printf (" %8s     &", "inf_prim");
00159           
00160         if (fabs (bb.bestBound()) < 9e12) 
00161           printf    (" %12.3f   &", CoinCpuTime () - time_start);
00162         else printf (" %8s       &", "inf_dual");
00163       }
00164 
00165 
00166       printf ("%7d & %7d \\\\\n",
00167               bb.numNodes(),
00168               bb.iterationCount());
00169               //              nlp_and_solver->totalNlpSolveTime(),
00170               //              nlp_and_solver->nCallOptimizeTNLP(),
00171       //              status.c_str());
00172       */
00173     }
00174 
00175 //    nlp_and_solver -> writeAmplSolFile (message, bb.bestSolution (), NULL);
00176   }
00177   catch(TNLPSolver::UnsolvedError *E) {
00178      E->writeDiffFiles();
00179      E->printError(std::cerr);
00180     //There has been a failure to solve a problem with Ipopt.
00181     //And we will output file with information on what has been changed in the problem to make it fail.
00182     //Now depending on what algorithm has been called (B-BB or other) the failed problem may be at different place.
00183     //    const OsiSolverInterface &si1 = (algo > 0) ? nlpSolver : *model.solver();
00184   }
00185   catch(OsiTMINLPInterface::SimpleError &E) {
00186     std::cerr<<E.className()<<"::"<<E.methodName()
00187              <<std::endl
00188              <<E.message()<<std::endl;
00189   }
00190   catch(CoinError &E) {
00191     std::cerr<<E.className()<<"::"<<E.methodName()
00192              <<std::endl
00193              <<E.message()<<std::endl;
00194   }
00195   catch (Ipopt::OPTION_INVALID &E)
00196   {
00197    std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl;
00198   }
00199 //  catch(...) {
00200 //    std::cerr<<pbName<<" unrecognized excpetion"<<std::endl;
00201 //    std::cerr<<pbName<<"\t Finished \t exception"<<std::endl;
00202 //    throw;
00203 //  }
00204 
00205   delete [] pbName;
00206   return 0;
00207 }

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