- Main Page
- Namespaces
- Classes
- Files
- Directories

- Search for |

- File List
- File Members

# OsiRowCut.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2000, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003 // This code is licensed under the terms of the Eclipse Public License (EPL).
    00004
    00005 #ifndef OsiRowCut_H
    00006 #define OsiRowCut_H
    00007
    00008 #include "CoinPackedVector.hpp"
    00009
    00010 #include "OsiCollections.hpp"
    00011 #include "OsiCut.hpp"
    00012
    00013 //#define OSI_INLINE_ROWCUT_METHODS
    00014 #ifdef OSI_INLINE_ROWCUT_METHODS
    00015 #define OsiRowCut_inline inline
    00016 #else
    00017 #define OsiRowCut_inline
    00018 #endif
    00019
    00029 class OsiRowCut : public OsiCut {
    00030    friend void OsiRowCutUnitTest(const OsiSolverInterface * baseSiP,
    00031                                  const std::string & mpsDir);
    00032
    00033 public:
    00034
    00037
    00038     OsiRowCut_inline double lb() const;
    00040     OsiRowCut_inline void setLb(double lb);
    00042     OsiRowCut_inline double ub() const;
    00044     OsiRowCut_inline void setUb(double ub);
    00046
    00049
    00050     char sense() const;
    00052     double rhs() const;
    00054     double range() const;
    00056
    00057   //-------------------------------------------------------------------
    00060
    00061     OsiRowCut_inline void setRow(
    00062       int size,
    00063       const int * colIndices,
    00064       const double * elements,
    00065       bool testForDuplicateIndex = COIN_DEFAULT_VALUE_FOR_DUPLICATE);
    00067     OsiRowCut_inline void setRow( const CoinPackedVector & v );
    00069     OsiRowCut_inline const CoinPackedVector & row() const;
    00071     OsiRowCut_inline CoinPackedVector & mutableRow() ;
    00073
    00076 #if __GNUC__ != 2
    00077     using OsiCut::operator== ;
    00078 #endif
    00079
    00082     OsiRowCut_inline bool operator==(const OsiRowCut& rhs) const;
    00083
    00084 #if __GNUC__ != 2
    00085     using OsiCut::operator!= ;
    00086 #endif
    00088     OsiRowCut_inline bool operator!=(const OsiRowCut& rhs) const;
    00089
    00090
    00091
    00092   //----------------------------------------------------------------
    00102     OsiRowCut_inline bool consistent() const;
    00103
    00112     OsiRowCut_inline bool consistent(const OsiSolverInterface& im) const;
    00113
    00121     OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const;
    00126     virtual double violated(const double * solution) const;
    00128
    00131
    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; }
    00142
    00144     void operator/=(double value)
    00145         { row_ /= value; }
    00147
    00149   void sortIncrIndex()
    00150         {row_.sortIncrIndex();}
    00151
    00154
    00155     OsiRowCut & operator=( const OsiRowCut& rhs);
    00156
    00158     OsiRowCut ( const OsiRowCut &);
    00159
    00161     virtual OsiRowCut * clone() const;
    00162
    00164     OsiRowCut ();
    00165
    00172     OsiRowCut(double cutlb, double cutub,
    00173                      int capacity, int size,
    00174                      int *&colIndices, double *&elements);
    00175
    00177     virtual ~OsiRowCut ();
    00179
    00182
    00183   virtual void print() const ;
    00185
    00186 private:
    00187
    00188
    00191
    00192     CoinPackedVector row_;
    00194     double lb_;
    00196     double ub_;
    00198 };
    00199
    00200 #ifdef OSI_INLINE_ROWCUT_METHODS
    00201
    00202 //-------------------------------------------------------------------
    00203 // Set/Get lower & upper bounds
    00204 //-------------------------------------------------------------------
    00205 double OsiRowCut::lb() const { return lb_; }
    00206 void OsiRowCut::setLb(double lb) { lb_ = lb; }
    00207 double OsiRowCut::ub() const { return ub_; }
    00208 void OsiRowCut::setUb(double ub) { ub_ = ub; }
    00209
    00210 //-------------------------------------------------------------------
    00211 // Set row elements
    00212 //-------------------------------------------------------------------
    00213 void OsiRowCut::setRow(int size,
    00214                        const int * colIndices, const double * elements)
    00215 {
    00216   row_.setVector(size,colIndices,elements);
    00217 }
    00218 void OsiRowCut::setRow( const CoinPackedVector & v )
    00219 {
    00220   row_ = v;
    00221 }
    00222
    00223 //-------------------------------------------------------------------
    00224 // Get the row
    00225 //-------------------------------------------------------------------
    00226 const CoinPackedVector & OsiRowCut::row() const
    00227 {
    00228   return row_;
    00229 }
    00230
    00231 //-------------------------------------------------------------------
    00232 // Get the row so we can change
    00233 //-------------------------------------------------------------------
    00234 CoinPackedVector & OsiRowCut::mutableRow()
    00235 {
    00236   return row_;
    00237 }
    00238
    00239 //----------------------------------------------------------------
    00240 // == operator
    00241 //-------------------------------------------------------------------
    00242 bool
    00243 OsiRowCut::operator==(const OsiRowCut& rhs) const
    00244 {
    00245   if ( this->OsiCut::operator!=(rhs) ) return false;
    00246   if ( row() != rhs.row() ) return false;
    00247   if ( lb() != rhs.lb() ) return false;
    00248   if ( ub() != rhs.ub() ) return false;
    00249   return true;
    00250 }
    00251 bool
    00252 OsiRowCut::operator!=(const OsiRowCut& rhs) const
    00253 {
    00254   return !( (*this)==rhs );
    00255 }
    00256
    00257
    00258 //----------------------------------------------------------------
    00259 // consistent & infeasible
    00260 //-------------------------------------------------------------------
    00261 bool OsiRowCut::consistent() const
    00262 {
    00263   const CoinPackedVector & r=row();
    00264   r.duplicateIndex("consistent", "OsiRowCut");
    00265   if ( r.getMinIndex() < 0 ) return false;
    00266   return true;
    00267 }
    00268 bool OsiRowCut::consistent(const OsiSolverInterface& im) const
    00269 {
    00270   const CoinPackedVector & r=row();
    00271   if ( r.getMaxIndex() >= im.getNumCols() ) return false;
    00272
    00273   return true;
    00274 }
    00275 bool OsiRowCut::infeasible(const OsiSolverInterface &im) const
    00276 {
    00277   if ( lb() > ub() ) return true;
    00278
    00279   return false;
    00280 }
    00281
    00282 #endif
    00283
    00290 class OsiRowCut2 : public OsiRowCut {
    00291
    00292 public:
    00293
    00296
    00297   inline int whichRow() const
    00298   { return whichRow_;}
    00300   inline void setWhichRow(int row)
    00301   { whichRow_=row;}
    00303
    00306
    00307   OsiRowCut2 & operator=( const OsiRowCut2& rhs);
    00308
    00310   OsiRowCut2 ( const OsiRowCut2 &);
    00311
    00313   virtual OsiRowCut * clone() const;
    00314
    00316   OsiRowCut2 (int row=-1);
    00317
    00319   virtual ~OsiRowCut2 ();
    00321
    00322 private:
    00323
    00324
    00327
    00328   int whichRow_;
    00330 };
    00331 #endif