Clp 1.17.6

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //-------------------------------------------------------------------
59 OsiRowCut_inline void setRow(
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
155 void sortIncrIndex()
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
319 OsiRowCut2 &operator=(const OsiRowCut2 &rhs);
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 */
OsiRowCut2::whichRow_
int whichRow_
Which row.
Definition: OsiRowCut.hpp:339
OsiRowCut::ub_
double ub_
Row upper bound.
Definition: OsiRowCut.hpp:202
OsiRowCut::operator+=
void operator+=(double value)
add value to every vector entry
Definition: OsiRowCut.hpp:130
OsiRowCut::OsiRowCutUnitTest
friend void OsiRowCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiRowCut class.
OsiRowCut::operator!=
OsiRowCut_inline bool operator!=(const OsiRowCut &rhs) const
not equal
OsiRowCut::lb_
double lb_
Row lower bound.
Definition: OsiRowCut.hpp:200
OsiRowCut2::OsiRowCut2
OsiRowCut2(const OsiRowCut2 &)
Copy constructor.
OsiRowCut::lb
OsiRowCut_inline double lb() const
Get lower bound.
OsiRowCut_inline
#define OsiRowCut_inline
Definition: OsiRowCut.hpp:17
OsiRowCut::rhs
double rhs() const
Get right-hand side.
OsiRowCut::setUb
OsiRowCut_inline void setUb(double ub)
Set upper bound.
OsiRowCut::~OsiRowCut
virtual ~OsiRowCut()
Destructor.
OsiRowCut2::~OsiRowCut2
virtual ~OsiRowCut2()
Destructor.
OsiCut.hpp
CoinPackedVectorBase::getMinIndex
int getMinIndex() const
Get value of minimum index.
CoinPackedVector.hpp
OsiRowCut::operator=
OsiRowCut & operator=(const OsiRowCut &rhs)
Assignment operator.
OsiRowCut::clone
virtual OsiRowCut * clone() const
Clone.
OsiRowCut::print
virtual void print() const
Print cuts in collection.
OsiSolverInterface::getNumCols
virtual int getNumCols() const =0
Get the number of columns.
OsiRowCut2::clone
virtual OsiRowCut * clone() const
Clone.
OsiSolverInterface
Abstract Base Class for describing an interface to a solver.
Definition: OsiSolverInterface.hpp:61
OsiRowCut::range
double range() const
Get range (ub - lb for &#39;R&#39; rows, 0 otherwise)
OsiRowCut2
Row Cut Class which refers back to row which created it.
Definition: OsiRowCut.hpp:300
OsiRowCut::ub
OsiRowCut_inline double ub() const
Get upper bound.
CoinPackedVector::sortIncrIndex
void sortIncrIndex()
Definition: CoinPackedVector.hpp:245
OsiRowCut::row
OsiRowCut_inline const CoinPackedVector & row() const
Get row elements.
COIN_DEFAULT_VALUE_FOR_DUPLICATE
#define COIN_DEFAULT_VALUE_FOR_DUPLICATE
Definition: CoinPackedVector.hpp:22
OsiRowCut::sense
char sense() const
Get sense (&#39;E&#39;, &#39;G&#39;, &#39;L&#39;, &#39;N&#39;, &#39;R&#39;)
CoinPackedVector::setVector
void setVector(int size, const int *inds, const double *elems, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set vector size, indices, and elements.
OsiRowCut::mutableRow
OsiRowCut_inline CoinPackedVector & mutableRow()
Get row elements for changing.
OsiRowCut
Row Cut Class.
Definition: OsiRowCut.hpp:29
OsiRowCut::operator-=
void operator-=(double value)
subtract value from every vector entry
Definition: OsiRowCut.hpp:136
OsiRowCut::operator/=
void operator/=(double value)
divide every vector entry by value
Definition: OsiRowCut.hpp:148
OsiCut
Definition: OsiCut.hpp:35
OsiRowCut::setRow
OsiRowCut_inline void setRow(int size, const int *colIndices, const double *elements, bool testForDuplicateIndex=COIN_DEFAULT_VALUE_FOR_DUPLICATE)
Set row elements.
OsiRowCut::infeasible
OsiRowCut_inline bool infeasible(const OsiSolverInterface &im) const
Returns true if the row cut itself is infeasible and cannot be satisfied.
OsiRowCut::violated
virtual double violated(const double *solution) const
Returns infeasibility of the cut with respect to solution passed in i.e.
OsiCollections.hpp
OsiRowCut::OsiRowCut
OsiRowCut()
Default Constructor.
OsiRowCut::operator*=
void operator*=(double value)
multiply every vector entry by value
Definition: OsiRowCut.hpp:142
OsiRowCut2::whichRow
int whichRow() const
Get row.
Definition: OsiRowCut.hpp:306
CoinPackedVectorBase::duplicateIndex
void duplicateIndex(const char *methodName=NULL, const char *className=NULL) const
Throw an exception if there are duplicate indices.
OsiRowCut::sortIncrIndex
void sortIncrIndex()
Allow access row sorting function.
Definition: OsiRowCut.hpp:155
OsiRowCut::consistent
OsiRowCut_inline bool consistent() const
Returns true if the cut is consistent.
OsiRowCut::setLb
OsiRowCut_inline void setLb(double lb)
Set lower bound.
OsiRowCut::row_
CoinPackedVector row_
Row elements.
Definition: OsiRowCut.hpp:198
CoinPackedVector
Sparse Vector.
Definition: CoinPackedVector.hpp:123
CoinPackedVectorBase::getMaxIndex
int getMaxIndex() const
Get value of maximum index.
OsiRowCut2::operator=
OsiRowCut2 & operator=(const OsiRowCut2 &rhs)
Assignment operator.
OsiRowCut::operator==
OsiRowCut_inline bool operator==(const OsiRowCut &rhs) const
equal - true if lower bound, upper bound, row elements, and OsiCut are equal.
OsiRowCut2::setWhichRow
void setWhichRow(int row)
Set row.
Definition: OsiRowCut.hpp:311