Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

OsiColCut.hpp

00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef OsiColCut_H
00004 #define OsiColCut_H
00005 
00006 #include <string>
00007 
00008 #include "CoinPackedVector.hpp"
00009 
00010 #include "OsiCollections.hpp"
00011 #include "OsiCut.hpp"
00012 
00021 class OsiColCut : public OsiCut {
00022    friend void OsiColCutUnitTest(const OsiSolverInterface * baseSiP, 
00023                                  const std::string & mpsDir);
00024   
00025 public:
00026   
00027   //----------------------------------------------------------------
00028   
00031 
00032   inline void setLbs( 
00033     int nElements, 
00034     const int * colIndices, 
00035     const double * lbElements );   
00036   
00038   inline void setLbs( const CoinPackedVector & lbs );
00039   
00041   inline void setUbs( 
00042     int nElements, 
00043     const int * colIndices, 
00044     const double * ubElements );
00045   
00047   inline void setUbs( const CoinPackedVector & ubs );
00049   
00050   //----------------------------------------------------------------
00051   
00054 
00055   inline const CoinPackedVector & lbs() const;
00057   inline const CoinPackedVector & ubs() const;
00059   
00065   inline virtual bool operator==(const OsiColCut& rhs) const; 
00067   inline virtual bool operator!=(const OsiColCut& rhs) const; 
00069   
00070   
00071   //----------------------------------------------------------------
00072   
00082   inline virtual bool consistent() const; 
00083   
00091   inline virtual bool consistent(const OsiSolverInterface& im) const;
00092   
00101   inline virtual bool infeasible(const OsiSolverInterface &im) const;
00106   virtual double violated(const double * solution) const;
00108   
00109   //----------------------------------------------------------------
00110   
00113 
00114   OsiColCut & operator=( const OsiColCut& rhs);
00115   
00117   OsiColCut ( const OsiColCut &);
00118   
00120   OsiColCut ();
00121   
00123   virtual OsiColCut * clone() const;
00124   
00126   virtual ~OsiColCut ();
00128   
00131 
00132   virtual void print() const;
00134    
00135 private:
00136   
00139 
00140   CoinPackedVector lbs_;
00142   CoinPackedVector ubs_;
00144   
00145 };
00146 
00147 
00148 
00149 //-------------------------------------------------------------------
00150 // Set lower & upper bound vectors
00151 //------------------------------------------------------------------- 
00152 void OsiColCut::setLbs( 
00153                        int size, 
00154                        const int * colIndices, 
00155                        const double * lbElements )
00156 {
00157   lbs_.setVector(size,colIndices,lbElements);
00158 }
00159 //
00160 void OsiColCut::setUbs( 
00161                        int size, 
00162                        const int * colIndices, 
00163                        const double * ubElements )
00164 {
00165   ubs_.setVector(size,colIndices,ubElements);
00166 }
00167 //
00168 void OsiColCut::setLbs( const CoinPackedVector & lbs )
00169 {
00170   lbs_ = lbs;
00171 }
00172 //
00173 void OsiColCut::setUbs( const CoinPackedVector & ubs )
00174 {
00175   ubs_ = ubs;
00176 }
00177 
00178 //-------------------------------------------------------------------
00179 // Get Column Lower Bounds and Column Upper Bounds
00180 //-------------------------------------------------------------------
00181 const CoinPackedVector & OsiColCut::lbs() const 
00182 { 
00183   return lbs_; 
00184 }
00185 //
00186 const CoinPackedVector & OsiColCut::ubs() const 
00187 { 
00188   return ubs_; 
00189 }
00190 
00191 //----------------------------------------------------------------
00192 // == operator 
00193 //-------------------------------------------------------------------
00194 bool
00195 OsiColCut::operator==(
00196                       const OsiColCut& rhs) const
00197 {
00198   if ( this->OsiCut::operator!=(rhs) ) 
00199     return false;
00200   if ( lbs() != rhs.lbs() ) 
00201     return false;
00202   if ( ubs() != rhs.ubs() ) 
00203     return false;
00204   return true;
00205 }
00206 //
00207 bool
00208 OsiColCut::operator!=(
00209                       const OsiColCut& rhs) const
00210 {
00211   return !( (*this)==rhs );
00212 }
00213 
00214 //----------------------------------------------------------------
00215 // consistent & infeasible 
00216 //-------------------------------------------------------------------
00217 bool OsiColCut::consistent() const
00218 {
00219   const CoinPackedVector & lb = lbs();
00220   const CoinPackedVector & ub = ubs();
00221   // Test for consistent cut.
00222   // Are packed vectors consistent?
00223   lb.duplicateIndex("consistent", "OsiColCut");
00224   ub.duplicateIndex("consistent", "OsiColCut");
00225   if ( lb.getMinIndex() < 0 ) return false;
00226   if ( ub.getMinIndex() < 0 ) return false;
00227   return true;
00228 }
00229 //
00230 bool OsiColCut::consistent(const OsiSolverInterface& im) const
00231 {  
00232   const CoinPackedVector & lb = lbs();
00233   const CoinPackedVector & ub = ubs();
00234   
00235   // Test for consistent cut.
00236   if ( lb.getMaxIndex() >= im.getNumCols() ) return false;
00237   if ( ub.getMaxIndex() >= im.getNumCols() ) return false;
00238   
00239   return true;
00240 }
00241 
00242 #if 0
00243 bool OsiColCut::feasible(const OsiSolverInterface &im) const
00244 {
00245   const double * oldColLb = im.getColLower();
00246   const double * oldColUb = im.getColUpper();
00247   const CoinPackedVector & cutLbs = lbs();
00248   const CoinPackedVector & cutUbs = ubs();
00249   int i;
00250   
00251   for ( i=0; i<cutLbs.size(); i++ ) {
00252     int colIndx = cutLbs.indices()[i];
00253     double newLb;
00254     if ( cutLbs.elements()[i] > oldColLb[colIndx] )
00255       newLb = cutLbs.elements()[i];
00256     else
00257       newLb = oldColLb[colIndx];
00258 
00259     double newUb = oldColUb[colIndx];
00260     if ( cutUbs.indexExists(colIndx) )
00261       if ( cutUbs[colIndx] < newUb ) newUb = cutUbs[colIndx];
00262       if ( newLb > newUb ) 
00263         return false;
00264   }
00265   
00266   for ( i=0; i<cutUbs.size(); i++ ) {
00267     int colIndx = cutUbs.indices()[i];
00268     double newUb = cutUbs.elements()[i] < oldColUb[colIndx] ? cutUbs.elements()[i] : oldColUb[colIndx];
00269     double newLb = oldColLb[colIndx];
00270     if ( cutLbs.indexExists(colIndx) )
00271       if ( cutLbs[colIndx] > newLb ) newLb = cutLbs[colIndx];
00272       if ( newUb < newLb ) 
00273         return false;
00274   }
00275   
00276   return true;
00277 }
00278 #endif 
00279 
00280 
00281 bool OsiColCut::infeasible(const OsiSolverInterface &im) const
00282 {
00283   const double * oldColLb = im.getColLower();
00284   const double * oldColUb = im.getColUpper();
00285   const CoinPackedVector & cutLbs = lbs();
00286   const CoinPackedVector & cutUbs = ubs();
00287   int i;
00288   
00289   for ( i=0; i<cutLbs.getNumElements(); i++ ) {
00290     int colIndx = cutLbs.getIndices()[i];
00291     double newLb= cutLbs.getElements()[i] > oldColLb[colIndx] ?
00292        cutLbs.getElements()[i] : oldColLb[colIndx];
00293 
00294     double newUb = oldColUb[colIndx];
00295     if ( cutUbs.isExistingIndex(colIndx) )
00296       if ( cutUbs[colIndx] < newUb ) newUb = cutUbs[colIndx];
00297       if ( newLb > newUb ) 
00298         return true;
00299   }
00300   
00301   for ( i=0; i<cutUbs.getNumElements(); i++ ) {
00302     int colIndx = cutUbs.getIndices()[i];
00303     double newUb = cutUbs.getElements()[i] < oldColUb[colIndx] ?
00304        cutUbs.getElements()[i] : oldColUb[colIndx];
00305     double newLb = oldColLb[colIndx];
00306     if ( cutLbs.isExistingIndex(colIndx) )
00307       if ( cutLbs[colIndx] > newLb ) newLb = cutLbs[colIndx];
00308       if ( newUb < newLb ) 
00309         return true;
00310   }
00311   
00312   return false;
00313 }
00314 
00315 //#############################################################################
00321 void
00322 OsiColCutUnitTest(const OsiSolverInterface * baseSiP, 
00323                   const std::string & mpsDir);
00324 
00325 #endif

Generated on Wed Dec 3 14:35:29 2003 for Osi by doxygen 1.3.5