int main (int argc, char *argv[]) { using namespace Ipopt; using namespace Bonmin; // Read in model using argv[1] char * pbName = new char[strlen(argv[1])+1]; strcpy(pbName, argv[1]); std::string nodeFileName; if(argc > 2) nodeFileName=argv[2]; std::string startingPointFile =""; if(argc>3) startingPointFile = argv[3]; //Give ampl an argv which doesn't crash him. char ** myArgv = new char *[3]; myArgv[0]=new char[strlen(argv[0])+1]; strcpy(myArgv[0],argv[0]); myArgv[1]=new char[strlen(argv[1])+1]; strcpy(myArgv[1],argv[1]); myArgv[2]= NULL;//new char[1]; BonminAmplSetup bonmin; bonmin.initialize(myArgv); Bonmin::OsiTMINLPInterface& nlpSolver = *bonmin.nonlinearSolver(); Ipopt::SmartPtr<Ipopt::OptionsList> Options = nlpSolver.options(); nlpSolver.messageHandler()->setLogLevel(2); try { std::cout<<nodeFileName<<std::endl; // Read the bounds and change them in Ipopt if(argc>2) { Bonmin::BoundsReader bounds(nodeFileName); bounds.readAndApply(&nlpSolver); } if(argc>3) { Bonmin::StartPointReader init(startingPointFile); init.readAndApply(&nlpSolver); } nlpSolver.solver()->forceSolverOutput(4); nlpSolver.initialSolve(); //Print out integer variable values for(int i = 0 ; i <nlpSolver.getNumCols() ; i++) { if (nlpSolver.isInteger(i)) { std::cout<<"x[ "<<i<<"] = "<<nlpSolver.getColSolution()[i]<<std::endl; } } } catch(Bonmin::OsiTMINLPInterface::SimpleError &E) { std::cerr<<E.className()<<"::"<<E.methodName() <<std::endl <<E.message()<<std::endl; } catch(CoinError &E) { std::cerr<<E.className()<<"::"<<E.methodName() <<std::endl <<E.message()<<std::endl; } catch(...) { std::cerr<<pbName<<" unrecognized excpetion"<<std::endl; std::cerr<<pbName<<"\t Finished \t exception"<<std::endl; throw; } delete [] pbName; delete [] myArgv[0]; delete [] myArgv[1]; delete [] myArgv; return 0; }
int main (int argc, char *argv[]) { using namespace Ipopt; char * pbName = NULL; std::cout<<"Bonmin " <<BONMIN_VERSION; std::cout<<" using Cbc " <<CBC_VERSION; std::cout<<" and Ipopt " <<IPOPT_VERSION<<std::endl; if(argc > 1) { pbName = new char[strlen(argv[1])+1]; strcpy(pbName, argv[1]); } #define CATCH_ERRORS #ifdef CATCH_ERRORS try #endif { //FILE * fp = fopen("log","w"); BonminAmplSetup bonmin; bonmin.initialize(argv); { Bab bb; bb(bonmin);//do branch and bound } } #ifdef CATCH_ERRORS catch(TNLPSolver::UnsolvedError *E) { E->writeDiffFiles(); E->printError(std::cerr); //There has been a failure to solve a problem with Ipopt. //And we will output file with information on what has been changed in the problem to make it fail. //Now depending on what algorithm has been called (B-BB or other) the failed problem may be at different place. // const OsiSolverInterface &si1 = (algo > 0) ? nlpSolver : *model.solver(); } catch(OsiTMINLPInterface::SimpleError &E) { std::cerr<<E.className()<<"::"<<E.methodName() <<std::endl <<E.message()<<std::endl; } catch(CoinError &E) { std::cerr<<E.className()<<"::"<<E.methodName() <<std::endl <<E.message()<<std::endl; } catch (Ipopt::OPTION_INVALID &E) { std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl; } catch (Ipopt::IpoptException &E) { std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl; } #ifndef NO_CATCH_ALL catch(...) { std::cerr<<pbName<<" unrecognized exception"<<std::endl; std::cerr<<pbName<<"\t Finished \t exception"<<std::endl; throw; } #endif #endif delete [] pbName; return 0; }