Osi 0.108.9
Loading...
Searching...
No Matches
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
23class OsiColCut : public OsiCut {
24 friend void OsiColCutUnitTest(const OsiSolverInterface *baseSiP,
25 const std::string &mpsDir);
26
27public:
28 //----------------------------------------------------------------
29
33 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
56 inline const CoinPackedVector &lbs() const;
58 inline const CoinPackedVector &ubs() const;
60
63#if __GNUC__ != 2
64 using OsiCut::operator==;
65#endif
69 inline virtual bool operator==(const OsiColCut &rhs) const;
70
71#if __GNUC__ != 2
72 using OsiCut::operator!=;
73#endif
75 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
122
125
128
130 virtual OsiColCut *clone() const;
131
133 virtual ~OsiColCut();
135
139 virtual void print() const;
141
142private:
146 CoinPackedVector lbs_;
148 CoinPackedVector ubs_;
150};
151
152//-------------------------------------------------------------------
153// Set lower & upper bound vectors
154//-------------------------------------------------------------------
156 int size,
157 const int *colIndices,
158 const double *lbElements)
159{
160 lbs_.setVector(size, colIndices, lbElements);
161}
162//
164 int size,
165 const int *colIndices,
166 const double *ubElements)
167{
168 ubs_.setVector(size, colIndices, ubElements);
169}
170//
171void OsiColCut::setLbs(const CoinPackedVector &lbs)
172{
173 lbs_ = lbs;
174}
175//
176void OsiColCut::setUbs(const CoinPackedVector &ubs)
177{
178 ubs_ = ubs;
179}
180
181//-------------------------------------------------------------------
182// Get Column Lower Bounds and Column Upper Bounds
183//-------------------------------------------------------------------
184const CoinPackedVector &OsiColCut::lbs() const
185{
186 return lbs_;
187}
188//
189const CoinPackedVector &OsiColCut::ubs() const
190{
191 return ubs_;
192}
193
194//----------------------------------------------------------------
195// == operator
196//-------------------------------------------------------------------
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//
210 const OsiColCut &rhs) const
211{
212 return !((*this) == rhs);
213}
214
215//----------------------------------------------------------------
216// consistent & infeasible
217//-------------------------------------------------------------------
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//
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
248bool 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
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*/
Column Cut Class.
Definition OsiColCut.hpp:23
CoinPackedVector lbs_
Lower bounds.
virtual OsiColCut * clone() const
Clone.
OsiColCut(const OsiColCut &)
Copy constructor.
OsiColCut()
Default Constructor.
void setUbs(int nElements, const int *colIndices, const double *ubElements)
Set column upper bounds.
const CoinPackedVector & lbs() const
Get column lower bounds.
CoinPackedVector ubs_
Upper bounds.
const CoinPackedVector & ubs() const
Get column upper bounds.
virtual ~OsiColCut()
Destructor.
virtual bool operator!=(const OsiColCut &rhs) const
not equal
virtual bool operator==(const OsiColCut &rhs) const
equal - true if lower bounds, upper bounds, and OsiCut are equal.
OsiColCut & operator=(const OsiColCut &rhs)
Assignment operator.
virtual void print() const
Print cuts in collection.
virtual double violated(const double *solution) const
Returns infeasibility of the cut with respect to solution passed in i.e.
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 solver ...
void setLbs(int nElements, const int *colIndices, const double *lbElements)
Set column lower bounds.
virtual bool consistent() const
Returns true if the cut is consistent with respect to itself.
friend void OsiColCutUnitTest(const OsiSolverInterface *baseSiP, const std::string &mpsDir)
A function that tests the methods in the OsiColCut class.
Abstract Base Class for describing an interface to a solver.
virtual const double * getColUpper() const =0
Get a pointer to an array[getNumCols()] of column upper bounds.
virtual const double * getColLower() const =0
Get a pointer to an array[getNumCols()] of column lower bounds.
virtual int getNumCols() const =0
Get the number of columns.