/home/coin/SVN-release/OS-2.0.1/Couenne/src/convex/genColCuts.cpp

Go to the documentation of this file.
00001 /* $Id: genColCuts.cpp 141 2009-06-03 04:19:19Z pbelotti $ */
00002 /*
00003  * Name:    genColCuts.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: generate Column Cuts for improved bounds
00006  *
00007  * (C) Carnegie-Mellon University, 2006-07.
00008  * This file is licensed under the Common Public License (CPL)
00009  */
00010 
00011 #include "CglCutGenerator.hpp"
00012 #include "CouenneCutGenerator.hpp"
00013 #include "CouenneProblem.hpp"
00014 
00015 //#define DEBUG
00016 
00018 void CouenneCutGenerator::genColCuts (const OsiSolverInterface &si,
00019                                       OsiCuts &cs,
00020                                       int nchanged,
00021                                       int *changed) const {
00022 
00023 #ifdef DEBUG
00024   int nrc = cs.sizeRowCuts ();// Must go
00025 #endif
00026 
00027   int  ncols  = problem_ -> nVars (),
00028       *indLow = new int [ncols], // indices for OsiColCut
00029       *indUpp = new int [ncols], //
00030        nLow, nUpp = nLow = 0;
00031     //ind_obj = problem_ -> Obj (0) -> Body () -> Index ();
00032 
00033   // values fo OsiColCut
00034   CouNumber *bndLow = new CouNumber [ncols],
00035             *bndUpp = new CouNumber [ncols];
00036 
00037   const CouNumber 
00038     *oldLow = si.getColLower (), // old bounds
00039     *oldUpp = si.getColUpper (),
00040     *newLow = problem_ -> Lb (), // changed bounds
00041     *newUpp = problem_ -> Ub ();
00042 
00043 #ifdef DEBUG
00044   for (int i=0; i < problem_ -> nVars (); i++)
00045     if ((newLow [i] > oldLow [i] + COUENNE_EPS) ||
00046         (newUpp [i] < oldUpp [i] - COUENNE_EPS))
00047       printf ("x%-3d. [%-10g , %10g] ---> [%-10g , %10g]\n",
00048       i, oldLow [i], oldUpp [i], newLow [i], newUpp [i]);*/
00049 #endif
00050 
00051   // check all changed bounds
00052   for (int i = 0; i < nchanged; i++) {
00053 
00054     int index = changed [i];
00055 
00056     // fails with spectra2 with (abt=2,obbt=0) for variable x70
00057     //assert (problem_ -> Var (index) -> Multiplicity () > 0);
00058 
00059     if (//(index == ind_obj) || 
00060         (problem_ -> Var (index) -> Multiplicity () <= 0))
00061       continue;
00062 
00063     if (newLow [index] > newUpp [index])
00064       problem_ -> Lb (index) = problem_ -> Ub (index);
00065 
00066     CouNumber bd;
00067 
00068     if ((((bd = newLow [index]) > oldLow [index] + COUENNE_EPS) || firstcall_) // better lb?
00069         && (bd > -COUENNE_INFINITY / 10)) {                                    // finite?
00070 
00071       //printf ("chging low %d %g -> %g\n", index, oldLow [index], newLow [index]);
00072       if (problem_ -> Var (index) -> isInteger ()) 
00073         bd = ceil (bd);
00074       indLow [nLow]   = index;
00075       bndLow [nLow++] = bd;
00076     }
00077 
00078     if ((((bd = newUpp [index]) < oldUpp [index] - COUENNE_EPS) || firstcall_) // better ub?
00079         && (bd < COUENNE_INFINITY / 10)) {                                     // finite?
00080 
00081       //printf ("chging upp %d %g -> %g\n", index, oldUpp [index], newUpp [index]);
00082       if (problem_ -> Var (index) -> isInteger ()) 
00083         bd = floor (bd);
00084       indUpp [nUpp]   = index;
00085       bndUpp [nUpp++] = bd;
00086     }
00087   }
00088 
00089   // create Column Cut
00090 
00091   if (nUpp || nLow) {
00092 
00093     OsiColCut *cut = new OsiColCut;
00094 
00095     if (cut) {
00096       cut -> setLbs (nLow, indLow, bndLow);
00097       cut -> setUbs (nUpp, indUpp, bndUpp);
00098 
00099       cs.insert (cut);
00100       delete cut;
00101     }
00102   }
00103 
00104 #ifdef DEBUG
00105   printf ("column cuts\n");
00106   for (int jj = nrc; jj < cs.sizeRowCuts (); jj++) cs.rowCutPtr (jj) -> print ();
00107 #endif
00108 
00109   delete [] bndLow; delete [] indLow;
00110   delete [] bndUpp; delete [] indUpp;
00111 }

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