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

Go to the documentation of this file.
00001 /* $Id: isOptimumCut.cpp 490 2011-01-14 16:07:12Z 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 Eclipse Public License (EPL)
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   // Column cuts ////////////////////////////////////////////////////////////////////////
00026 
00027   if (cs.sizeColCuts ()) {
00028 
00029     //printf ("Checking col cuts:\n");
00030 
00031     for (int i = cs.sizeColCuts (); i--;) {
00032 
00033       // lower bounds
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       // upper bounds
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   // Row cuts ///////////////////////////////////////////////////////////////////////////
00070 
00071   if (cs.sizeRowCuts ()) {
00072 
00073     //printf ("Checking row cuts:\n");
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 }

Generated on Thu Sep 22 03:05:56 2011 by  doxygen 1.4.7