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

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

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