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

Go to the documentation of this file.
00001 /* $Id$
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 Common Public License (CPL)
00009  */
00010 
00011 #include "CoinHelperFunctions.hpp"
00012 #include "CouenneProblem.hpp"
00013 #include "CouenneSolverInterface.hpp"
00014 
00015 // Tighten bounds - lightweight. Returns -1 if infeasible, otherwise
00016 // number of variables tightened.
00017 int CouenneSolverInterface::tightenBounds (int lightweight) {
00018 
00019   if (!(cutgen_ -> enableLpImpliedBounds ()))
00020     return 0;
00021 
00022   int 
00023     ncols = getNumCols (),
00024     nTightened;
00025 
00026   double 
00027     *oldLower = new double [ncols],
00028     *oldUpper = new double [ncols];
00029 
00030   CoinCopyN (getColLower (), ncols, oldLower);
00031   CoinCopyN (getColUpper (), ncols, oldUpper);
00032 
00033 //   printf ("-------- BOUNDS BEFORE ------------\n  ");
00034 //   int j=0;
00035 //   for (int i=0; i < ncols; i++) {
00036 //     printf("x_%03d [%+15.8g %+15.8g] ", i, oldLower [i], oldUpper [i]);
00037 //     if (!(++j % 6)) printf ("\n  ");
00038 //   }
00039 //   if (j % 6) printf ("\n");
00040 
00041   nTightened = tightenBoundsCLP (lightweight);
00042 
00043   if (nTightened < 0)
00044     return nTightened;
00045 
00046 //   printf ("-------- BOUNDS DURING ------------\n  ");
00047 //   j=0;
00048 //   for (int i=0; i < ncols; i++) {
00049 //     printf("x_%03d [%+15.8g %+15.8g] ", i, getColLower () [i], getColUpper () [i]);
00050 //     if (!(++j % 6)) printf ("\n  ");
00051 //   }
00052 //   if (j % 6) printf ("\n");
00053 
00054   if (nTightened > 0) {
00055 
00056     // something was tightened. Run an extra btCore "por si las
00057     // moscas" (just in case)
00058 
00059     const double 
00060       *newLower = getColLower (),
00061       *newUpper = getColUpper ();
00062 
00063     t_chg_bounds *chgd = new t_chg_bounds [ncols];
00064 
00065     for (int i=0; i<ncols; i++) {
00066       if (newLower [i] > oldLower [i] + COUENNE_EPS) chgd [i].setLower (t_chg_bounds::CHANGED);
00067       if (newUpper [i] < oldUpper [i] - COUENNE_EPS) chgd [i].setUpper (t_chg_bounds::CHANGED);
00068     }
00069 
00070     cutgen_ -> Problem () -> domain () -> push (ncols, NULL, newLower, newUpper);
00071 
00072     if (!(cutgen_ -> Problem () -> btCore (chgd))) // infeasible
00073       nTightened = -1;
00074 
00075     else {
00076 
00077       const double 
00078         *newerLower = cutgen_ -> Problem () -> Lb (),
00079         *newerUpper = cutgen_ -> Problem () -> Ub ();
00080 
00081       for (int i=0; i<ncols; i++) {
00082 
00083         if (newerLower [i] > newLower [i] + COUENNE_EPS) {
00084           setColLower (i, newerLower [i]);
00085           if (newLower [i] < oldLower [i] + COUENNE_EPS) nTightened++; // extra tightening
00086         }
00087 
00088         if (newerUpper [i] < newUpper [i] - COUENNE_EPS) {
00089           setColUpper (i, newerUpper [i]);
00090           if (newUpper [i] > oldUpper [i] - COUENNE_EPS) nTightened++; // extra tightening
00091         }
00092       }
00093     }
00094 
00095 //    const double 
00096 //      *newerLower = cutgen_ -> Problem () -> Lb (),
00097 //      *newerUpper = cutgen_ -> Problem () -> Ub ();
00098 //
00099 //     printf ("-------- BOUNDS AFTER ------------\n  ");
00100 //     for (int i=0; i < ncols; i++) {
00101 //       printf("x_%03d [%+15.8g %+15.8g] ", i, newerLower [i], newerUpper [i]);
00102 //       if (!(++j % 6)) printf ("\n  ");
00103 //     }
00104 //     if (j % 6) printf ("\n");
00105 
00106     cutgen_ -> Problem () -> domain () -> pop ();
00107 
00108     delete [] chgd;
00109   }
00110 
00111   delete [] oldLower;
00112   delete [] oldUpper;
00113 
00114   return nTightened;
00115 }

Generated on Thu Oct 8 03:02:57 2009 by  doxygen 1.4.7