Osi 0.107.10

- 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:
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 //-------------------------------------------------------------------
60 OsiRowCut_inline void setRow(
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;
71 OsiRowCut_inline CoinPackedVector & mutableRow() ;
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
149 void sortIncrIndex()
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
191 CoinPackedVector row_;
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 //-------------------------------------------------------------------
234 CoinPackedVector & OsiRowCut::mutableRow()
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
OsiRowCut2::whichRow_
int whichRow_
Which row.
Definition: OsiRowCut.hpp:328
OsiRowCut::ub_
double ub_
Row upper bound.
Definition: OsiRowCut.hpp:196
OsiRowCut::operator+=
void operator+=(double value)
add value to every vector entry
Definition: OsiRowCut.hpp:132
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:194
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:62
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:290
OsiRowCut::ub
OsiRowCut_inline double ub() const
Get upper bound.
CoinPackedVector::sortIncrIndex
void sortIncrIndex()
Definition: CoinPackedVector.hpp:243
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:144
OsiCut
Definition: OsiCut.hpp:36
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:140
OsiRowCut2::whichRow
int whichRow() const
Get row.
Definition: OsiRowCut.hpp:297
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:149
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:192
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:300