OsiRowCut.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 // This code is licensed under the terms of the Eclipse Public License (EPL).
4 
5 #ifndef OsiRowCut_H
6 #define OsiRowCut_H
7 
8 #include "CoinPackedVector.hpp"
9 
10 #include "OsiCollections.hpp"
11 #include "OsiCut.hpp"
12 
13 //#define OSI_INLINE_ROWCUT_METHODS
14 #ifdef OSI_INLINE_ROWCUT_METHODS
15 #define OsiRowCut_inline inline
16 #else
17 #define OsiRowCut_inline
18 #endif
19 
29 class OsiRowCut : public OsiCut {
30  friend void OsiRowCutUnitTest(const OsiSolverInterface * baseSiP,
31  const std::string & mpsDir);
32 
33 public:
34 
37  OsiRowCut_inline double lb() const;
40  OsiRowCut_inline void setLb(double lb);
42  OsiRowCut_inline double ub() const;
44  OsiRowCut_inline void setUb(double ub);
46 
49  char sense() const;
52  double rhs() const;
54  double range() const;
56 
57  //-------------------------------------------------------------------
62  int size,
63  const int * colIndices,
64  const double * elements,
65  bool testForDuplicateIndex = COIN_DEFAULT_VALUE_FOR_DUPLICATE);
67  OsiRowCut_inline void setRow( const CoinPackedVector & v );
69  OsiRowCut_inline const CoinPackedVector & row() const;
73 
76 #if __GNUC__ != 2
77  using OsiCut::operator== ;
78 #endif
79 
82  OsiRowCut_inline bool operator==(const OsiRowCut& rhs) const;
83 
84 #if __GNUC__ != 2
85  using OsiCut::operator!= ;
86 #endif
87  OsiRowCut_inline bool operator!=(const OsiRowCut& rhs) const;
90 
91 
92  //----------------------------------------------------------------
102  OsiRowCut_inline bool consistent() const;
103 
112  OsiRowCut_inline bool consistent(const OsiSolverInterface& im) const;
113 
121  OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const;
126  virtual double violated(const double * solution) const;
128 
131  void operator+=(double value)
133  { row_ += value; }
134 
136  void operator-=(double value)
137  { row_ -= value; }
138 
140  void operator*=(double value)
141  { row_ *= value; }
142 
144  void operator/=(double value)
145  { row_ /= value; }
147 
150  {row_.sortIncrIndex();}
151 
154  OsiRowCut & operator=( const OsiRowCut& rhs);
156 
158  OsiRowCut ( const OsiRowCut &);
159 
161  virtual OsiRowCut * clone() const;
162 
164  OsiRowCut ();
165 
172  OsiRowCut(double cutlb, double cutub,
173  int capacity, int size,
174  int *&colIndices, double *&elements);
175 
177  virtual ~OsiRowCut ();
179 
182  virtual void print() const ;
185 
186 private:
187 
188 
194  double lb_;
196  double ub_;
198 };
199 
200 #ifdef OSI_INLINE_ROWCUT_METHODS
201 
202 //-------------------------------------------------------------------
203 // Set/Get lower & upper bounds
204 //-------------------------------------------------------------------
205 double OsiRowCut::lb() const { return lb_; }
206 void OsiRowCut::setLb(double lb) { lb_ = lb; }
207 double OsiRowCut::ub() const { return ub_; }
208 void OsiRowCut::setUb(double ub) { ub_ = ub; }
209 
210 //-------------------------------------------------------------------
211 // Set row elements
212 //-------------------------------------------------------------------
213 void OsiRowCut::setRow(int size,
214  const int * colIndices, const double * elements)
215 {
216  row_.setVector(size,colIndices,elements);
217 }
218 void OsiRowCut::setRow( const CoinPackedVector & v )
219 {
220  row_ = v;
221 }
222 
223 //-------------------------------------------------------------------
224 // Get the row
225 //-------------------------------------------------------------------
226 const CoinPackedVector & OsiRowCut::row() const
227 {
228  return row_;
229 }
230 
231 //-------------------------------------------------------------------
232 // Get the row so we can change
233 //-------------------------------------------------------------------
235 {
236  return row_;
237 }
238 
239 //----------------------------------------------------------------
240 // == operator
241 //-------------------------------------------------------------------
242 bool
243 OsiRowCut::operator==(const OsiRowCut& rhs) const
244 {
245  if ( this->OsiCut::operator!=(rhs) ) return false;
246  if ( row() != rhs.row() ) return false;
247  if ( lb() != rhs.lb() ) return false;
248  if ( ub() != rhs.ub() ) return false;
249  return true;
250 }
251 bool
252 OsiRowCut::operator!=(const OsiRowCut& rhs) const
253 {
254  return !( (*this)==rhs );
255 }
256 
257 
258 //----------------------------------------------------------------
259 // consistent & infeasible
260 //-------------------------------------------------------------------
261 bool OsiRowCut::consistent() const
262 {
263  const CoinPackedVector & r=row();
264  r.duplicateIndex("consistent", "OsiRowCut");
265  if ( r.getMinIndex() < 0 ) return false;
266  return true;
267 }
268 bool OsiRowCut::consistent(const OsiSolverInterface& im) const
269 {
270  const CoinPackedVector & r=row();
271  if ( r.getMaxIndex() >= im.getNumCols() ) return false;
272 
273  return true;
274 }
275 bool OsiRowCut::infeasible(const OsiSolverInterface &im) const
276 {
277  if ( lb() > ub() ) return true;
278 
279  return false;
280 }
281 
282 #endif
283 
290 class OsiRowCut2 : public OsiRowCut {
291 
292 public:
293 
296  inline int whichRow() const
298  { return whichRow_;}
300  inline void setWhichRow(int row)
301  { whichRow_=row;}
303 
306  OsiRowCut2 & operator=( const OsiRowCut2& rhs);
308 
310  OsiRowCut2 ( const OsiRowCut2 &);
311 
313  virtual OsiRowCut * clone() const;
314 
316  OsiRowCut2 (int row=-1);
317 
319  virtual ~OsiRowCut2 ();
321 
322 private:
323 
324 
327  int whichRow_;
330 };
331 #endif
int whichRow_
Which row.
Definition: OsiRowCut.hpp:328
double ub_
Row upper bound.
Definition: OsiRowCut.hpp:196
friend void OsiRowCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiRowCut class.
int getMaxIndex() const
Get value of maximum index.
virtual void print() const
Print cuts in collection.
virtual ~OsiRowCut2()
Destructor.
Row Cut Class.
Definition: OsiRowCut.hpp:29
virtual OsiRowCut * clone() const
Clone.
void setVector(int size, const int *inds, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set vector size, indices, and elements.
#define OsiRowCut_inline
Definition: OsiRowCut.hpp:17
virtual int getNumCols() const =0
Get the number of columns.
void sortIncrIndex()
Sort the packed storage vector.
OsiRowCut_inline bool operator!=(const OsiRowCut &rhs) const
not equal
Row Cut Class which refers back to row which created it.
Definition: OsiRowCut.hpp:290
void operator-=(double value)
subtract value from every vector entry
Definition: OsiRowCut.hpp:136
OsiRowCut()
Default Constructor.
OsiRowCut & operator=(const OsiRowCut &rhs)
Assignment operator.
int getMinIndex() const
Get value of minimum index.
OsiRowCut_inline double lb() const
Get lower bound.
OsiRowCut_inline const CoinPackedVector & row() const
Get row elements.
OsiRowCut_inline CoinPackedVector & mutableRow()
Get row elements for changing.
OsiRowCut_inline double ub() const
Get upper bound.
virtual ~OsiRowCut()
Destructor.
double range() const
Get range (ub - lb for &#39;R&#39; rows, 0 otherwise)
OsiRowCut_inline void setRow(int size, const int *colIndices, const double *elements, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set row elements.
#define COIN_DEFAULT_VALUE_FOR_DUPLICATE
OsiRowCut_inline bool consistent() const
Returns true if the cut is consistent.
Abstract Base Class for describing an interface to a solver.
OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const
Returns true if the row cut itself is infeasible and cannot be satisfied.
OsiRowCut2(const OsiRowCut2 &)
Copy constructor.
CoinPackedVector row_
Row elements.
Definition: OsiRowCut.hpp:192
char sense() const
Get sense (&#39;E&#39;, &#39;G&#39;, &#39;L&#39;, &#39;N&#39;, &#39;R&#39;)
OsiRowCut_inline void setUb(double ub)
Set upper bound.
Sparse Vector.
void operator+=(double value)
add value to every vector entry
Definition: OsiRowCut.hpp:132
void sortIncrIndex()
Allow access row sorting function.
Definition: OsiRowCut.hpp:149
void operator/=(double value)
divide every vector entry by value
Definition: OsiRowCut.hpp:144
double lb_
Row lower bound.
Definition: OsiRowCut.hpp:194
OsiRowCut_inline void setLb(double lb)
Set lower bound.
virtual OsiRowCut * clone() const
Clone.
OsiRowCut_inline bool operator==(const OsiRowCut &rhs) const
equal - true if lower bound, upper bound, row elements, and OsiCut are equal.
double rhs() const
Get right-hand side.
void operator*=(double value)
multiply every vector entry by value
Definition: OsiRowCut.hpp:140
void duplicateIndex(const char *methodName=NULL, const char *className=NULL) const
Throw an exception if there are duplicate indices.
void setWhichRow(int row)
Set row.
Definition: OsiRowCut.hpp:300
virtual double violated(const double *solution) const
Returns infeasibility of the cut with respect to solution passed in i.e.
int whichRow() const
Get row.
Definition: OsiRowCut.hpp:297
OsiRowCut2 & operator=(const OsiRowCut2 &rhs)
Assignment operator.