/home/coin/SVN-release/OS-2.0.0/Couenne/src/convex/operators/unifiedProdCuts.cpp

Go to the documentation of this file.
00001 /* $Id: unifiedProdCuts.cpp 141 2009-06-03 04:19:19Z pbelotti $ */
00002 /*
00003  * Name:    unifiedProdCuts.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: unified convexification of products and divisions
00006  *
00007  * (C) Carnegie-Mellon University, 2006. 
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include "CouenneTypes.hpp"
00012 #include "CouennePrecisions.hpp"
00013 #include "CouenneCutGenerator.hpp"
00014 #include "exprDiv.hpp"
00015 #include "exprMul.hpp"
00016 #include "exprPow.hpp"
00017 #include "funtriplets.hpp"
00018 
00019 
00021 
00022 void contourCut (const CouenneCutGenerator *cg,
00023                  OsiCuts &cs, 
00024                  CouNumber xp, CouNumber yp, // current point
00025                  CouNumber wb,               // bound on w
00026                  int sign,                   // is wb lower or upper?
00027                  CouNumber x0, CouNumber y0, // (allegedly) outside point
00028                  CouNumber x1, CouNumber y1, //             inside
00029                  int xi, int yi, int wi) {   // indices of the variables
00030 
00031   // TODO: generalize to two bounds [l,u] for w
00032 
00033   // Upper right corner of the bounding box of (x,y) is feasible,
00034   // the opposite corner is not, hence there is a cut violated by
00035   // (x0,y0).
00036 
00037   // If (x0,y0) is not in the same orthant as the contour in
00038   // question, move it in so that we can apply a Newton step to
00039   // find closest point on contour.
00040 
00041   int xsign = (x1 >= 0) ? 1 : -1, // define orthant where the "inside
00042       ysign = (y1 >= 0) ? 1 : -1; // point" lies
00043 
00044   if      (((xsign > 0) ? xp : -xp) <= COUENNE_EPS)
00045     if    (((ysign > 0) ? yp : -yp) <= COUENNE_EPS) { 
00046 
00047       // opposite orthant, put in the right one where constraint is violated
00048       xp = yp = sqrt (fabs (wb))/2; 
00049       if (xsign<0) xp = -xp;
00050       if (ysign<0) yp = -yp;
00051     }                                                // otherwise, must cross one axis only:
00052     else                                            {xp = sqrt (fabs(wb/yp)); if (xsign<0) xp=-xp;}//y
00053   else if (((ysign > 0) ? yp : -yp) <= COUENNE_EPS) {yp = sqrt (fabs(wb/xp)); if (ysign<0) yp=-yp;}//x
00054 
00055   kpowertriplet pt (-1, wb);
00056 
00057   CouNumber 
00058     // tangent point closest to current point
00059     xt    = powNewton (xp, yp, &pt),
00060     // coefficient of w in the lifted cut
00061     alpha = ((fabs (x1) < COUENNE_INFINITY) && 
00062              (fabs (y1) < COUENNE_INFINITY)) ? 
00063        ((2*wb/xt - y1 - wb*x1 / (xt*xt)) / (x1*y1 - wb)) : 0;
00064 
00065   //  printf ("+++++ %d %d %d. [%c] xp (%g,%g) wb %g out(%g,%g) in(%g,%g) --> [%g,%g] alpha %g\n",
00066   //             xi, yi, wi, (sign<0) ? '-' : '+', xp, yp, wb, x0, y0, x1, y1, xt, wb/xt, alpha);
00067 
00068   if (alpha != 0)
00069     cg     -> createCut (cs, alpha*wb + 2*wb/xt, sign, wi, alpha, yi, 1., xi, wb/(xt*xt));
00070   else  cg -> createCut (cs,            2*wb/xt, sign,            yi, 1., xi, wb/(xt*xt));
00071 }
00072 
00073 
00074 
00075 // Unified procedure to create convexification cuts for an expression of the form w = x*y
00076 void unifiedProdCuts (const CouenneCutGenerator *cg, OsiCuts &cs, 
00077                       int xi, CouNumber x0, CouNumber xl, CouNumber xu,
00078                       int yi, CouNumber y0, CouNumber yl, CouNumber yu,
00079                       int wi, CouNumber w0, CouNumber wl, CouNumber wu,
00080                       t_chg_bounds *chg) {
00081 
00082   bool cLX,  cRX,  cLY,  cRY,  cLW,  cRW = 
00083        cLX = cRX = cLY = cRY = cLW = true;
00084 
00085   if (!(cg -> isFirst ()) && chg) {
00086     cLX= chg[xi].lower() != t_chg_bounds::UNCHANGED; cRX= chg[xi].upper() != t_chg_bounds::UNCHANGED;
00087     cLY= chg[yi].lower() != t_chg_bounds::UNCHANGED; cRY= chg[yi].upper() != t_chg_bounds::UNCHANGED;
00088     cLW= chg[wi].lower() != t_chg_bounds::UNCHANGED; cRW= chg[wi].upper() != t_chg_bounds::UNCHANGED;
00089   }
00090 
00091   // Add McCormick convexification cuts:
00092   //
00093   // 1) w >= yl x + xl y - yl xl
00094   // 2) w >= yu x + xu y - yu xu
00095   //
00096   // 3) w <= yl x + xu y - yl xu
00097   // 4) w <= yu x + xl y - yu xl
00098   //
00099   // These cuts are added if the corresponding bounds are finite
00100 
00101   if ((cLX || cLY) && is_boundbox_regular (yl, xl)) cg -> createCut (cs, yl*xl,-1,wi,-1.,xi,yl,yi,xl);
00102   if ((cRX || cRY) && is_boundbox_regular (yu, xu)) cg -> createCut (cs, yu*xu,-1,wi,-1.,xi,yu,yi,xu);
00103   if ((cRX || cLY) && is_boundbox_regular (yl, xu)) cg -> createCut (cs, yl*xu,+1,wi,-1.,xi,yl,yi,xu);
00104   if ((cLX || cRY) && is_boundbox_regular (yu, xl)) cg -> createCut (cs, yu*xl,+1,wi,-1.,xi,yu,yi,xl);
00105 
00106   // If w=xy and w >= l > 0 (resp. w <= u < 0) are "tight" bounds
00107   // (i.e. they are tighter than those obtained through propagation of
00108   // x and y's bounds), McCormick's convexification is not tight as
00109   // the surface has a curve contour at w=l (resp. w=u).
00110   //
00111   // McCormick rules induce a tangent to this contour at the bounds of
00112   // both variables, but it may be useful to add further cuts along
00113   // the contour to eliminate infeasible point (x0,y0,w0), which may
00114   // be in the convexification but out of the contour (on its "convex"
00115   // side, or "out of the belly").
00116   //
00117   // Suppose P (xt,l/xt) (resp. (xt,u/xt) is the point on the contour
00118   // closest to (x0,y0), found through a Newton method. The cut is
00119   // tangent to the contour in P and has the form
00120   //
00121   //        y - l/xt >= -l/(xt^2) (x-xt)   if xl*yl < l and xu*yu > l
00122   //        y - l/xt <= -l/(xt^2) (x-xt)   if xl*yl > l and xu*yu < l
00123   //
00124   // (resp. y - u/xt <= -u/(xt^2) (x-xt)   if xl*yu > u and xu*yl < u
00125   //        y - u/xt >= -u/(xt^2) (x-xt)   if xl*yu < u and xu*yl > u)
00126   //
00127   // These can be lifted to satisfy, at equality, the point
00128   // (xu,yu,wu=xu*yu) (resp. (xl,yl,wl=xl*yl)), where xl and xu are
00129   // lower and upper bound of x, etc.
00130   //
00131   //        alpha (w - l) + y - l/xt >= -l/(xt^2) (x-xt) ...
00132   //
00133   // where alpha is such that the relation holds at equality at the
00134   // point (xu,yu,xu*yu):
00135   //
00136   //    alpha = [-yu + l/xt - l/(xt^2)(xu-xt)] / (xu*yu - l)
00137 
00138   if ((x0 > xl + COUENNE_EPS) && (y0 > yl + COUENNE_EPS) &&
00139       (x0 < xu + COUENNE_EPS) && (y0 < yu + COUENNE_EPS)) {
00140 
00141     if (cLW && (wl > 0) && (x0*y0 < wl)) { // that is, if (x0,y0) is out of the contour
00142 
00143       CouNumber xyl = xl * yl;
00144 
00145       // first and third orthant
00146       if      ((xyl <  wl) && (xu*yu >=wl)) contourCut (cg,cs, x0,y0, wl, +1, xl,yl, xu,yu, xi,yi,wi);
00147       else if ((xyl >= wl) && (xu*yu < wl)) contourCut (cg,cs, x0,y0, wl, -1, xu,yu, xl,yl, xi,yi,wi);
00148     }
00149 
00150   // Similarly for w <= u < 0 
00151 
00152     if (cRW && (wu < 0) && (x0*y0 > wu)) { // that is, if (x0,y0) is out of the contour
00153 
00154       CouNumber xuyl = xl * yu;
00155 
00156       // second and fourth orthant
00157       if      ((xuyl > wu) && (xl*yu <=wu)) contourCut (cg,cs, x0,y0, wu, +1, xu,yl, xl,yu, xi,yi,wi);
00158       else if ((xuyl <=wu) && (xl*yu > wu)) contourCut (cg,cs, x0,y0, wu, -1, xl,yu, xu,yl, xi,yi,wi);
00159     }
00160   }
00161 }

Generated on Mon Aug 3 03:02:19 2009 by  doxygen 1.4.7