Osi 0.108.9
Loading...
Searching...
No Matches
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
29class OsiRowCut : public OsiCut {
30 friend void OsiRowCutUnitTest(const OsiSolverInterface *baseSiP,
31 const std::string &mpsDir);
32
33public:
37 OsiRowCut_inline double lb() const;
41 OsiRowCut_inline double ub() const;
45
49 char sense() const;
51 double rhs() const;
53 double range() const;
55
56 //-------------------------------------------------------------------
59
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
82
83#if __GNUC__ != 2
84 using OsiCut::operator!=;
85#endif
89
90 //----------------------------------------------------------------
101
111
124 virtual double violated(const double *solution) const;
126
130 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
164
167
169 virtual OsiRowCut *clone() const;
170
173
180 OsiRowCut(double cutlb, double cutub,
181 int capacity, int size,
182 int *&colIndices, double *&elements);
183
185 virtual ~OsiRowCut();
187
191 virtual void print() const;
193
194private:
198 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//-------------------------------------------------------------------
211double OsiRowCut::lb() const { return lb_; }
212void OsiRowCut::setLb(double lb) { lb_ = lb; }
213double OsiRowCut::ub() const { return ub_; }
214void OsiRowCut::setUb(double ub) { ub_ = ub; }
215
216//-------------------------------------------------------------------
217// Set row elements
218//-------------------------------------------------------------------
219void OsiRowCut::setRow(int size,
220 const int *colIndices, const double *elements)
221{
222 row_.setVector(size, colIndices, elements);
223}
224void OsiRowCut::setRow(const CoinPackedVector &v)
225{
226 row_ = v;
227}
228
229//-------------------------------------------------------------------
230// Get the row
231//-------------------------------------------------------------------
232const CoinPackedVector &OsiRowCut::row() const
233{
234 return row_;
235}
236
237//-------------------------------------------------------------------
238// Get the row so we can change
239//-------------------------------------------------------------------
240CoinPackedVector &OsiRowCut::mutableRow()
241{
242 return row_;
243}
244
245//----------------------------------------------------------------
246// == operator
247//-------------------------------------------------------------------
248bool 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}
260bool OsiRowCut::operator!=(const OsiRowCut &rhs) const
261{
262 return !((*this) == rhs);
263}
264
265//----------------------------------------------------------------
266// consistent & infeasible
267//-------------------------------------------------------------------
268bool 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}
276bool 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}
284bool OsiRowCut::infeasible(const OsiSolverInterface &im) const
285{
286 if (lb() > ub())
287 return true;
288
289 return false;
290}
291
292#endif
293
300class OsiRowCut2 : public OsiRowCut {
301
302public:
306 inline int whichRow() const
307 {
308 return whichRow_;
309 }
311 inline void setWhichRow(int row)
312 {
313 whichRow_ = row;
314 }
316
321
324
326 virtual OsiRowCut *clone() const;
327
329 OsiRowCut2(int row = -1);
330
332 virtual ~OsiRowCut2();
334
335private:
341};
342#endif
343
344/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
345*/
#define COIN_DEFAULT_VALUE_FOR_DUPLICATE
Base Class for cut.
Definition OsiCut.hpp:30
#define OsiRowCut_inline
Definition OsiRowCut.hpp:17
Row Cut Class which refers back to row which created it.
OsiRowCut2(const OsiRowCut2 &)
Copy constructor.
void setWhichRow(int row)
Set row.
OsiRowCut2 & operator=(const OsiRowCut2 &rhs)
Assignment operator.
int whichRow_
Which row.
virtual OsiRowCut * clone() const
Clone.
OsiRowCut2(int row=-1)
Default Constructor.
virtual ~OsiRowCut2()
Destructor.
int whichRow() const
Get row.
Row Cut Class.
Definition OsiRowCut.hpp:29
OsiRowCut_inline bool operator!=(const OsiRowCut &rhs) const
not equal
char sense() const
Get sense ('E', 'G', 'L', 'N', 'R')
void sortIncrIndex()
Allow access row sorting function.
OsiRowCut_inline bool consistent() const
Returns true if the cut is consistent.
double rhs() const
Get right-hand side.
virtual void print() const
Print cuts in collection.
OsiRowCut_inline void setUb(double ub)
Set upper bound.
OsiRowCut_inline void setLb(double lb)
Set lower bound.
void operator*=(double value)
multiply every vector entry by value
OsiRowCut_inline const CoinPackedVector & row() const
Get row elements.
OsiRowCut(const OsiRowCut &)
Copy constructor.
OsiRowCut & operator=(const OsiRowCut &rhs)
Assignment operator.
virtual double violated(const double *solution) const
Returns infeasibility of the cut with respect to solution passed in i.e.
OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const
Returns true if the row cut itself is infeasible and cannot be satisfied.
OsiRowCut_inline bool consistent(const OsiSolverInterface &im) const
Returns true if cut is consistent with respect to the solver interface's model.
virtual ~OsiRowCut()
Destructor.
CoinPackedVector row_
Row elements.
OsiRowCut_inline CoinPackedVector & mutableRow()
Get row elements for changing.
OsiRowCut_inline void setRow(const CoinPackedVector &v)
Set row elements from a packed vector.
OsiRowCut_inline double lb() const
Get lower bound.
void operator/=(double value)
divide every vector entry by value
OsiRowCut_inline double ub() const
Get upper bound.
OsiRowCut()
Default Constructor.
OsiRowCut_inline void setRow(int size, const int *colIndices, const double *elements, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set row elements.
void operator-=(double value)
subtract value from every vector entry
friend void OsiRowCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiRowCut class.
virtual OsiRowCut * clone() const
Clone.
double lb_
Row lower bound.
void operator+=(double value)
add value to every vector entry
double range() const
Get range (ub - lb for 'R' rows, 0 otherwise)
OsiRowCut_inline bool operator==(const OsiRowCut &rhs) const
equal - true if lower bound, upper bound, row elements, and OsiCut are equal.
OsiRowCut(double cutlb, double cutub, int capacity, int size, int *&colIndices, double *&elements)
Ownership Constructor.
double ub_
Row upper bound.
Abstract Base Class for describing an interface to a solver.
virtual int getNumCols() const =0
Get the number of columns.