/home/coin/SVN-release/OS-2.4.0/Couenne/src/problem/CouenneLPtightenBounds.cpp

Go to the documentation of this file.
00001 /* $Id: CouenneLPtightenBounds.cpp 490 2011-01-14 16:07:12Z pbelotti $
00002  *
00003  * Name:    CouenneLPtightenBounds.cpp
00004  * Authors: Pietro Belotti, Carnegie Mellon University
00005  * Purpose: tighten LP bounds on all variables (including continuous)
00006  *
00007  * (C) Carnegie-Mellon University, 2008-09.
00008  * This file is licensed under the Eclipse Public License (EPL)
00009  */
00010 
00011 #include "CouenneProblem.hpp"
00012 #include "CouenneCutGenerator.hpp"
00013 
00014 namespace Couenne {
00015 
00016 // Tighten bounds - lightweight. Returns -1 if infeasible, otherwise
00017 // number of variables tightened.
00018 template <class T> 
00019 int CouenneSolverInterface<T>::tightenBounds (int lightweight) {
00020 
00021   if (!(cutgen_ -> enableLpImpliedBounds ()))
00022     return 0;
00023 
00024   int 
00025     ncols = T::getNumCols (),
00026     nTightened;
00027 
00028   double 
00029     *oldLower = new double [ncols],
00030     *oldUpper = new double [ncols];
00031 
00032   CoinCopyN (T::getColLower (), ncols, oldLower);
00033   CoinCopyN (T::getColUpper (), ncols, oldUpper);
00034 
00035 //   printf ("-------- BOUNDS BEFORE ------------\n  ");
00036 //   int j=0;
00037 //   for (int i=0; i < ncols; i++) {
00038 //     printf("x_%03d [%+15.8g %+15.8g] ", i, oldLower [i], oldUpper [i]);
00039 //     if (!(++j % 6)) printf ("\n  ");
00040 //   }
00041 //   if (j % 6) printf ("\n");
00042 
00043   nTightened = tightenBoundsCLP (lightweight);
00044 
00045   if (nTightened < 0)
00046     return nTightened;
00047 
00048 //   printf ("-------- BOUNDS DURING ------------\n  ");
00049 //   j=0;
00050 //   for (int i=0; i < ncols; i++) {
00051 //     printf("x_%03d [%+15.8g %+15.8g] ", i, getColLower () [i], getColUpper () [i]);
00052 //     if (!(++j % 6)) printf ("\n  ");
00053 //   }
00054 //   if (j % 6) printf ("\n");
00055 
00056   if (nTightened > 0) {
00057 
00058     // something was tightened. Run an extra btCore "por si las
00059     // moscas" (just in case)
00060 
00061     const double 
00062       *newLower = T::getColLower (),
00063       *newUpper = T::getColUpper ();
00064 
00065     t_chg_bounds *chgd = new t_chg_bounds [ncols];
00066 
00067     for (int i=0; i<ncols; i++) {
00068       if (newLower [i] > oldLower [i] + COUENNE_EPS) chgd [i].setLower (t_chg_bounds::CHANGED);
00069       if (newUpper [i] < oldUpper [i] - COUENNE_EPS) chgd [i].setUpper (t_chg_bounds::CHANGED);
00070     }
00071 
00072     cutgen_ -> Problem () -> domain () -> push (ncols, NULL, newLower, newUpper);
00073 
00074     if (!(cutgen_ -> Problem () -> btCore (chgd))) // infeasible
00075       nTightened = -1;
00076 
00077     else {
00078 
00079       const double 
00080         *newerLower = cutgen_ -> Problem () -> Lb (),
00081         *newerUpper = cutgen_ -> Problem () -> Ub ();
00082 
00083       for (int i=0; i<ncols; i++) {
00084 
00085         if (newerLower [i] > newLower [i] + COUENNE_EPS) {
00086           T::setColLower (i, newerLower [i]);
00087           if (newLower [i] < oldLower [i] + COUENNE_EPS) nTightened++; // extra tightening
00088         }
00089 
00090         if (newerUpper [i] < newUpper [i] - COUENNE_EPS) {
00091           T::setColUpper (i, newerUpper [i]);
00092           if (newUpper [i] > oldUpper [i] - COUENNE_EPS) nTightened++; // extra tightening
00093         }
00094       }
00095     }
00096 
00097 //     const double 
00098 //       *newerLower = cutgen_ -> Problem () -> Lb (),
00099 //       *newerUpper = cutgen_ -> Problem () -> Ub ();
00100 
00101 //     printf ("-------- BOUNDS AFTER ------------\n  ");
00102 //     for (int i=0; i < ncols; i++) {
00103 //       printf("x_%03d [%+15.8g %+15.8g] ", i, newerLower [i], newerUpper [i]);
00104 //       if (!(++j % 6)) printf ("\n  ");
00105 //     }
00106 //     if (j % 6) printf ("\n");
00107 
00108     cutgen_ -> Problem () -> domain () -> pop ();
00109 
00110     delete [] chgd;
00111   }
00112 
00113   delete [] oldLower;
00114   delete [] oldUpper;
00115 
00116   return nTightened;
00117 }
00118 
00119 }

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