/home/coin/SVN-release/OS-2.4.2/Couenne/src/bound_tightening/impliedBounds.cpp

Go to the documentation of this file.
00001 /* $Id: impliedBounds.cpp 532 2011-03-13 00:33:20Z pbelotti $
00002  *
00003  * Name:    impliedBounds.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: backward implied bound search
00006  *
00007  * (C) Carnegie-Mellon University, 2006-10. 
00008  * This file is licensed under the Eclipse Public License (EPL)
00009  */
00010 
00011 #include "CoinHelperFunctions.hpp"
00012 
00013 #include "CouenneProblem.hpp"
00014 #include "CouenneExprVar.hpp"
00015 
00016 using namespace Couenne;
00017 
00019 
00020 int CouenneProblem::impliedBounds (t_chg_bounds *chg_bds) const {
00021 
00022   int nchg = 0; //< number of bounds changed for propagation
00023 
00024   CouNumber *knownOptimum = optimum_;
00025 
00026   if (optimum_) {
00027 
00028     for (int i=nVars(); i--; knownOptimum++)
00029 
00030       if (*knownOptimum < Lb (i) || 
00031           *knownOptimum > Ub (i)) {
00032 
00033         knownOptimum = NULL;
00034         break;
00035       }
00036 
00037     if (knownOptimum) 
00038       knownOptimum -= nVars ();
00039   }
00040 
00041   if (Jnlst()->ProduceOutput(Ipopt::J_DETAILED, J_BOUNDTIGHTENING)) {  
00042     Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING,"  backward =====================\n  ");
00043     int j=0;
00044     for (int i=0; i < nVars (); i++) 
00045       if (variables_ [i] -> Multiplicity () >= 0) {
00046         Jnlst()->Printf(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING,
00047                         "x_%03d [%+10g %+10g] ", i, 
00048                         domain_.lb (i),
00049                         domain_.ub (i));
00050         if (!(++j % 6)) Jnlst()->Printf(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING,"\n  ");
00051       }
00052     if (j % 6) Jnlst()->Printf(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING,"\n");
00053   }
00054 
00055   for (int ii = nVars (); ii--;) {
00056 
00057     int i = numbering_ [ii];
00058 
00059     if (Lb (i) > Ub (i) &&
00060         (Lb (i) < Ub (i) + COUENNE_BOUND_PREC * (1 + CoinMin (fabs (Lb (i)), fabs (Ub (i)))))) {
00061 
00062       // This is to prevent very tiny infeasibilities to propagate
00063       // down and make the problem infeasible. Example pointed out in
00064       // http://list.coin-or.org/pipermail/couenne/2010-October/000145.html
00065 
00066       CouNumber tmp = Lb (i);
00067       Lb (i)        = Ub (i);
00068       Ub (i)        = tmp;
00069     }
00070 
00071     if ((variables_ [i] -> Type () == AUX) &&
00072         (variables_ [i] -> Multiplicity () > 0)) {
00073 
00074       if (Lb (i) > Ub (i) + COUENNE_BOUND_PREC * (1 + CoinMin (fabs (Lb (i)), fabs (Ub (i))))) {
00075         Jnlst () -> Printf (Ipopt::J_DETAILED, J_BOUNDTIGHTENING,
00076                             "  implied bounds: w_%d has infeasible bounds [%g,%g]\n", 
00077                             i, Lb (i), Ub (i));
00078         return -1;
00079       }
00080 
00081       // TODO: also test if this expression, or any of its indep
00082       // variables, have changed. If not, skip
00083 
00084       CouNumber 
00085         l0 = Lb (i), 
00086         u0 = Ub (i);
00087 
00088       if (variables_ [i] -> Image () -> impliedBound 
00089           (variables_ [i] -> Index (), Lb (), Ub (), chg_bds, variables_ [i] -> sign ())) {
00090 
00091         // conservative check for integer variables. 
00092         /*if (Var (i) -> isInteger ()) {
00093           Lb (i) = ceil  (Lb (i) - COUENNE_EPS);
00094           Ub (i) = floor (Ub (i) + COUENNE_EPS);
00095           }*/
00096 
00097         if (Jnlst()->ProduceOutput(Ipopt::J_VECTOR, J_BOUNDTIGHTENING)) {
00098           // todo: send all output through journalist
00099           Jnlst()->Printf(Ipopt::J_VECTOR, J_BOUNDTIGHTENING,
00100                           "  impli %2d [%15.8g, %15.8g] -> [%15.8g, %15.8g]: ",
00101                           i, l0, u0, Lb (i), Ub (i));
00102 
00103           variables_ [i] -> print (std::cout);
00104 
00105           if (Jnlst()->ProduceOutput(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING)) {
00106             Jnlst()->Printf(Ipopt::J_MOREVECTOR, J_BOUNDTIGHTENING," := ");
00107             variables_ [i] -> Image () -> print (std::cout);
00108           }
00109 
00110           Jnlst()->Printf(Ipopt::J_VECTOR, J_BOUNDTIGHTENING,"\n");
00111         }
00112 
00113         if (knownOptimum && 
00114             ((knownOptimum [i] < Lb (i) - COUENNE_EPS) ||
00115              (knownOptimum [i] > Ub (i) + COUENNE_EPS)))
00116 
00117           Jnlst () -> Printf (Ipopt::J_DETAILED, J_BOUNDTIGHTENING,
00118                               "#### implied b_%d [%g,%g] cuts optimum %g\n",
00119                               i, Lb (i), Ub (i), 
00120                               knownOptimum [i]);
00121 
00122         //printf ("impli %2d ", nvar+i);
00123 
00124         /*if (variables_ [i] -> Image () -> Argument () || 
00125             variables_ [i] -> Image () -> ArgList ()) {
00126 
00127           expression *arg = variables_ [i] -> Image () -> Argument ();
00128 
00129           if (!arg) {
00130             for (int k=0; k < variables_ [i] -> Image () -> nArgs (); k++) {
00131               arg =  variables_ [i] -> Image () -> ArgList () [k];
00132               Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING," ");
00133               arg -> print (std::cout);
00134               if (arg -> Index () >= 0) {
00135                 int ind = arg -> Index ();
00136                 Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING,
00137                                 " in [%g,%g]", 
00138                                 expression::Lbound (ind), 
00139                                 expression::Ubound (ind));
00140               }     
00141             }
00142           } else {
00143             Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING," ");
00144             arg -> print (std::cout);
00145             if (arg -> Index () >= 0) {
00146               int ind = arg -> Index ();
00147               Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING," in [%g,%g]", 
00148                       expression::Lbound (ind), 
00149                       expression::Ubound (ind));
00150             }
00151           }
00152         } else Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING," [no args]");
00153         Jnlst()->Printf(Ipopt::J_DETAILED, J_BOUNDTIGHTENING,"\n");*/
00154 
00155         nchg++;
00156       }
00157     }
00158   }
00159 
00160   if (nchg)
00161     Jnlst () -> Printf (Ipopt::J_DETAILED, J_BOUNDTIGHTENING, "  implied bounds: %d changes\n", nchg);
00162 
00163   return nchg;
00164 }

Generated on Wed Nov 30 03:03:57 2011 by  doxygen 1.4.7