00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <cassert>
00013 #include <iomanip>
00014
00015 #include "BonminConfig.h"
00016
00017 #include "CoinPragma.hpp"
00018 #include "BonAmplInterface.hpp"
00019 #include "BonIpoptSolver.hpp"
00020 #include "BonBoundsReader.hpp"
00021 #include "BonStartPointReader.hpp"
00022 #include "CoinTime.hpp"
00023
00024 #include "BonAmplSetup.hpp"
00025
00026
00027
00028
00029
00030
00031
00032
00033 int main (int argc, char *argv[])
00034 {
00035
00036 using namespace Ipopt;
00037 using namespace Bonmin;
00038
00039
00040 char * pbName = new char[strlen(argv[1])+1];
00041 strcpy(pbName, argv[1]);
00042 std::string nodeFileName;
00043 if(argc > 2)
00044 nodeFileName=argv[2];
00045 std::string startingPointFile ="";
00046 if(argc>3)
00047 startingPointFile = argv[3];
00048
00049
00050 char ** myArgv = new char *[3];
00051 myArgv[0]=new char[strlen(argv[0])+1];
00052 strcpy(myArgv[0],argv[0]);
00053 myArgv[1]=new char[strlen(argv[1])+1];
00054 strcpy(myArgv[1],argv[1]);
00055 myArgv[2]= NULL;
00056
00057
00058 BonminAmplSetup bonmin;
00059 bonmin.initialize(myArgv);
00060 Bonmin::OsiTMINLPInterface& nlpSolver = *bonmin.nonlinearSolver();
00061
00062 Ipopt::SmartPtr<Ipopt::OptionsList> Options =
00063 nlpSolver.options();
00064
00065 nlpSolver.messageHandler()->setLogLevel(2);
00066
00067 try
00068 {
00069 std::cout<<nodeFileName<<std::endl;
00070
00071 if(argc>2) {
00072 Bonmin::BoundsReader bounds(nodeFileName);
00073 bounds.readAndApply(&nlpSolver);
00074 }
00075 if(argc>3) {
00076 Bonmin::StartPointReader init(startingPointFile);
00077 init.readAndApply(&nlpSolver);
00078 }
00079
00080 nlpSolver.solver()->forceSolverOutput(4);
00081 nlpSolver.initialSolve();
00082
00083
00084 for(int i = 0 ; i <nlpSolver.getNumCols() ; i++) {
00085 if (nlpSolver.isInteger(i)) {
00086 std::cout<<"x[ "<<i<<"] = "<<nlpSolver.getColSolution()[i]<<std::endl;
00087 }
00088 }
00089 }
00090 catch(Bonmin::OsiTMINLPInterface::SimpleError &E) {
00091 std::cerr<<E.className()<<"::"<<E.methodName()
00092 <<std::endl
00093 <<E.message()<<std::endl;
00094 }
00095 catch(CoinError &E) {
00096 std::cerr<<E.className()<<"::"<<E.methodName()
00097 <<std::endl
00098 <<E.message()<<std::endl;
00099 }
00100 catch(...) {
00101 std::cerr<<pbName<<" unrecognized excpetion"<<std::endl;
00102 std::cerr<<pbName<<"\t Finished \t exception"<<std::endl;
00103 throw;
00104 }
00105
00106
00107 delete [] pbName;
00108 delete [] myArgv[0];
00109 delete [] myArgv[1];
00110 delete [] myArgv;
00111 return 0;
00112 }