Osi 0.107.7

- 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
OsiColCut.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 OsiColCut_H
6 #define OsiColCut_H
7
8 #include <string>
9
10 #include "CoinPackedVector.hpp"
11
12 #include "OsiCollections.hpp"
13 #include "OsiCut.hpp"
14
23 class OsiColCut : public OsiCut {
24 friend void OsiColCutUnitTest(const OsiSolverInterface * baseSiP,
25 const std::string & mpsDir);
26
27 public:
28
29 //----------------------------------------------------------------
30
33 inline void setLbs(
35 int nElements,
36 const int * colIndices,
37 const double * lbElements );
38
40 inline void setLbs( const CoinPackedVector & lbs );
41
43 inline void setUbs(
44 int nElements,
45 const int * colIndices,
46 const double * ubElements );
47
49 inline void setUbs( const CoinPackedVector & ubs );
51
52 //----------------------------------------------------------------
53
56 inline const CoinPackedVector & lbs() const;
59 inline const CoinPackedVector & ubs() const;
61
64 #if __GNUC__ != 2
65 using OsiCut::operator== ;
66 #endif
67
70 inline virtual bool operator==(const OsiColCut& rhs) const;
71
72 #if __GNUC__ != 2
73 using OsiCut::operator!= ;
74 #endif
75 inline virtual bool operator!=(const OsiColCut& rhs) const;
78
79
80 //----------------------------------------------------------------
81
91 inline virtual bool consistent() const;
92
100 inline virtual bool consistent(const OsiSolverInterface& im) const;
101
110 inline virtual bool infeasible(const OsiSolverInterface &im) const;
115 virtual double violated(const double * solution) const;
117
118 //----------------------------------------------------------------
119
122 OsiColCut & operator=( const OsiColCut& rhs);
124
126 OsiColCut ( const OsiColCut &);
127
129 OsiColCut ();
130
132 virtual OsiColCut * clone() const;
133
135 virtual ~OsiColCut ();
137
140 virtual void print() const;
143
144 private:
145
148 CoinPackedVector lbs_;
151 CoinPackedVector ubs_;
153
154 };
155
156
157
158 //-------------------------------------------------------------------
159 // Set lower & upper bound vectors
160 //-------------------------------------------------------------------
161 void OsiColCut::setLbs(
162 int size,
163 const int * colIndices,
164 const double * lbElements )
165 {
166 lbs_.setVector(size,colIndices,lbElements);
167 }
168 //
169 void OsiColCut::setUbs(
170 int size,
171 const int * colIndices,
172 const double * ubElements )
173 {
174 ubs_.setVector(size,colIndices,ubElements);
175 }
176 //
177 void OsiColCut::setLbs( const CoinPackedVector & lbs )
178 {
179 lbs_ = lbs;
180 }
181 //
182 void OsiColCut::setUbs( const CoinPackedVector & ubs )
183 {
184 ubs_ = ubs;
185 }
186
187 //-------------------------------------------------------------------
188 // Get Column Lower Bounds and Column Upper Bounds
189 //-------------------------------------------------------------------
190 const CoinPackedVector & OsiColCut::lbs() const
191 {
192 return lbs_;
193 }
194 //
195 const CoinPackedVector & OsiColCut::ubs() const
196 {
197 return ubs_;
198 }
199
200 //----------------------------------------------------------------
201 // == operator
202 //-------------------------------------------------------------------
203 bool
204 OsiColCut::operator==(
205 const OsiColCut& rhs) const
206 {
207 if ( this->OsiCut::operator!=(rhs) )
208 return false;
209 if ( lbs() != rhs.lbs() )
210 return false;
211 if ( ubs() != rhs.ubs() )
212 return false;
213 return true;
214 }
215 //
216 bool
217 OsiColCut::operator!=(
218 const OsiColCut& rhs) const
219 {
220 return !( (*this)==rhs );
221 }
222
223 //----------------------------------------------------------------
224 // consistent & infeasible
225 //-------------------------------------------------------------------
226 bool OsiColCut::consistent() const
227 {
228 const CoinPackedVector & lb = lbs();
229 const CoinPackedVector & ub = ubs();
230 // Test for consistent cut.
231 // Are packed vectors consistent?
232 lb.duplicateIndex("consistent", "OsiColCut");
233 ub.duplicateIndex("consistent", "OsiColCut");
234 if ( lb.getMinIndex() < 0 ) return false;
235 if ( ub.getMinIndex() < 0 ) return false;
236 return true;
237 }
238 //
239 bool OsiColCut::consistent(const OsiSolverInterface& im) const
240 {
241 const CoinPackedVector & lb = lbs();
242 const CoinPackedVector & ub = ubs();
243
244 // Test for consistent cut.
245 if ( lb.getMaxIndex() >= im.getNumCols() ) return false;
246 if ( ub.getMaxIndex() >= im.getNumCols() ) return false;
247
248 return true;
249 }
250
251 #if 0
252 bool OsiColCut::feasible(const OsiSolverInterface &im) const
253 {
254 const double * oldColLb = im.getColLower();
255 const double * oldColUb = im.getColUpper();
256 const CoinPackedVector & cutLbs = lbs();
257 const CoinPackedVector & cutUbs = ubs();
258 int i;
259
260 for ( i=0; i<cutLbs.size(); i++ ) {
261 int colIndx = cutLbs.indices()[i];
262 double newLb;
263 if ( cutLbs.elements()[i] > oldColLb[colIndx] )
264 newLb = cutLbs.elements()[i];
265 else
266 newLb = oldColLb[colIndx];
267
268 double newUb = oldColUb[colIndx];
269 if ( cutUbs.indexExists(colIndx) )
270 if ( cutUbs[colIndx] < newUb ) newUb = cutUbs[colIndx];
271 if ( newLb > newUb )
272 return false;
273 }
274
275 for ( i=0; i<cutUbs.size(); i++ ) {
276 int colIndx = cutUbs.indices()[i];
277 double newUb = cutUbs.elements()[i] < oldColUb[colIndx] ? cutUbs.elements()[i] : oldColUb[colIndx];
278 double newLb = oldColLb[colIndx];
279 if ( cutLbs.indexExists(colIndx) )
280 if ( cutLbs[colIndx] > newLb ) newLb = cutLbs[colIndx];
281 if ( newUb < newLb )
282 return false;
283 }
284
285 return true;
286 }
287 #endif
288
289
290 bool OsiColCut::infeasible(const OsiSolverInterface &im) const
291 {
292 const double * oldColLb = im.getColLower();
293 const double * oldColUb = im.getColUpper();
294 const CoinPackedVector & cutLbs = lbs();
295 const CoinPackedVector & cutUbs = ubs();
296 int i;
297
298 for ( i=0; i<cutLbs.getNumElements(); i++ ) {
299 int colIndx = cutLbs.getIndices()[i];
300 double newLb= cutLbs.getElements()[i] > oldColLb[colIndx] ?
301 cutLbs.getElements()[i] : oldColLb[colIndx];
302
303 double newUb = oldColUb[colIndx];
304 if ( cutUbs.isExistingIndex(colIndx) )
305 if ( cutUbs[colIndx] < newUb ) newUb = cutUbs[colIndx];
306 if ( newLb > newUb )
307 return true;
308 }
309
310 for ( i=0; i<cutUbs.getNumElements(); i++ ) {
311 int colIndx = cutUbs.getIndices()[i];
312 double newUb = cutUbs.getElements()[i] < oldColUb[colIndx] ?
313 cutUbs.getElements()[i] : oldColUb[colIndx];
314 double newLb = oldColLb[colIndx];
315 if ( cutLbs.isExistingIndex(colIndx) )
316 if ( cutLbs[colIndx] > newLb ) newLb = cutLbs[colIndx];
317 if ( newUb < newLb )
318 return true;
319 }
320
321 return false;
322 }
323
324 #endif
OsiColCut::infeasible
virtual bool infeasible(const OsiSolverInterface &im) const
Returns true if the cut is infeasible with respect to its bounds and the column bounds in the solve...
Definition: OsiColCut.hpp:290
OsiColCut::lbs_
CoinPackedVector lbs_
Lower bounds.
Definition: OsiColCut.hpp:149
OsiColCut::clone
virtual OsiColCut * clone() const
Clone.
OsiColCut::setLbs
void setLbs(int nElements, const int *colIndices, const double *lbElements)
Set column lower bounds.
Definition: OsiColCut.hpp:161
CoinPackedVectorBase::isExistingIndex
bool isExistingIndex(int i) const
Return true if the i&#39;th element of the full storage vector exists in the packed storage vector...
OsiCut.hpp
CoinPackedVector::getNumElements
virtual int getNumElements() const
Get the size.
Definition: CoinPackedVector.hpp:130
CoinPackedVectorBase::getMinIndex
int getMinIndex() const
Get value of minimum index.
CoinPackedVector.hpp
OsiColCut
Column Cut Class.
Definition: OsiColCut.hpp:23
CoinPackedVector::getElements
virtual const double * getElements() const
Get element values.
Definition: CoinPackedVector.hpp:134
OsiColCut::operator==
virtual bool operator==(const OsiColCut &rhs) const
equal - true if lower bounds, upper bounds, and OsiCut are equal.
Definition: OsiColCut.hpp:204
OsiColCut::~OsiColCut
virtual ~OsiColCut()
Destructor.
OsiSolverInterface::getNumCols
virtual int getNumCols() const =0
Get the number of columns.
OsiColCut::print
virtual void print() const
Print cuts in collection.
OsiSolverInterface
Abstract Base Class for describing an interface to a solver.
Definition: OsiSolverInterface.hpp:62
OsiColCut::ubs_
CoinPackedVector ubs_
Upper bounds.
Definition: OsiColCut.hpp:151
OsiColCut::OsiColCutUnitTest
friend void OsiColCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiColCut class.
OsiColCut::OsiColCut
OsiColCut()
Default Constructor.
OsiSolverInterface::getColLower
virtual const double * getColLower() const =0
Get a pointer to an array[getNumCols()] of column lower bounds.
OsiColCut::consistent
virtual bool consistent() const
Returns true if the cut is consistent with respect to itself.
Definition: OsiColCut.hpp:226
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.
OsiCut
Definition: OsiCut.hpp:36
OsiColCut::operator=
OsiColCut & operator=(const OsiColCut &rhs)
Assignment operator.
OsiColCut::setUbs
void setUbs(int nElements, const int *colIndices, const double *ubElements)
Set column upper bounds.
Definition: OsiColCut.hpp:169
OsiCollections.hpp
OsiColCut::violated
virtual double violated(const double *solution) const
Returns infeasibility of the cut with respect to solution passed in i.e.
OsiColCut::lbs
const CoinPackedVector & lbs() const
Get column lower bounds.
Definition: OsiColCut.hpp:190
CoinPackedVectorBase::duplicateIndex
void duplicateIndex(const char *methodName=NULL, const char *className=NULL) const
Throw an exception if there are duplicate indices.
OsiColCut::operator!=
virtual bool operator!=(const OsiColCut &rhs) const
not equal
Definition: OsiColCut.hpp:217
CoinPackedVector::getIndices
virtual const int * getIndices() const
Get indices of elements.
Definition: CoinPackedVector.hpp:132
CoinPackedVector
Sparse Vector.
Definition: CoinPackedVector.hpp:123
CoinPackedVectorBase::getMaxIndex
int getMaxIndex() const
Get value of maximum index.
OsiColCut::ubs
const CoinPackedVector & ubs() const
Get column upper bounds.
Definition: OsiColCut.hpp:195
OsiSolverInterface::getColUpper
virtual const double * getColUpper() const =0
Get a pointer to an array[getNumCols()] of column upper bounds.