OsiRowCut.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef OsiRowCut_H
4 #define OsiRowCut_H
5 
6 #include "CoinPackedVector.hpp"
7 
8 #include "OsiCollections.hpp"
9 #include "OsiCut.hpp"
10 
11 //#define OSI_INLINE_ROWCUT_METHODS
12 #ifdef OSI_INLINE_ROWCUT_METHODS
13 #define OsiRowCut_inline inline
14 #else
15 #define OsiRowCut_inline
16 #endif
17 
27 class OsiRowCut : public OsiCut {
28  friend void OsiRowCutUnitTest(const OsiSolverInterface * baseSiP,
29  const std::string & mpsDir);
30 
31 public:
32 
35  OsiRowCut_inline double lb() const;
38  OsiRowCut_inline void setLb(double lb);
40  OsiRowCut_inline double ub() const;
42  OsiRowCut_inline void setUb(double ub);
44 
47  char sense() const;
50  double rhs() const;
52  double range() const;
54 
55  //-------------------------------------------------------------------
60  int size,
61  const int * colIndices,
62  const double * elements,
63  bool testForDuplicateIndex = COIN_DEFAULT_VALUE_FOR_DUPLICATE);
65  OsiRowCut_inline void setRow( const CoinPackedVector & v );
67  OsiRowCut_inline const CoinPackedVector & row() const;
69  OsiRowCut_inline CoinPackedVector & mutableRow() ;
71 
74 #if __GNUC__ != 2
75  using OsiCut::operator== ;
76 #endif
77 
80  OsiRowCut_inline bool operator==(const OsiRowCut& rhs) const;
81 
82 #if __GNUC__ != 2
83  using OsiCut::operator!= ;
84 #endif
85  OsiRowCut_inline bool operator!=(const OsiRowCut& rhs) const;
88 
89 
90  //----------------------------------------------------------------
100  OsiRowCut_inline bool consistent() const;
101 
110  OsiRowCut_inline bool consistent(const OsiSolverInterface& im) const;
111 
119  OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const;
124  virtual double violated(const double * solution) const;
126 
129  void operator+=(double value)
131  { row_ += value; }
132 
134  void operator-=(double value)
135  { row_ -= value; }
136 
138  void operator*=(double value)
139  { row_ *= value; }
140 
142  void operator/=(double value)
143  { row_ /= value; }
145 
148  {row_.sortIncrIndex();}
149 
152  OsiRowCut & operator=( const OsiRowCut& rhs);
154 
156  OsiRowCut ( const OsiRowCut &);
157 
159  virtual OsiRowCut * clone() const;
160 
162  OsiRowCut ();
163 
170  OsiRowCut(double cutlb, double cutub,
171  int capacity, int size,
172  int *&colIndices, double *&elements);
173 
175  virtual ~OsiRowCut ();
177 
180  virtual void print() const ;
183 
184 private:
185 
186 
189  CoinPackedVector row_;
192  double lb_;
194  double ub_;
196 };
197 
198 #ifdef OSI_INLINE_ROWCUT_METHODS
199 
200 //-------------------------------------------------------------------
201 // Set/Get lower & upper bounds
202 //-------------------------------------------------------------------
203 double OsiRowCut::lb() const { return lb_; }
204 void OsiRowCut::setLb(double lb) { lb_ = lb; }
205 double OsiRowCut::ub() const { return ub_; }
206 void OsiRowCut::setUb(double ub) { ub_ = ub; }
207 
208 //-------------------------------------------------------------------
209 // Set row elements
210 //-------------------------------------------------------------------
211 void OsiRowCut::setRow(int size,
212  const int * colIndices, const double * elements)
213 {
214  row_.setVector(size,colIndices,elements);
215 }
216 void OsiRowCut::setRow( const CoinPackedVector & v )
217 {
218  row_ = v;
219 }
220 
221 //-------------------------------------------------------------------
222 // Get the row
223 //-------------------------------------------------------------------
224 const CoinPackedVector & OsiRowCut::row() const
225 {
226  return row_;
227 }
228 
229 //-------------------------------------------------------------------
230 // Get the row so we can change
231 //-------------------------------------------------------------------
232 CoinPackedVector & OsiRowCut::mutableRow()
233 {
234  return row_;
235 }
236 
237 //----------------------------------------------------------------
238 // == operator
239 //-------------------------------------------------------------------
240 bool
241 OsiRowCut::operator==(const OsiRowCut& rhs) const
242 {
243  if ( this->OsiCut::operator!=(rhs) ) return false;
244  if ( row() != rhs.row() ) return false;
245  if ( lb() != rhs.lb() ) return false;
246  if ( ub() != rhs.ub() ) return false;
247  return true;
248 }
249 bool
250 OsiRowCut::operator!=(const OsiRowCut& rhs) const
251 {
252  return !( (*this)==rhs );
253 }
254 
255 
256 //----------------------------------------------------------------
257 // consistent & infeasible
258 //-------------------------------------------------------------------
259 bool OsiRowCut::consistent() const
260 {
261  const CoinPackedVector & r=row();
262  r.duplicateIndex("consistent", "OsiRowCut");
263  if ( r.getMinIndex() < 0 ) return false;
264  return true;
265 }
266 bool OsiRowCut::consistent(const OsiSolverInterface& im) const
267 {
268  const CoinPackedVector & r=row();
269  if ( r.getMaxIndex() >= im.getNumCols() ) return false;
270 
271  return true;
272 }
273 bool OsiRowCut::infeasible(const OsiSolverInterface &im) const
274 {
275  if ( lb() > ub() ) return true;
276 
277  return false;
278 }
279 
280 #endif
281 
282 //#############################################################################
288 void
289 OsiRowCutUnitTest(const OsiSolverInterface * baseSiP,
290  const std::string & mpsDir);
291 
298 class OsiRowCut2 : public OsiRowCut {
299 
300 public:
301 
304  inline int whichRow() const
306  { return whichRow_;}
308  inline void setWhichRow(int row)
309  { whichRow_=row;}
311 
314  OsiRowCut2 & operator=( const OsiRowCut2& rhs);
316 
318  OsiRowCut2 ( const OsiRowCut2 &);
319 
321  virtual OsiRowCut * clone() const;
322 
324  OsiRowCut2 (int row=-1);
325 
327  virtual ~OsiRowCut2 ();
329 
330 private:
331 
332 
335  int whichRow_;
338 };
339 #endif