MyBonmin.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iomanip>
00012 #include <fstream>
00013
00014 #include "CoinPragma.hpp"
00015 #include "CoinTime.hpp"
00016 #include "CoinError.hpp"
00017
00018 #include "BonOsiTMINLPInterface.hpp"
00019 #include "BonIpoptSolver.hpp"
00020 #include "MyTMINLP.hpp"
00021 #include "BonCbc.hpp"
00022 #include "BonBonminSetup.hpp"
00023
00024 #include "BonOACutGenerator2.hpp"
00025 #include "BonEcpCuts.hpp"
00026 #include "BonOaNlpOptim.hpp"
00027
00028
00029 int main (int argc, char *argv[])
00030 {
00031 WindowsErrorPopupBlocker();
00032
00033 using namespace Ipopt;
00034 using namespace Bonmin;
00035 SmartPtr<MyTMINLP> tminlp = new MyTMINLP;
00036
00037 #ifdef REDIRECT
00038 FILE * fp = fopen("log.out","w");
00039 CoinMessageHandler handler(fp);
00040 BonminSetup bonmin(&handler);
00041 #else
00042 BonminSetup bonmin;
00043 #endif
00044 bonmin.initializeOptionsAndJournalist();
00045
00046 bonmin.roptions()->AddStringOption2("print_solution","Do we print the solution or not?",
00047 "yes",
00048 "no", "No, we don't.",
00049 "yes", "Yes, we do.",
00050 "A longer comment can be put here");
00051
00052
00053
00054
00055 bonmin.options()->SetNumericValue("bonmin.time_limit", 5);
00056 bonmin.options()->SetStringValue("mu_oracle","loqo");
00057
00058
00059 bonmin.readOptionsFile("Mybonmin.opt");
00060 bonmin.readOptionsFile();
00061
00062
00063 bonmin.readOptionsString("bonmin.algorithm B-BB\n");
00064
00065
00066 int printSolution;
00067 bonmin.options()->GetEnumValue("print_solution", printSolution,"");
00068 if(printSolution == 1){
00069 tminlp->printSolutionAtEndOfAlgorithm();
00070 }
00071
00072
00073 bonmin.initialize(GetRawPtr(tminlp));
00074
00075
00076
00077
00078 try {
00079 Bab bb;
00080 bb(bonmin);
00081
00082
00083 }
00084 catch(TNLPSolver::UnsolvedError *E) {
00085
00086 std::cerr<<"Ipopt has failed to solve a problem"<<std::endl;
00087 }
00088 catch(OsiTMINLPInterface::SimpleError &E) {
00089 std::cerr<<E.className()<<"::"<<E.methodName()
00090 <<std::endl
00091 <<E.message()<<std::endl;
00092 }
00093 catch(CoinError &E) {
00094 std::cerr<<E.className()<<"::"<<E.methodName()
00095 <<std::endl
00096 <<E.message()<<std::endl;
00097 }
00098
00099
00100 return 0;
00101 }
00102