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
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
32 inline void setLbs(
34 int nElements,
35 const int *colIndices,
36 const double *lbElements);
37
39 inline void setLbs(const CoinPackedVector &lbs);
40
42 inline void setUbs(
43 int nElements,
44 const int *colIndices,
45 const double *ubElements);
46
48 inline void setUbs(const CoinPackedVector &ubs);
50
51 //----------------------------------------------------------------
52
55 inline const CoinPackedVector &lbs() const;
58 inline const CoinPackedVector &ubs() const;
60
63 #if __GNUC__ != 2
64 using OsiCut::operator==;
65 #endif
66
69 inline virtual bool operator==(const OsiColCut &rhs) const;
70
71 #if __GNUC__ != 2
72 using OsiCut::operator!=;
73 #endif
74 inline virtual bool operator!=(const OsiColCut &rhs) const;
77
78 //----------------------------------------------------------------
79
89 inline virtual bool consistent() const;
90
98 inline virtual bool consistent(const OsiSolverInterface &im) const;
99
108 inline virtual bool infeasible(const OsiSolverInterface &im) const;
113 virtual double violated(const double *solution) const;
115
116 //----------------------------------------------------------------
117
120 OsiColCut &operator=(const OsiColCut &rhs);
122
124 OsiColCut(const OsiColCut &);
125
127 OsiColCut();
128
130 virtual OsiColCut *clone() const;
131
133 virtual ~OsiColCut();
135
138 virtual void print() const;
141
142 private:
145 CoinPackedVector lbs_;
148 CoinPackedVector ubs_;
150 };
151
152 //-------------------------------------------------------------------
153 // Set lower & upper bound vectors
154 //-------------------------------------------------------------------
155 void OsiColCut::setLbs(
156 int size,
157 const int *colIndices,
158 const double *lbElements)
159 {
160 lbs_.setVector(size, colIndices, lbElements);
161 }
162 //
163 void OsiColCut::setUbs(
164 int size,
165 const int *colIndices,
166 const double *ubElements)
167 {
168 ubs_.setVector(size, colIndices, ubElements);
169 }
170 //
171 void OsiColCut::setLbs(const CoinPackedVector &lbs)
172 {
173 lbs_ = lbs;
174 }
175 //
176 void OsiColCut::setUbs(const CoinPackedVector &ubs)
177 {
178 ubs_ = ubs;
179 }
180
181 //-------------------------------------------------------------------
182 // Get Column Lower Bounds and Column Upper Bounds
183 //-------------------------------------------------------------------
184 const CoinPackedVector &OsiColCut::lbs() const
185 {
186 return lbs_;
187 }
188 //
189 const CoinPackedVector &OsiColCut::ubs() const
190 {
191 return ubs_;
192 }
193
194 //----------------------------------------------------------------
195 // == operator
196 //-------------------------------------------------------------------
197 bool OsiColCut::operator==(
198 const OsiColCut &rhs) const
199 {
200 if (this->OsiCut::operator!=(rhs))
201 return false;
202 if (lbs() != rhs.lbs())
203 return false;
204 if (ubs() != rhs.ubs())
205 return false;
206 return true;
207 }
208 //
209 bool OsiColCut::operator!=(
210 const OsiColCut &rhs) const
211 {
212 return !((*this) == rhs);
213 }
214
215 //----------------------------------------------------------------
216 // consistent & infeasible
217 //-------------------------------------------------------------------
218 bool OsiColCut::consistent() const
219 {
220 const CoinPackedVector &lb = lbs();
221 const CoinPackedVector &ub = ubs();
222 // Test for consistent cut.
223 // Are packed vectors consistent?
224 lb.duplicateIndex("consistent", "OsiColCut");
225 ub.duplicateIndex("consistent", "OsiColCut");
226 if (lb.getMinIndex() < 0)
227 return false;
228 if (ub.getMinIndex() < 0)
229 return false;
230 return true;
231 }
232 //
233 bool OsiColCut::consistent(const OsiSolverInterface &im) const
234 {
235 const CoinPackedVector &lb = lbs();
236 const CoinPackedVector &ub = ubs();
237
238 // Test for consistent cut.
239 if (lb.getMaxIndex() >= im.getNumCols())
240 return false;
241 if (ub.getMaxIndex() >= im.getNumCols())
242 return false;
243
244 return true;
245 }
246
247 #if 0
248 bool OsiColCut::feasible(const OsiSolverInterface &im) const
249 {
250 const double * oldColLb = im.getColLower();
251 const double * oldColUb = im.getColUpper();
252 const CoinPackedVector & cutLbs = lbs();
253 const CoinPackedVector & cutUbs = ubs();
254 int i;
255
256 for ( i=0; i<cutLbs.size(); i++ ) {
257 int colIndx = cutLbs.indices()[i];
258 double newLb;
259 if ( cutLbs.elements()[i] > oldColLb[colIndx] )
260 newLb = cutLbs.elements()[i];
261 else
262 newLb = oldColLb[colIndx];
263
264 double newUb = oldColUb[colIndx];
265 if ( cutUbs.indexExists(colIndx) )
266 if ( cutUbs[colIndx] < newUb ) newUb = cutUbs[colIndx];
267 if ( newLb > newUb )
268 return false;
269 }
270
271 for ( i=0; i<cutUbs.size(); i++ ) {
272 int colIndx = cutUbs.indices()[i];
273 double newUb = cutUbs.elements()[i] < oldColUb[colIndx] ? cutUbs.elements()[i] : oldColUb[colIndx];
274 double newLb = oldColLb[colIndx];
275 if ( cutLbs.indexExists(colIndx) )
276 if ( cutLbs[colIndx] > newLb ) newLb = cutLbs[colIndx];
277 if ( newUb < newLb )
278 return false;
279 }
280
281 return true;
282 }
283 #endif
284
285 bool OsiColCut::infeasible(const OsiSolverInterface &im) const
286 {
287 const double *oldColLb = im.getColLower();
288 const double *oldColUb = im.getColUpper();
289 const CoinPackedVector &cutLbs = lbs();
290 const CoinPackedVector &cutUbs = ubs();
291 int i;
292
293 for (i = 0; i < cutLbs.getNumElements(); i++) {
294 int colIndx = cutLbs.getIndices()[i];
295 double newLb = cutLbs.getElements()[i] > oldColLb[colIndx] ? cutLbs.getElements()[i] : oldColLb[colIndx];
296
297 double newUb = oldColUb[colIndx];
298 if (cutUbs.isExistingIndex(colIndx))
299 if (cutUbs[colIndx] < newUb)
300 newUb = cutUbs[colIndx];
301 if (newLb > newUb)
302 return true;
303 }
304
305 for (i = 0; i < cutUbs.getNumElements(); i++) {
306 int colIndx = cutUbs.getIndices()[i];
307 double newUb = cutUbs.getElements()[i] < oldColUb[colIndx] ? cutUbs.getElements()[i] : oldColUb[colIndx];
308 double newLb = oldColLb[colIndx];
309 if (cutLbs.isExistingIndex(colIndx))
310 if (cutLbs[colIndx] > newLb)
311 newLb = cutLbs[colIndx];
312 if (newUb < newLb)
313 return true;
314 }
315
316 return false;
317 }
318
319 #endif
320
321 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
322 */
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:285
OsiColCut::lbs_
CoinPackedVector lbs_
Lower bounds.
Definition: OsiColCut.hpp:146
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:155
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:197
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:61
OsiColCut::ubs_
CoinPackedVector ubs_
Upper bounds.
Definition: OsiColCut.hpp:148
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:218
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:35
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:163
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:184
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:209
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:189
OsiSolverInterface::getColUpper
virtual const double * getColUpper() const =0
Get a pointer to an array[getNumCols()] of column upper bounds.