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

OsiRowCut.hpp

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 );
00064     OsiRowCut_inline void setRow( const CoinPackedVector & v );
00066     OsiRowCut_inline const CoinPackedVector & row() const;
00068 
00074     OsiRowCut_inline bool operator==(const OsiRowCut& rhs) const; 
00076     OsiRowCut_inline bool operator!=(const OsiRowCut& rhs) const; 
00078   
00079     
00080   //----------------------------------------------------------------
00090     OsiRowCut_inline bool consistent() const; 
00091 
00100     OsiRowCut_inline bool consistent(const OsiSolverInterface& im) const;
00101 
00109     OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const;
00114     virtual double violated(const double * solution) const;
00116 
00117 
00120 
00121     OsiRowCut & operator=( const OsiRowCut& rhs);
00122   
00124     OsiRowCut ( const OsiRowCut &);  
00125 
00127     virtual OsiRowCut * clone() const;
00128   
00130     OsiRowCut ();
00131   
00133     virtual ~OsiRowCut ();
00135 
00138 
00139   virtual void print() const ;
00141    
00142 private:
00143   
00144  
00147 
00148     CoinPackedVector row_;
00150     double lb_;
00152     double ub_;
00154 };
00155 
00156 #ifdef OSI_INLINE_ROWCUT_METHODS
00157 
00158 //-------------------------------------------------------------------
00159 // Set/Get lower & upper bounds
00160 //-------------------------------------------------------------------
00161 double OsiRowCut::lb() const { return lb_; }
00162 void OsiRowCut::setLb(double lb) { lb_ = lb; }
00163 double OsiRowCut::ub() const { return ub_; }
00164 void OsiRowCut::setUb(double ub) { ub_ = ub; }
00165 
00166 //-------------------------------------------------------------------
00167 // Set row elements
00168 //------------------------------------------------------------------- 
00169 void OsiRowCut::setRow(int size, 
00170                        const int * colIndices, const double * elements)
00171 {
00172   row_.setVector(size,colIndices,elements);
00173 }
00174 void OsiRowCut::setRow( const CoinPackedVector & v )
00175 {
00176   row_ = v;
00177 }
00178 
00179 //-------------------------------------------------------------------
00180 // Get the row
00181 //-------------------------------------------------------------------
00182 const CoinPackedVector & OsiRowCut::row() const 
00183 { 
00184   return row_; 
00185 }
00186 
00187 //----------------------------------------------------------------
00188 // == operator 
00189 //-------------------------------------------------------------------
00190 bool
00191 OsiRowCut::operator==(const OsiRowCut& rhs) const
00192 {
00193   if ( this->OsiCut::operator!=(rhs) ) return false;
00194   if ( row() != rhs.row() ) return false;
00195   if ( lb() != rhs.lb() ) return false;
00196   if ( ub() != rhs.ub() ) return false;
00197   return true;
00198 }
00199 bool
00200 OsiRowCut::operator!=(const OsiRowCut& rhs) const
00201 {
00202   return !( (*this)==rhs );
00203 }
00204 
00205 
00206 //----------------------------------------------------------------
00207 // consistent & infeasible 
00208 //-------------------------------------------------------------------
00209 bool OsiRowCut::consistent() const
00210 {
00211   const CoinPackedVector & r=row();
00212   r.duplicateIndex("consistent", "OsiRowCut");
00213   if ( r.getMinIndex() < 0 ) return false;
00214   return true;
00215 }
00216 bool OsiRowCut::consistent(const OsiSolverInterface& im) const
00217 {  
00218   const CoinPackedVector & r=row();
00219   if ( r.getMaxIndex() >= im.getNumCols() ) return false;
00220 
00221   return true;
00222 }
00223 bool OsiRowCut::infeasible(const OsiSolverInterface &im) const
00224 {
00225   if ( lb() > ub() ) return true;
00226 
00227   return false;
00228 }
00229 
00230 #endif
00231 
00232 //#############################################################################
00238 void
00239 OsiRowCutUnitTest(const OsiSolverInterface * baseSiP,    
00240                   const std::string & mpsDir);
00241 
00242 #endif

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