- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Blis-0.91.0/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 = COIN_DEFAULT_VALUE_FOR_DUPLICATE);
    00065     OsiRowCut_inline void setRow( const CoinPackedVector & v );
    00067     OsiRowCut_inline const CoinPackedVector & row() const;
    00069     OsiRowCut_inline CoinPackedVector & mutableRow() ;
    00071
    00074 #if __GNUC__ != 2
    00075     using OsiCut::operator== ;
    00076 #endif
    00077
    00080     OsiRowCut_inline bool operator==(const OsiRowCut& rhs) const;
    00081
    00082 #if __GNUC__ != 2
    00083     using OsiCut::operator!= ;
    00084 #endif
    00086     OsiRowCut_inline bool operator!=(const OsiRowCut& rhs) const;
    00087
    00088
    00089
    00090   //----------------------------------------------------------------
    00100     OsiRowCut_inline bool consistent() const;
    00101
    00110     OsiRowCut_inline bool consistent(const OsiSolverInterface& im) const;
    00111
    00119     OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const;
    00124     virtual double violated(const double * solution) const;
    00126
    00129
    00130     void operator+=(double value)
    00131         { row_ += value; }
    00132
    00134     void operator-=(double value)
    00135         { row_ -= value; }
    00136
    00138     void operator*=(double value)
    00139         { row_ *= value; }
    00140
    00142     void operator/=(double value)
    00143         { row_ /= value; }
    00145
    00147   void sortIncrIndex()
    00148         {row_.sortIncrIndex();}
    00149
    00152
    00153     OsiRowCut & operator=( const OsiRowCut& rhs);
    00154
    00156     OsiRowCut ( const OsiRowCut &);
    00157
    00159     virtual OsiRowCut * clone() const;
    00160
    00162     OsiRowCut ();
    00163
    00170     OsiRowCut(double cutlb, double cutub,
    00171                      int capacity, int size,
    00172                      int *&colIndices, double *&elements);
    00173
    00175     virtual ~OsiRowCut ();
    00177
    00180
    00181   virtual void print() const ;
    00183
    00184 private:
    00185
    00186
    00189
    00190     CoinPackedVector row_;
    00192     double lb_;
    00194     double ub_;
    00196 };
    00197
    00198 #ifdef OSI_INLINE_ROWCUT_METHODS
    00199
    00200 //-------------------------------------------------------------------
    00201 // Set/Get lower & upper bounds
    00202 //-------------------------------------------------------------------
    00203 double OsiRowCut::lb() const { return lb_; }
    00204 void OsiRowCut::setLb(double lb) { lb_ = lb; }
    00205 double OsiRowCut::ub() const { return ub_; }
    00206 void OsiRowCut::setUb(double ub) { ub_ = ub; }
    00207
    00208 //-------------------------------------------------------------------
    00209 // Set row elements
    00210 //-------------------------------------------------------------------
    00211 void OsiRowCut::setRow(int size,
    00212                        const int * colIndices, const double * elements)
    00213 {
    00214   row_.setVector(size,colIndices,elements);
    00215 }
    00216 void OsiRowCut::setRow( const CoinPackedVector & v )
    00217 {
    00218   row_ = v;
    00219 }
    00220
    00221 //-------------------------------------------------------------------
    00222 // Get the row
    00223 //-------------------------------------------------------------------
    00224 const CoinPackedVector & OsiRowCut::row() const
    00225 {
    00226   return row_;
    00227 }
    00228
    00229 //-------------------------------------------------------------------
    00230 // Get the row so we can change
    00231 //-------------------------------------------------------------------
    00232 CoinPackedVector & OsiRowCut::mutableRow()
    00233 {
    00234   return row_;
    00235 }
    00236
    00237 //----------------------------------------------------------------
    00238 // == operator
    00239 //-------------------------------------------------------------------
    00240 bool
    00241 OsiRowCut::operator==(const OsiRowCut& rhs) const
    00242 {
    00243   if ( this->OsiCut::operator!=(rhs) ) return false;
    00244   if ( row() != rhs.row() ) return false;
    00245   if ( lb() != rhs.lb() ) return false;
    00246   if ( ub() != rhs.ub() ) return false;
    00247   return true;
    00248 }
    00249 bool
    00250 OsiRowCut::operator!=(const OsiRowCut& rhs) const
    00251 {
    00252   return !( (*this)==rhs );
    00253 }
    00254
    00255
    00256 //----------------------------------------------------------------
    00257 // consistent & infeasible
    00258 //-------------------------------------------------------------------
    00259 bool OsiRowCut::consistent() const
    00260 {
    00261   const CoinPackedVector & r=row();
    00262   r.duplicateIndex("consistent", "OsiRowCut");
    00263   if ( r.getMinIndex() < 0 ) return false;
    00264   return true;
    00265 }
    00266 bool OsiRowCut::consistent(const OsiSolverInterface& im) const
    00267 {
    00268   const CoinPackedVector & r=row();
    00269   if ( r.getMaxIndex() >= im.getNumCols() ) return false;
    00270
    00271   return true;
    00272 }
    00273 bool OsiRowCut::infeasible(const OsiSolverInterface &im) const
    00274 {
    00275   if ( lb() > ub() ) return true;
    00276
    00277   return false;
    00278 }
    00279
    00280 #endif
    00281
    00282 //#############################################################################
    00288 void
    00289 OsiRowCutUnitTest(const OsiSolverInterface * baseSiP,
    00290                   const std::string & mpsDir);
    00291
    00298 class OsiRowCut2 : public OsiRowCut {
    00299
    00300 public:
    00301
    00304
    00305   inline int whichRow() const
    00306   { return whichRow_;}
    00308   inline void setWhichRow(int row)
    00309   { whichRow_=row;}
    00311
    00314
    00315   OsiRowCut2 & operator=( const OsiRowCut2& rhs);
    00316
    00318   OsiRowCut2 ( const OsiRowCut2 &);
    00319
    00321   virtual OsiRowCut * clone() const;
    00322
    00324   OsiRowCut2 (int row=-1);
    00325
    00327   virtual ~OsiRowCut2 ();
    00329
    00330 private:
    00331
    00332
    00335
    00336   int whichRow_;
    00338 };
    00339 #endif