Osi  0.108.8
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:
36  OsiRowCut_inline double lb() const;
39  OsiRowCut_inline void setLb(double lb);
41  OsiRowCut_inline double ub() const;
43  OsiRowCut_inline void setUb(double ub);
45 
48  char sense() const;
51  double rhs() const;
53  double range() const;
55 
56  //-------------------------------------------------------------------
61  int size,
62  const int *colIndices,
63  const double *elements,
64  bool testForDuplicateIndex = COIN_DEFAULT_VALUE_FOR_DUPLICATE);
66  OsiRowCut_inline void setRow(const CoinPackedVector &v);
68  OsiRowCut_inline const CoinPackedVector &row() const;
70  OsiRowCut_inline CoinPackedVector &mutableRow();
72 
75 #if __GNUC__ != 2
76  using OsiCut::operator==;
77 #endif
78 
81  OsiRowCut_inline bool operator==(const OsiRowCut &rhs) const;
82 
83 #if __GNUC__ != 2
84  using OsiCut::operator!=;
85 #endif
86  OsiRowCut_inline bool operator!=(const OsiRowCut &rhs) const;
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  {
132  row_ += value;
133  }
134 
136  void operator-=(double value)
137  {
138  row_ -= value;
139  }
140 
142  void operator*=(double value)
143  {
144  row_ *= value;
145  }
146 
148  void operator/=(double value)
149  {
150  row_ /= value;
151  }
153 
156  {
157  row_.sortIncrIndex();
158  }
159 
162  OsiRowCut &operator=(const OsiRowCut &rhs);
164 
166  OsiRowCut(const OsiRowCut &);
167 
169  virtual OsiRowCut *clone() const;
170 
172  OsiRowCut();
173 
180  OsiRowCut(double cutlb, double cutub,
181  int capacity, int size,
182  int *&colIndices, double *&elements);
183 
185  virtual ~OsiRowCut();
187 
190  virtual void print() const;
193 
194 private:
197  CoinPackedVector row_;
200  double lb_;
202  double ub_;
204 };
205 
206 #ifdef OSI_INLINE_ROWCUT_METHODS
207 
208 //-------------------------------------------------------------------
209 // Set/Get lower & upper bounds
210 //-------------------------------------------------------------------
211 double OsiRowCut::lb() const { return lb_; }
212 void OsiRowCut::setLb(double lb) { lb_ = lb; }
213 double OsiRowCut::ub() const { return ub_; }
214 void OsiRowCut::setUb(double ub) { ub_ = ub; }
215 
216 //-------------------------------------------------------------------
217 // Set row elements
218 //-------------------------------------------------------------------
219 void OsiRowCut::setRow(int size,
220  const int *colIndices, const double *elements)
221 {
222  row_.setVector(size, colIndices, elements);
223 }
224 void OsiRowCut::setRow(const CoinPackedVector &v)
225 {
226  row_ = v;
227 }
228 
229 //-------------------------------------------------------------------
230 // Get the row
231 //-------------------------------------------------------------------
232 const CoinPackedVector &OsiRowCut::row() const
233 {
234  return row_;
235 }
236 
237 //-------------------------------------------------------------------
238 // Get the row so we can change
239 //-------------------------------------------------------------------
240 CoinPackedVector &OsiRowCut::mutableRow()
241 {
242  return row_;
243 }
244 
245 //----------------------------------------------------------------
246 // == operator
247 //-------------------------------------------------------------------
248 bool OsiRowCut::operator==(const OsiRowCut &rhs) const
249 {
250  if (this->OsiCut::operator!=(rhs))
251  return false;
252  if (row() != rhs.row())
253  return false;
254  if (lb() != rhs.lb())
255  return false;
256  if (ub() != rhs.ub())
257  return false;
258  return true;
259 }
260 bool OsiRowCut::operator!=(const OsiRowCut &rhs) const
261 {
262  return !((*this) == rhs);
263 }
264 
265 //----------------------------------------------------------------
266 // consistent & infeasible
267 //-------------------------------------------------------------------
268 bool OsiRowCut::consistent() const
269 {
270  const CoinPackedVector &r = row();
271  r.duplicateIndex("consistent", "OsiRowCut");
272  if (r.getMinIndex() < 0)
273  return false;
274  return true;
275 }
276 bool OsiRowCut::consistent(const OsiSolverInterface &im) const
277 {
278  const CoinPackedVector &r = row();
279  if (r.getMaxIndex() >= im.getNumCols())
280  return false;
281 
282  return true;
283 }
284 bool OsiRowCut::infeasible(const OsiSolverInterface &im) const
285 {
286  if (lb() > ub())
287  return true;
288 
289  return false;
290 }
291 
292 #endif
293 
300 class OsiRowCut2 : public OsiRowCut {
301 
302 public:
305  inline int whichRow() const
307  {
308  return whichRow_;
309  }
311  inline void setWhichRow(int row)
312  {
313  whichRow_ = row;
314  }
316 
321 
323  OsiRowCut2(const OsiRowCut2 &);
324 
326  virtual OsiRowCut *clone() const;
327 
329  OsiRowCut2(int row = -1);
330 
332  virtual ~OsiRowCut2();
334 
335 private:
338  int whichRow_;
341 };
342 #endif
343 
344 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
345 */
OsiRowCut::clone
virtual OsiRowCut * clone() const
Clone.
OsiRowCut::rhs
double rhs() const
Get right-hand side.
OsiCollections.hpp
OsiRowCut::operator/=
void operator/=(double value)
divide every vector entry by value
Definition: OsiRowCut.hpp:148
OsiRowCut::operator!=
OsiRowCut_inline bool operator!=(const OsiRowCut &rhs) const
not equal
OsiRowCut::operator=
OsiRowCut & operator=(const OsiRowCut &rhs)
Assignment operator.
OsiRowCut::infeasible
OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const
Returns true if the row cut itself is infeasible and cannot be satisfied.
COIN_DEFAULT_VALUE_FOR_DUPLICATE
#define COIN_DEFAULT_VALUE_FOR_DUPLICATE
Base Class for cut.
Definition: OsiCut.hpp:30
OsiRowCut_inline
#define OsiRowCut_inline
Definition: OsiRowCut.hpp:17
OsiRowCut::~OsiRowCut
virtual ~OsiRowCut()
Destructor.
OsiRowCut::violated
virtual double violated(const double *solution) const
Returns infeasibility of the cut with respect to solution passed in i.e.
OsiRowCut::operator+=
void operator+=(double value)
add value to every vector entry
Definition: OsiRowCut.hpp:130
OsiRowCut::range
double range() const
Get range (ub - lb for 'R' rows, 0 otherwise)
OsiRowCut::operator-=
void operator-=(double value)
subtract value from every vector entry
Definition: OsiRowCut.hpp:136
OsiRowCut::row
const OsiRowCut_inline CoinPackedVector & row() const
Get row elements.
OsiRowCut::print
virtual void print() const
Print cuts in collection.
OsiRowCut
Row Cut Class.
Definition: OsiRowCut.hpp:29
OsiRowCut::OsiRowCut
OsiRowCut()
Default Constructor.
OsiCut.hpp
OsiRowCut2::~OsiRowCut2
virtual ~OsiRowCut2()
Destructor.
OsiRowCut::setRow
OsiRowCut_inline void setRow(int size, const int *colIndices, const double *elements, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set row elements.
OsiRowCut2::operator=
OsiRowCut2 & operator=(const OsiRowCut2 &rhs)
Assignment operator.
OsiRowCut2::whichRow_
int whichRow_
Which row.
Definition: OsiRowCut.hpp:339
OsiRowCut::operator==
OsiRowCut_inline bool operator==(const OsiRowCut &rhs) const
equal - true if lower bound, upper bound, row elements, and OsiCut are equal.
OsiRowCut2::whichRow
int whichRow() const
Get row.
Definition: OsiRowCut.hpp:306
OsiRowCut::lb_
double lb_
Row lower bound.
Definition: OsiRowCut.hpp:200
OsiRowCut2::setWhichRow
void setWhichRow(int row)
Set row.
Definition: OsiRowCut.hpp:311
OsiRowCut2::OsiRowCut2
OsiRowCut2(const OsiRowCut2 &)
Copy constructor.
OsiRowCut::sortIncrIndex
void sortIncrIndex()
Allow access row sorting function.
Definition: OsiRowCut.hpp:155
OsiRowCut::operator*=
void operator*=(double value)
multiply every vector entry by value
Definition: OsiRowCut.hpp:142
OsiRowCut::setLb
OsiRowCut_inline void setLb(double lb)
Set lower bound.
OsiRowCut::mutableRow
OsiRowCut_inline CoinPackedVector & mutableRow()
Get row elements for changing.
OsiRowCut::row_
CoinPackedVector row_
Row elements.
Definition: OsiRowCut.hpp:198
OsiRowCut::ub
OsiRowCut_inline double ub() const
Get upper bound.
OsiRowCut::consistent
OsiRowCut_inline bool consistent() const
Returns true if the cut is consistent.
OsiRowCut::lb
OsiRowCut_inline double lb() const
Get lower bound.
OsiRowCut::ub_
double ub_
Row upper bound.
Definition: OsiRowCut.hpp:202
OsiRowCut2::clone
virtual OsiRowCut * clone() const
Clone.
OsiRowCut::setUb
OsiRowCut_inline void setUb(double ub)
Set upper bound.
OsiSolverInterface::getNumCols
virtual int getNumCols() const =0
Get the number of columns.
OsiRowCut::sense
char sense() const
Get sense ('E', 'G', 'L', 'N', 'R')
OsiRowCut::OsiRowCutUnitTest
friend void OsiRowCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiRowCut class.
OsiCut
Definition: OsiCut.hpp:35
OsiSolverInterface
Abstract Base Class for describing an interface to a solver.
Definition: OsiSolverInterface.hpp:61
OsiRowCut2
Row Cut Class which refers back to row which created it.
Definition: OsiRowCut.hpp:300