00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "CglCutGenerator.hpp"
00013 #include "CoinHelperFunctions.hpp"
00014
00015 #include "CouenneCutGenerator.hpp"
00016 #include "CouenneProblem.hpp"
00017 #include "CouenneExprVar.hpp"
00018
00019 namespace Couenne {
00020
00021 bool isOptimumCut (const CouNumber *opt, OsiCuts &cs, CouenneProblem *p) {
00022
00023 bool retval = false;
00024
00025
00026
00027 if (cs.sizeColCuts ()) {
00028
00029
00030
00031 for (int i = cs.sizeColCuts (); i--;) {
00032
00033
00034
00035 const CoinPackedVector &lbs = cs.colCutPtr (i) -> lbs ();
00036 const int *lindices = lbs.getIndices ();
00037 const double *lvalues = lbs.getElements ();
00038
00039 for (int j = lbs.getNumElements (); j--;) {
00040 register double lb = *lvalues++;
00041 register int ind = *lindices++;
00042
00043 if (lb > opt [ind] + COUENNE_EPS) {
00044 printf ("################################## new lb [%d] = %g cuts opt %g by %g\n",
00045 ind, lb, opt [ind], lb - opt [ind]);
00046 retval = true;
00047 }
00048 }
00049
00050
00051
00052 const CoinPackedVector &ubs = cs.colCutPtr (i) -> ubs ();
00053 const int *uindices = ubs.getIndices ();
00054 const double *uvalues = ubs.getElements ();
00055
00056 for (int j = ubs.getNumElements (); j--;) {
00057 register double ub = *uvalues++;
00058 register int ind = *uindices++;
00059
00060 if (ub < opt [ind] - COUENNE_EPS) {
00061 printf ("################################## new ub [%d] = %g cuts opt %g by %g\n",
00062 ind, ub, opt [ind], opt [ind] - ub);
00063 retval = true;
00064 }
00065 }
00066 }
00067 }
00068
00069
00070
00071 if (cs.sizeRowCuts ()) {
00072
00073
00074
00075 for (int jj=0; jj < cs.sizeRowCuts (); jj++) {
00076
00077 OsiRowCut *cut = cs.rowCutPtr (jj);
00078 CoinPackedVector row = cut -> row ();
00079
00080 int n = cut -> row (). getNumElements();
00081 const double *el = row. getElements ();
00082 const int *ind = row. getIndices ();
00083
00084 double lb = cut -> lb ();
00085 double ub = cut -> ub ();
00086
00087 double lhs = 0;
00088
00089 while (n--)
00090 lhs += el [n] * opt [ind [n]];
00091
00092
00093 if ((lhs < lb - COUENNE_EPS) ||
00094 (lhs > ub + COUENNE_EPS)) {
00095
00096 printf ("################################## new cut [%d] [%g,%g] cuts opt %g by %g:",
00097 jj, lb, ub, lhs, CoinMax (lb - lhs, lhs - ub));
00098
00099 cut -> print ();
00100 retval = true;
00101 }
00102 }
00103 }
00104
00105 if (retval) {
00106
00107 printf ("== genrowcuts on LP =============");
00108
00109 for (int i = 0; i < p -> nVars (); i++) {
00110 if (!(i % 3))
00111 printf ("\n");
00112 if (p -> Var (i) -> Multiplicity () > 0)
00113 printf ("%3d %+10.3g [%+10.3g,%+10.3g] ", i,
00114 p -> X (i),
00115 p -> Lb (i),
00116 p -> Ub (i));
00117 }
00118
00119 printf ("\n=============================\n");
00120 }
00121
00122 return retval;
00123 }
00124
00125 }