/home/coin/SVN-release/OS-2.2.0/Couenne/src/convex/isOptimumCut.cpp

Go to the documentation of this file.
00001 /* $Id: isOptimumCut.cpp 215 2009-07-08 15:43:38Z pbelotti $
00002  *
00003  * Name:    isOptimumCut.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: check if known optimal solution (read from .txt) is
00006  *          erroneously cut by the row/col cuts we've added
00007  *
00008  * (C) Carnegie-Mellon University, 2009.
00009  * This file is licensed under the Common Public License (CPL)
00010  */
00011 
00012 #include "CglCutGenerator.hpp"
00013 #include "CoinHelperFunctions.hpp"
00014 
00015 #include "CouenneCutGenerator.hpp"
00016 #include "CouenneProblem.hpp"
00017 
00018 
00019 bool isOptimumCut (const CouNumber *opt, OsiCuts &cs, CouenneProblem *p) {
00020 
00021   bool retval = false;
00022 
00023   // Column cuts ////////////////////////////////////////////////////////////////////////
00024 
00025   if (cs.sizeColCuts ()) {
00026 
00027     //printf ("Checking col cuts:\n");
00028 
00029     for (int i = cs.sizeColCuts (); i--;) {
00030 
00031       // lower bounds
00032 
00033       const CoinPackedVector &lbs = cs.colCutPtr (i) -> lbs ();
00034       const int    *lindices = lbs.getIndices ();
00035       const double *lvalues  = lbs.getElements ();
00036 
00037       for (int j = lbs.getNumElements (); j--;) {
00038         register double lb  = *lvalues++;
00039         register int    ind = *lindices++;
00040 
00041         if (lb > opt [ind] + COUENNE_EPS) {
00042           printf ("################################## new lb [%d] = %g cuts opt %g by %g\n",
00043                   ind, lb, opt [ind], lb - opt [ind]);
00044           retval = true;
00045         }
00046       }
00047 
00048       // upper bounds
00049 
00050       const CoinPackedVector &ubs = cs.colCutPtr (i) -> ubs ();
00051       const int    *uindices = ubs.getIndices ();
00052       const double *uvalues  = ubs.getElements ();
00053 
00054       for (int j = ubs.getNumElements (); j--;) {
00055         register double ub  = *uvalues++;
00056         register int    ind = *uindices++;
00057 
00058         if (ub < opt [ind] - COUENNE_EPS) {
00059           printf ("################################## new ub [%d] = %g cuts opt %g by %g\n",
00060                   ind, ub, opt [ind], opt [ind] - ub);
00061           retval = true;
00062         }
00063       }
00064     }
00065   }
00066 
00067   // Row cuts ///////////////////////////////////////////////////////////////////////////
00068 
00069   if (cs.sizeRowCuts ()) {
00070 
00071     //printf ("Checking row cuts:\n");
00072 
00073     for (int jj=0; jj < cs.sizeRowCuts (); jj++) {
00074 
00075       OsiRowCut        *cut = cs.rowCutPtr (jj);
00076       CoinPackedVector  row = cut -> row ();
00077 
00078       int           n   = cut -> row (). getNumElements();
00079       const double *el  = row. getElements ();
00080       const int    *ind = row. getIndices ();
00081 
00082       double        lb  = cut -> lb ();
00083       double        ub  = cut -> ub ();
00084 
00085       double lhs = 0;
00086 
00087       while (n--) 
00088         lhs += el [n] * opt [ind [n]];
00089 
00090 
00091       if ((lhs < lb - COUENNE_EPS) || 
00092           (lhs > ub + COUENNE_EPS)) {
00093 
00094         printf ("################################## new cut [%d] [%g,%g] cuts opt %g by %g:",
00095                 jj, lb, ub, lhs, CoinMax (lb - lhs, lhs - ub));
00096 
00097         cut -> print ();
00098         retval = true;
00099       }
00100     }
00101   }
00102 
00103   if (retval) {
00104 
00105     printf ("== genrowcuts on LP =============");
00106 
00107     for (int i = 0; i < p -> nVars (); i++) {
00108       if (!(i % 3)) 
00109         printf ("\n");
00110       if (p -> Var (i) -> Multiplicity () > 0)
00111         printf ("%3d %+10.3g [%+10.3g,%+10.3g] ", i,
00112                 p -> X  (i),
00113                 p -> Lb (i),
00114               p -> Ub (i));
00115     }
00116 
00117     printf ("\n=============================\n");
00118   }
00119 
00120   return retval;
00121 }

Generated on Thu Aug 5 03:02:56 2010 by  doxygen 1.4.7