/home/coin/SVN-release/OS-2.4.2/Bonmin/src/Apps/BonNodeSolver.cpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006 
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Andreas Waechter, International Business Machines Corporation
00007 // Pierre Bonami, Carnegie Mellon University,
00008 //
00009 // Date : 02/15/2006
00010 
00011 
00012 #if defined(_MSC_VER)
00013 // Turn off compiler warning about long names
00014 #  pragma warning(disable:4786)
00015 #endif
00016 
00017 #include <cassert>
00018 #include <iomanip>
00019 
00020 #include "BonminConfig.h"
00021 
00022 #include "BonAmplInterface.hpp"
00023 #include "BonIpoptSolver.hpp"
00024 #include "BonBoundsReader.hpp"
00025 #include "BonStartPointReader.hpp"
00026 #include "CoinTime.hpp"
00027 
00028 #include "BonAmplSetup.hpp"
00029 
00030 
00031 /************************************************************************
00032  
00033 This mains is used for resolving the problem with fixed bounds and eventually a starting point
00034  
00035 ************************************************************************/
00036 
00037 int main (int argc, char *argv[])
00038 {
00039 
00040   using namespace Ipopt;
00041   using namespace Bonmin;
00042 
00043   // Read in model using argv[1]
00044   char * pbName = new char[strlen(argv[1])+1];
00045   strcpy(pbName, argv[1]);
00046   std::string nodeFileName;
00047   if(argc > 2)
00048     nodeFileName=argv[2];
00049   std::string startingPointFile ="";
00050   if(argc>3)
00051     startingPointFile = argv[3];
00052 
00053   //Give ampl an argv which doesn't crash him.
00054   char ** myArgv = new char *[3];
00055   myArgv[0]=new char[strlen(argv[0])+1];
00056   strcpy(myArgv[0],argv[0]);
00057   myArgv[1]=new char[strlen(argv[1])+1];
00058   strcpy(myArgv[1],argv[1]);
00059   myArgv[2]= NULL;//new char[1];
00060 
00061 
00062     BonminAmplSetup bonmin;
00063     bonmin.initialize(myArgv);
00064     Bonmin::OsiTMINLPInterface& nlpSolver = *bonmin.nonlinearSolver();
00065   
00066     Ipopt::SmartPtr<Ipopt::OptionsList> Options =
00067       nlpSolver.options();
00068 
00069     nlpSolver.messageHandler()->setLogLevel(2);
00070 
00071   try
00072     {
00073       std::cout<<nodeFileName<<std::endl;
00074       // Read the bounds and change them in Ipopt
00075       if(argc>2) {
00076         Bonmin::BoundsReader bounds(nodeFileName);
00077         bounds.readAndApply(&nlpSolver);
00078       }
00079       if(argc>3) {
00080         Bonmin::StartPointReader init(startingPointFile);
00081         init.readAndApply(&nlpSolver);
00082       }
00083       
00084       nlpSolver.solver()->forceSolverOutput(4);
00085       nlpSolver.initialSolve();
00086       
00087       //Print out integer variable values
00088       for(int i = 0 ; i <nlpSolver.getNumCols() ; i++) {
00089         if (nlpSolver.isInteger(i)) {
00090           std::cout<<"x[ "<<i<<"] = "<<nlpSolver.getColSolution()[i]<<std::endl;
00091         }
00092       }
00093     }
00094   catch(Bonmin::OsiTMINLPInterface::SimpleError &E) {
00095     std::cerr<<E.className()<<"::"<<E.methodName()
00096              <<std::endl
00097              <<E.message()<<std::endl;
00098   }
00099   catch(CoinError &E) {
00100     std::cerr<<E.className()<<"::"<<E.methodName()
00101              <<std::endl
00102              <<E.message()<<std::endl;
00103   }
00104   catch(...) {
00105     std::cerr<<pbName<<" unrecognized excpetion"<<std::endl;
00106     std::cerr<<pbName<<"\t Finished \t exception"<<std::endl;
00107     throw;
00108   }
00109   
00110   
00111   delete [] pbName;
00112   delete [] myArgv[0];
00113   delete [] myArgv[1];
00114   delete [] myArgv;
00115   return 0;
00116 }

Generated on Wed Nov 30 03:03:54 2011 by  doxygen 1.4.7