/home/coin/SVN-release/Cbc-1.1.1/Osi/src/OsiRowCut.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef OsiRowCut_H
00004 #define OsiRowCut_H
00005 
00006 #include "CoinPackedVector.hpp"
00007 
00008 #include "OsiCollections.hpp"
00009 #include "OsiCut.hpp"
00010 
00011 //#define OSI_INLINE_ROWCUT_METHODS
00012 #ifdef OSI_INLINE_ROWCUT_METHODS
00013 #define OsiRowCut_inline inline
00014 #else
00015 #define OsiRowCut_inline
00016 #endif
00017 
00027 class OsiRowCut : public OsiCut {
00028    friend void OsiRowCutUnitTest(const OsiSolverInterface * baseSiP,    
00029                                  const std::string & mpsDir);
00030 
00031 public:
00032   
00035 
00036     OsiRowCut_inline double lb() const;
00038     OsiRowCut_inline void setLb(double lb);
00040     OsiRowCut_inline double ub() const;
00042     OsiRowCut_inline void setUb(double ub);
00044 
00047 
00048     char sense() const;
00050     double rhs() const;
00052     double range() const;
00054 
00055   //-------------------------------------------------------------------
00058 
00059     OsiRowCut_inline void setRow( 
00060       int size, 
00061       const int * colIndices, 
00062       const double * elements,
00063       bool testForDuplicateIndex = true );
00065     OsiRowCut_inline void setRow( const CoinPackedVector & v );
00067     OsiRowCut_inline const CoinPackedVector & row() const;
00069 
00072 #if __GNUC__ != 2 
00073     using OsiCut::operator== ;
00074 #endif
00075 
00078     OsiRowCut_inline bool operator==(const OsiRowCut& rhs) const; 
00079 
00080 #if __GNUC__ != 2 
00081     using OsiCut::operator!= ;
00082 #endif
00084     OsiRowCut_inline bool operator!=(const OsiRowCut& rhs) const; 
00085 
00086   
00087     
00088   //----------------------------------------------------------------
00098     OsiRowCut_inline bool consistent() const; 
00099 
00108     OsiRowCut_inline bool consistent(const OsiSolverInterface& im) const;
00109 
00117     OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const;
00122     virtual double violated(const double * solution) const;
00124 
00127 
00128     void operator+=(double value)
00129         { row_ += value; }
00130 
00132     void operator-=(double value)
00133         { row_ -= value; }
00134 
00136     void operator*=(double value)
00137         { row_ *= value; }
00138 
00140     void operator/=(double value)
00141         { row_ /= value; }
00143 
00145   void sortIncrIndex()
00146         {row_.sortIncrIndex();}
00147 
00150 
00151     OsiRowCut & operator=( const OsiRowCut& rhs);
00152   
00154     OsiRowCut ( const OsiRowCut &);  
00155 
00157     virtual OsiRowCut * clone() const;
00158   
00160     OsiRowCut ();
00161 
00168     OsiRowCut(double cutlb, double cutub,
00169                      int capacity, int size,
00170                      int *&colIndices, double *&elements);
00171   
00173     virtual ~OsiRowCut ();
00175 
00178 
00179   virtual void print() const ;
00181    
00182 private:
00183   
00184  
00187 
00188     CoinPackedVector row_;
00190     double lb_;
00192     double ub_;
00194 };
00195 
00196 #ifdef OSI_INLINE_ROWCUT_METHODS
00197 
00198 //-------------------------------------------------------------------
00199 // Set/Get lower & upper bounds
00200 //-------------------------------------------------------------------
00201 double OsiRowCut::lb() const { return lb_; }
00202 void OsiRowCut::setLb(double lb) { lb_ = lb; }
00203 double OsiRowCut::ub() const { return ub_; }
00204 void OsiRowCut::setUb(double ub) { ub_ = ub; }
00205 
00206 //-------------------------------------------------------------------
00207 // Set row elements
00208 //------------------------------------------------------------------- 
00209 void OsiRowCut::setRow(int size, 
00210                        const int * colIndices, const double * elements)
00211 {
00212   row_.setVector(size,colIndices,elements);
00213 }
00214 void OsiRowCut::setRow( const CoinPackedVector & v )
00215 {
00216   row_ = v;
00217 }
00218 
00219 //-------------------------------------------------------------------
00220 // Get the row
00221 //-------------------------------------------------------------------
00222 const CoinPackedVector & OsiRowCut::row() const 
00223 { 
00224   return row_; 
00225 }
00226 
00227 //----------------------------------------------------------------
00228 // == operator 
00229 //-------------------------------------------------------------------
00230 bool
00231 OsiRowCut::operator==(const OsiRowCut& rhs) const
00232 {
00233   if ( this->OsiCut::operator!=(rhs) ) return false;
00234   if ( row() != rhs.row() ) return false;
00235   if ( lb() != rhs.lb() ) return false;
00236   if ( ub() != rhs.ub() ) return false;
00237   return true;
00238 }
00239 bool
00240 OsiRowCut::operator!=(const OsiRowCut& rhs) const
00241 {
00242   return !( (*this)==rhs );
00243 }
00244 
00245 
00246 //----------------------------------------------------------------
00247 // consistent & infeasible 
00248 //-------------------------------------------------------------------
00249 bool OsiRowCut::consistent() const
00250 {
00251   const CoinPackedVector & r=row();
00252   r.duplicateIndex("consistent", "OsiRowCut");
00253   if ( r.getMinIndex() < 0 ) return false;
00254   return true;
00255 }
00256 bool OsiRowCut::consistent(const OsiSolverInterface& im) const
00257 {  
00258   const CoinPackedVector & r=row();
00259   if ( r.getMaxIndex() >= im.getNumCols() ) return false;
00260 
00261   return true;
00262 }
00263 bool OsiRowCut::infeasible(const OsiSolverInterface &im) const
00264 {
00265   if ( lb() > ub() ) return true;
00266 
00267   return false;
00268 }
00269 
00270 #endif
00271 
00272 //#############################################################################
00278 void
00279 OsiRowCutUnitTest(const OsiSolverInterface * baseSiP,    
00280                   const std::string & mpsDir);
00281 
00288 class OsiRowCut2 : public OsiRowCut {
00289 
00290 public:
00291   
00294 
00295   inline int whichRow() const
00296   { return whichRow_;};
00298   inline void setWhichRow(int row)
00299   { whichRow_=row;};
00301   
00304 
00305   OsiRowCut2 & operator=( const OsiRowCut2& rhs);
00306   
00308   OsiRowCut2 ( const OsiRowCut2 &);  
00309   
00311   virtual OsiRowCut * clone() const;
00312   
00314   OsiRowCut2 (int row=-1);
00315   
00317   virtual ~OsiRowCut2 ();
00319 
00320 private:
00321   
00322  
00325 
00326   int whichRow_;
00328 };
00329 #endif

Generated on Thu May 15 21:59:06 2008 by  doxygen 1.4.7