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