00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #if defined(_MSC_VER)
00015
00016 # pragma warning(disable:4786)
00017 #endif
00018 #include <iomanip>
00019 #include <fstream>
00020
00021 #include <stdlib.h>
00022
00023 #include "CoinTime.hpp"
00024 #include "CoinError.hpp"
00025 #include "BonCouenneInterface.hpp"
00026
00027 #include "BonCouenneSetup.hpp"
00028
00029 #include "BonCbc.hpp"
00030 #ifdef COIN_HAS_FILTERSQP
00031 #include "BonFilterSolver.hpp"
00032 #endif
00033
00034 #include "CbcCutGenerator.hpp"
00035 #include "CouenneProblem.hpp"
00036 #include "CouenneCutGenerator.hpp"
00037
00038 using namespace Bonmin;
00039
00040
00041 #define PRINTED_PRECISION 1e-5
00042
00043 #include "exprVar.hpp"
00044 #include "exprConst.hpp"
00045 #include "exprSum.hpp"
00046 #include "exprClone.hpp"
00047 #include "CouenneProblemElem.hpp"
00048 #include "CouenneProblem.hpp"
00049
00050 int main (int argc, char *argv[]) {
00051
00052
00053 using namespace Ipopt;
00054
00055 char * pbName = NULL;
00056 double time_start = CoinCpuTime();
00057
00058 const int infeasible = 1;
00059
00060 try {
00061
00062 Bab bb;
00063 bb.setUsingCouenne (true);
00064
00065 CouenneProblem *p = NULL;
00066 CouenneInterface *ci = NULL;
00067
00068 #if 0
00069 ci = new CouenneInterface;
00070 p = new CouenneProblem;
00071
00072 p -> addVariable (false, p -> domain ());
00073 p -> addVariable (false, p -> domain ());
00074 p -> addVariable (false, p -> domain ());
00075 p -> addVariable (false, p -> domain ());
00076
00077 p -> addObjective (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))), "min");
00078 p -> addLEConstraint (new exprSum (new exprClone (p->Var (0)), new exprClone (p->Var (2))),
00079 new exprConst (1));
00080 p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (2))),
00081 new exprConst (1));
00082 p -> addEQConstraint (new exprSum (new exprClone (p->Var (1)), new exprClone (p->Var (3))),
00083 new exprConst (1));
00084 p -> addEQConstraint (new exprSum (new exprClone (p->Var (2)), new exprClone (p->Var (3))),
00085 new exprConst (1));
00086 #endif
00087
00088 CouenneSetup couenne;
00089 if (!couenne.InitializeCouenne (argv, p, ci))
00090 throw infeasible;
00091
00092 #if 0
00093 CouenneFeasibility feasibility;
00094 bb.model().setProblemFeasibility (feasibility);
00095 #endif
00096
00098 double timeLimit = 0;
00099 couenne.options () -> GetNumericValue ("time_limit", timeLimit, "couenne.");
00100 couenne.setDoubleParameter (BabSetupBase::MaxTime,
00101 timeLimit - (time_start = (CoinCpuTime () - time_start)));
00102
00104
00105 bb (couenne);
00106
00108
00109 std::cout.precision (10);
00110
00112 CouenneCutGenerator *cg = NULL;
00113
00114 if (bb.model (). cutGenerators ())
00115 cg = dynamic_cast <CouenneCutGenerator *>
00116 (bb.model (). cutGenerators () [0] -> generator ());
00117
00119 int nr=-1, nt=-1;
00120 double st=-1;
00121
00122 if (cg) cg -> getStats (nr, nt, st);
00123 else printf ("Warning, could not get pointer to CouenneCutGenerator\n");
00124
00125 CouenneProblem *cp = cg ? cg -> Problem () : NULL;
00126
00127
00128 double global_opt;
00129 couenne.options () -> GetNumericValue ("couenne_check", global_opt, "couenne.");
00130
00131 if (global_opt < COUENNE_INFINITY) {
00132
00133 double opt = bb.model (). getBestPossibleObjValue ();
00134
00135 printf ("Global Optimum Test on %-40s %s\n",
00136 cp ? cp -> problemName ().c_str () : "unknown",
00137 (fabs (opt - global_opt) /
00138 (1. + CoinMax (fabs (opt), fabs (global_opt))) < PRINTED_PRECISION) ?
00139 (const char *) "OK" : (const char *) "FAILED");
00140
00141
00142
00143 } else
00144
00145 if (couenne.displayStats ()) {
00146
00147
00148
00149 if (cg && !cp) printf ("Warning, could not get pointer to problem\n");
00150 else
00151 printf ("Stats: %-15s %4d [var] %4d [int] %4d [con] %4d [aux] "
00152 "%6d [root] %8d [tot] %6g [sep] %8g [time] %8g [bb] "
00153 "%20e [lower] %20e [upper] %7d [nodes]\n",
00154 cp ? cp -> problemName ().c_str () : "unknown",
00155 (cp) ? cp -> nOrigVars () : -1,
00156 (cp) ? cp -> nOrigIntVars () : -1,
00157 (cp) ? cp -> nOrigCons () : -1,
00158 (cp) ? (cp -> nVars () -
00159 cp -> nOrigVars ()): -1,
00160 nr, nt, st,
00161 CoinCpuTime () - time_start,
00162 cg ? (CoinCpuTime () - cg -> rootTime ()) : CoinCpuTime (),
00163 bb.model (). getBestPossibleObjValue (),
00164 bb.model (). getObjValue (),
00165
00166
00167 bb.numNodes ());
00168
00169
00170 }
00171
00172
00173 }
00174 catch(TNLPSolver::UnsolvedError *E) {
00175 E->writeDiffFiles();
00176 E->printError(std::cerr);
00177
00178
00179
00180
00181 }
00182 catch(OsiTMINLPInterface::SimpleError &E) {
00183 std::cerr<<E.className()<<"::"<<E.methodName()
00184 <<std::endl
00185 <<E.message()<<std::endl;
00186 }
00187 catch(CoinError &E) {
00188 std::cerr<<E.className()<<"::"<<E.methodName()
00189 <<std::endl
00190 <<E.message()<<std::endl;
00191 }
00192 catch (Ipopt::OPTION_INVALID &E)
00193 {
00194 std::cerr<<"Ipopt exception : "<<E.Message()<<std::endl;
00195 }
00196 catch (int generic_error) {
00197 if (generic_error == infeasible)
00198 printf ("problem infeasible\n");
00199 }
00200
00201
00202
00203
00204
00205
00206
00207 delete [] pbName;
00208 return 0;
00209 }