/home/coin/SVN-release/OS-2.1.0/Couenne/src/bound_tightening/operators/impliedBounds-sum.cpp

Go to the documentation of this file.
00001 /* $Id: impliedBounds-sum.cpp 141 2009-06-03 04:19:19Z pbelotti $ */
00002 /*
00003  * Name:    impliedBounds-sum.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: inferring bounds on monomials in a sum
00006  *
00007  * (C) Carnegie-Mellon University, 2006. 
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include <vector>
00012 
00013 #include "CoinHelperFunctions.hpp"
00014 #include "exprSum.hpp"
00015 
00016 #define ALMOST_INF (1e-5 * COUENNE_INFINITY)
00017 
00018 int exprSum::impliedBoundSum (CouNumber wl, 
00019                               CouNumber wu, 
00020                               std::vector <CouNumber> &xl,
00021                               std::vector <CouNumber> &xu,
00022                               std::vector <std::pair <int, CouNumber> > &nl,
00023                               std::vector <std::pair <int, CouNumber> > &nu) {
00024   CouNumber 
00025     sumLB = 0,
00026     sumUB = 0;
00027 
00028   int 
00029     nImpr = 0,
00030     n     = xl.size (), 
00031     infLo = -1, 
00032     infUp = -1;
00033 
00034   // check lower bounds
00035   for (int i=0; i<n; i++) {
00036     CouNumber l = xl [i];
00037     if (l < -ALMOST_INF) 
00038       if (infLo >= 0) {infLo = -2; break;}
00039       else infLo = i;
00040     else sumLB += l;
00041   }
00042 
00043   // check upper bounds
00044   for (int i=0; i<n; i++) {
00045     CouNumber u = xu [i];
00046     if (u > ALMOST_INF) 
00047       if (infUp >= 0) {infUp = -2; break;}
00048       else infUp = i;
00049     else sumUB += u;
00050   }
00051 
00052   // if more than two unbounded quantities on both sides, bail out
00053   if ((infUp == -2) && 
00054       (infLo == -2)) 
00055     return 0;
00056 
00057   // new lower bounds ////////////////////////////////////////////////////
00058 
00059   if (infLo == -1) { // none of the "first" components is unbounded from below
00060 
00061     for (int i=0; i<n; i++) {
00062 
00063       CouNumber nb = wu - sumLB + xl [i];
00064       if (nb < xu [i]) {
00065         nu.push_back (std::pair <int, CouNumber> (i, nb));
00066         nImpr ++;
00067       }
00068     }   
00069 
00070   } else if (infLo >= 0) { // exactly one of them is, can improve bound on that one only
00071   
00072     CouNumber nb = wu - sumLB;
00073     if (nb < xu [infLo]) {
00074       nu.push_back (std::pair <int, CouNumber> (infLo, nb));
00075       nImpr ++;
00076     }
00077   }
00078 
00079   // new upper bounds ////////////////////////////////////////////////////
00080  
00081   if (infUp == -1) { // none of the "first" components is unbounded from below
00082 
00083     for (int i=0; i<n; i++) {
00084 
00085       CouNumber nb = wl - sumUB + xu [i];
00086       if (nb > xl [i]) {
00087         nl.push_back (std::pair <int, CouNumber> (i, nb));
00088         nImpr ++;
00089       }
00090     }   
00091 
00092   } else if (infUp >= 0) { // exactly one of them is, can improve bound on that one only
00093   
00094     CouNumber nb = wl - sumUB;
00095     if (nb < xl [infLo]) {
00096       nl.push_back (std::pair <int, CouNumber> (infUp, nb));
00097       nImpr ++;
00098     }
00099   }
00100 
00101   return nImpr;
00102 }

Generated on Tue Mar 30 03:04:36 2010 by  doxygen 1.4.7