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
OsiCuts.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 OsiCuts_H
6 #define OsiCuts_H
7
8 #include "CoinPragma.hpp"
9
10 #include <cmath>
11 #include <cfloat>
12 #include "OsiCollections.hpp"
13 #include "OsiRowCut.hpp"
14 #include "OsiColCut.hpp"
15 #include "CoinFloatEqual.hpp"
16
19 class OsiCuts {
20 friend void OsiCutsUnitTest();
21
22 public:
30 class iterator {
31 friend class OsiCuts;
32
33 public:
34 iterator(OsiCuts &cuts);
35 iterator(const iterator &src);
36 iterator &operator=(const iterator &rhs);
37 ~iterator();
38 OsiCut *operator*() const { return cutP_; }
39 iterator operator++();
40
41 iterator operator++(int)
42 {
43 iterator temp = *this;
44 ++*this;
45 return temp;
46 }
47
48 bool operator==(const iterator &it) const
49 {
50 return (colCutIndex_ + rowCutIndex_) == (it.colCutIndex_ + it.rowCutIndex_);
51 }
52
53 bool operator!=(const iterator &it) const
54 {
55 return !((*this) == it);
56 }
57
58 bool operator<(const iterator &it) const
59 {
60 return (colCutIndex_ + rowCutIndex_) < (it.colCutIndex_ + it.rowCutIndex_);
61 }
62
63 private:
64 iterator();
65 // *THINK* : how to inline these without sticking the code here (ugly...)
66 iterator begin();
67 iterator end();
68 OsiCuts &cuts_;
69 int rowCutIndex_;
70 int colCutIndex_;
71 OsiCut *cutP_;
72 };
73
78 class const_iterator {
79 friend class OsiCuts;
80
81 public:
82 typedef std::forward_iterator_tag iterator_category;
83 typedef OsiCut *value_type;
84 typedef size_t difference_type;
85 typedef OsiCut **pointer;
86 typedef OsiCut *&reference;
87
88 public:
89 const_iterator(const OsiCuts &cuts);
90 const_iterator(const const_iterator &src);
91 const_iterator &operator=(const const_iterator &rhs);
92 ~const_iterator();
93 const OsiCut *operator*() const { return cutP_; }
94
95 const_iterator operator++();
96
97 const_iterator operator++(int)
98 {
99 const_iterator temp = *this;
100 ++*this;
101 return temp;
102 }
103
104 bool operator==(const const_iterator &it) const
105 {
106 return (colCutIndex_ + rowCutIndex_) == (it.colCutIndex_ + it.rowCutIndex_);
107 }
108
109 bool operator!=(const const_iterator &it) const
110 {
111 return !((*this) == it);
112 }
113
114 bool operator<(const const_iterator &it) const
115 {
116 return (colCutIndex_ + rowCutIndex_) < (it.colCutIndex_ + it.rowCutIndex_);
117 }
118
119 private:
120 inline const_iterator();
121 // *THINK* : how to inline these without sticking the code here (ugly...)
122 const_iterator begin();
123 const_iterator end();
124 const OsiCuts *cutsPtr_;
125 int rowCutIndex_;
126 int colCutIndex_;
127 const OsiCut *cutP_;
128 };
130
131 //-------------------------------------------------------------------
132 //
133 // Cuts class definition begins here:
134 //
135 //-------------------------------------------------------------------
136
140 inline void insert(const OsiRowCut &rc);
143 void insertIfNotDuplicate(OsiRowCut &rc, CoinAbsFltEq treatAsSame = CoinAbsFltEq(1.0e-12));
146 void insertIfNotDuplicate(OsiRowCut &rc, CoinRelFltEq treatAsSame);
148 inline void insert(const OsiColCut &cc);
149
155 inline void insert(OsiRowCut *&rcPtr);
161 inline void insert(OsiColCut *&ccPtr);
162 #if 0
163 inline void insert( OsiCut * & cPtr );
164 #endif
165
167 inline void insert(const OsiCuts &cs);
168
170
173 inline int sizeRowCuts() const;
176 inline int sizeColCuts() const;
178 inline int sizeCuts() const;
180
183 inline void printCuts() const;
186
189 inline OsiRowCut *rowCutPtr(int i);
192 inline const OsiRowCut *rowCutPtr(int i) const;
194 inline OsiColCut *colCutPtr(int i);
196 inline const OsiColCut *colCutPtr(int i) const;
197
199 inline OsiRowCut &rowCut(int i);
201 inline const OsiRowCut &rowCut(int i) const;
203 inline OsiColCut &colCut(int i);
205 inline const OsiColCut &colCut(int i) const;
206
208 inline const OsiCut *mostEffectiveCutPtr() const;
210 inline OsiCut *mostEffectiveCutPtr();
212
215 inline void eraseRowCut(int i);
218 inline void eraseColCut(int i);
220 inline OsiRowCut *rowCutPtrAndZap(int i);
227 inline void dumpCuts();
235 inline void eraseAndDumpCuts(const std::vector< int > to_erase);
237
240 inline void sort();
243
254 inline iterator begin()
256 {
257 iterator it(*this);
258 it.begin();
259 return it;
260 }
262 inline const_iterator begin() const
263 {
264 const_iterator it(*this);
265 it.begin();
266 return it;
267 }
269 inline iterator end()
270 {
271 iterator it(*this);
272 it.end();
273 return it;
274 }
276 inline const_iterator end() const
277 {
278 const_iterator it(*this);
279 it.end();
280 return it;
281 }
283
286 OsiCuts();
288
290 OsiCuts(const OsiCuts &);
291
293 OsiCuts &operator=(const OsiCuts &rhs);
294
296 virtual ~OsiCuts();
298
299 private:
300 //*@name Function operator for sorting cuts by efectiveness */
302 class OsiCutCompare {
303 public:
305 inline bool operator()(const OsiCut *c1P, const OsiCut *c2P)
306 {
307 return c1P->effectiveness() > c2P->effectiveness();
308 }
309 };
311
314 void gutsOfCopy(const OsiCuts &source);
317 void gutsOfDestructor();
319
322 OsiVectorRowCutPtr rowCutPtrs_;
325 OsiVectorColCutPtr colCutPtrs_;
327 };
328
329 //-------------------------------------------------------------------
330 // insert cuts into collection
331 //-------------------------------------------------------------------
332 void OsiCuts::insert(const OsiRowCut &rc)
333 {
334 OsiRowCut *newCutPtr = rc.clone();
335 //assert(dynamic_cast<OsiRowCut*>(newCutPtr) != NULL );
336 rowCutPtrs_.push_back(static_cast< OsiRowCut * >(newCutPtr));
337 }
338 void OsiCuts::insert(const OsiColCut &cc)
339 {
340 OsiColCut *newCutPtr = cc.clone();
341 //assert(dynamic_cast<OsiColCut*>(newCutPtr) != NULL );
342 colCutPtrs_.push_back(static_cast< OsiColCut * >(newCutPtr));
343 }
344
345 void OsiCuts::insert(OsiRowCut *&rcPtr)
346 {
347 rowCutPtrs_.push_back(rcPtr);
348 rcPtr = NULL;
349 }
350 void OsiCuts::insert(OsiColCut *&ccPtr)
351 {
352 colCutPtrs_.push_back(ccPtr);
353 ccPtr = NULL;
354 }
355 #if 0
356 void OsiCuts::insert( OsiCut* & cPtr )
357 {
358 OsiRowCut * rcPtr = dynamic_cast<OsiRowCut*>(cPtr);
359 if ( rcPtr != NULL ) {
360 insert( rcPtr );
361 cPtr = rcPtr;
362 }
363 else {
364 OsiColCut * ccPtr = dynamic_cast<OsiColCut*>(cPtr);
365 assert( ccPtr != NULL );
366 insert( ccPtr );
367 cPtr = ccPtr;
368 }
369 }
370 #endif
371
372 // LANNEZ SEBASTIEN added Thu May 25 01:22:51 EDT 2006
373 void OsiCuts::insert(const OsiCuts &cs)
374 {
375 for (OsiCuts::const_iterator it = cs.begin(); it != cs.end(); it++) {
376 const OsiRowCut *rCut = dynamic_cast< const OsiRowCut * >(*it);
377 const OsiColCut *cCut = dynamic_cast< const OsiColCut * >(*it);
378 assert(rCut || cCut);
379 if (rCut)
380 insert(*rCut);
381 else
382 insert(*cCut);
383 }
384 }
385
386 //-------------------------------------------------------------------
387 // sort
388 //-------------------------------------------------------------------
389 void OsiCuts::sort()
390 {
391 std::sort(colCutPtrs_.begin(), colCutPtrs_.end(), OsiCutCompare());
392 std::sort(rowCutPtrs_.begin(), rowCutPtrs_.end(), OsiCutCompare());
393 }
394
395 //-------------------------------------------------------------------
396 // Get number of in collections
397 //-------------------------------------------------------------------
398 int OsiCuts::sizeRowCuts() const
399 {
400 return static_cast< int >(rowCutPtrs_.size());
401 }
402 int OsiCuts::sizeColCuts() const
403 {
404 return static_cast< int >(colCutPtrs_.size());
405 }
406 int OsiCuts::sizeCuts() const
407 {
408 return static_cast< int >(sizeRowCuts() + sizeColCuts());
409 }
410
411 //----------------------------------------------------------------
412 // Get i'th cut from the collection
413 //----------------------------------------------------------------
414 const OsiRowCut *OsiCuts::rowCutPtr(int i) const { return rowCutPtrs_[i]; }
415 const OsiColCut *OsiCuts::colCutPtr(int i) const { return colCutPtrs_[i]; }
416 OsiRowCut *OsiCuts::rowCutPtr(int i) { return rowCutPtrs_[i]; }
417 OsiColCut *OsiCuts::colCutPtr(int i) { return colCutPtrs_[i]; }
418
419 const OsiRowCut &OsiCuts::rowCut(int i) const { return *rowCutPtr(i); }
420 const OsiColCut &OsiCuts::colCut(int i) const { return *colCutPtr(i); }
421 OsiRowCut &OsiCuts::rowCut(int i) { return *rowCutPtr(i); }
422 OsiColCut &OsiCuts::colCut(int i) { return *colCutPtr(i); }
423
424 //----------------------------------------------------------------
425 // Get most effective cut from collection
426 //----------------------------------------------------------------
427 const OsiCut *OsiCuts::mostEffectiveCutPtr() const
428 {
429 const_iterator b = begin();
430 const_iterator e = end();
431 return *(std::min_element(b, e, OsiCutCompare()));
432 }
433 OsiCut *OsiCuts::mostEffectiveCutPtr()
434 {
435 iterator b = begin();
436 iterator e = end();
437 //return *(std::min_element(b,e,OsiCutCompare()));
438 OsiCut *retVal = NULL;
439 double maxEff = COIN_DBL_MIN;
440 for (OsiCuts::iterator it = b; it != e; ++it) {
441 if (maxEff < (*it)->effectiveness()) {
442 maxEff = (*it)->effectiveness();
443 retVal = *it;
444 }
445 }
446 return retVal;
447 }
448
449 //----------------------------------------------------------------
450 // Print all cuts
451 //----------------------------------------------------------------
452 void OsiCuts::printCuts() const
453 {
454 // do all column cuts first
455 int i;
456 int numberColCuts = sizeColCuts();
457 for (i = 0; i < numberColCuts; i++) {
458 const OsiColCut *cut = colCutPtr(i);
459 cut->print();
460 }
461 int numberRowCuts = sizeRowCuts();
462 for (i = 0; i < numberRowCuts; i++) {
463 const OsiRowCut *cut = rowCutPtr(i);
464 cut->print();
465 }
466 }
467
468 //----------------------------------------------------------------
469 // Erase i'th cut from the collection
470 //----------------------------------------------------------------
471 void OsiCuts::eraseRowCut(int i)
472 {
473 delete rowCutPtrs_[i];
474 rowCutPtrs_.erase(rowCutPtrs_.begin() + i);
475 }
476 void OsiCuts::eraseColCut(int i)
477 {
478 delete colCutPtrs_[i];
479 colCutPtrs_.erase(colCutPtrs_.begin() + i);
480 }
482 OsiRowCut *
483 OsiCuts::rowCutPtrAndZap(int i)
484 {
485 OsiRowCut *cut = rowCutPtrs_[i];
486 rowCutPtrs_[i] = NULL;
487 rowCutPtrs_.erase(rowCutPtrs_.begin() + i);
488 return cut;
489 }
490 void OsiCuts::dumpCuts()
491 {
492 rowCutPtrs_.clear();
493 }
494 void OsiCuts::eraseAndDumpCuts(const std::vector< int > to_erase)
495 {
496 for (unsigned i = 0; i < to_erase.size(); i++) {
497 delete rowCutPtrs_[to_erase[i]];
498 }
499 rowCutPtrs_.clear();
500 }
501
502 #endif
503
504 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
505 */
OsiCuts::gutsOfDestructor
void gutsOfDestructor()
Delete internal data.
OsiCuts::colCutPtrs_
OsiVectorColCutPtr colCutPtrs_
Vector of column cuts pointers.
Definition: OsiCuts.hpp:325
OsiCuts::const_iterator::operator++
const_iterator operator++(int)
Definition: OsiCuts.hpp:97
OsiCuts::const_iterator::reference
OsiCut *& reference
Definition: OsiCuts.hpp:86
OsiCuts::dumpCuts
void dumpCuts()
Clear all row cuts without deleting them.
Definition: OsiCuts.hpp:490
OsiCuts::~OsiCuts
virtual ~OsiCuts()
Destructor.
OsiCuts::const_iterator::const_iterator
const_iterator()
OsiColCut::clone
virtual OsiColCut * clone() const
Clone.
OsiCuts::begin
iterator begin()
Get iterator to beginning of collection.
Definition: OsiCuts.hpp:255
OsiCuts::rowCutPtrAndZap
OsiRowCut * rowCutPtrAndZap(int i)
Get pointer to i&#39;th row cut and remove ptr from collection.
Definition: OsiCuts.hpp:483
OsiCuts::insertIfNotDuplicate
void insertIfNotDuplicate(OsiRowCut &rc, CoinAbsFltEq treatAsSame=CoinAbsFltEq(1.0e-12))
Insert a row cut unless it is a duplicate - cut may get sorted.
OsiCuts::const_iterator::operator++
const_iterator operator++()
OsiCuts::iterator::begin
iterator begin()
OsiCut::effectiveness
double effectiveness() const
Get effectiveness.
Definition: OsiCut.hpp:217
OsiCuts::rowCutPtr
OsiRowCut * rowCutPtr(int i)
Get pointer to i&#39;th row cut.
Definition: OsiCuts.hpp:416
OsiCuts::const_iterator::value_type
OsiCut * value_type
Definition: OsiCuts.hpp:83
OsiCuts::begin
const_iterator begin() const
Get const iterator to beginning of collection.
Definition: OsiCuts.hpp:262
OsiCuts::eraseColCut
void eraseColCut(int i)
Remove i&#39;th column cut from collection.
Definition: OsiCuts.hpp:476
OsiCuts::const_iterator::difference_type
size_t difference_type
Definition: OsiCuts.hpp:84
OsiCuts::iterator::cuts_
OsiCuts & cuts_
Definition: OsiCuts.hpp:68
OsiCuts::iterator::operator*
OsiCut * operator*() const
Definition: OsiCuts.hpp:38
OsiCuts
Collections of row cuts and column cuts.
Definition: OsiCuts.hpp:19
OsiColCut
Column Cut Class.
Definition: OsiColCut.hpp:23
OsiCuts::const_iterator
Const Iterator.
Definition: OsiCuts.hpp:78
OsiCuts::iterator::operator++
iterator operator++()
OsiRowCut::clone
virtual OsiRowCut * clone() const
Clone.
OsiCuts::iterator::~iterator
~iterator()
OsiCuts::iterator::cutP_
OsiCut * cutP_
Definition: OsiCuts.hpp:71
OsiCuts::OsiCutCompare
Definition: OsiCuts.hpp:302
OsiCuts::iterator::colCutIndex_
int colCutIndex_
Definition: OsiCuts.hpp:70
OsiCuts::const_iterator::cutsPtr_
const OsiCuts * cutsPtr_
Definition: OsiCuts.hpp:124
OsiRowCut::print
virtual void print() const
Print cuts in collection.
OsiColCut::print
virtual void print() const
Print cuts in collection.
OsiCuts::const_iterator::operator<
bool operator<(const const_iterator &it) const
Definition: OsiCuts.hpp:114
OsiCuts::end
const_iterator end() const
Get const iterator to end of collection.
Definition: OsiCuts.hpp:276
COIN_DBL_MIN
const double COIN_DBL_MIN
Definition: CoinFinite.hpp:17
OsiCuts::colCutPtr
OsiColCut * colCutPtr(int i)
Get pointer to i&#39;th column cut.
Definition: OsiCuts.hpp:417
OsiCuts::mostEffectiveCutPtr
const OsiCut * mostEffectiveCutPtr() const
Get const pointer to the most effective cut.
Definition: OsiCuts.hpp:427
OsiVectorColCutPtr
std::vector< OsiColCut * > OsiVectorColCutPtr
Vector of OsiColCut pointers.
Definition: OsiCollections.hpp:24
OsiCuts::const_iterator::end
const_iterator end()
OsiCuts::const_iterator::operator=
const_iterator & operator=(const const_iterator &rhs)
OsiCuts::const_iterator::operator*
const OsiCut * operator*() const
Definition: OsiCuts.hpp:93
OsiCuts::const_iterator::cutP_
const OsiCut * cutP_
Definition: OsiCuts.hpp:127
OsiCuts::iterator
Iterator.
Definition: OsiCuts.hpp:30
CoinRelFltEq
Equality to a scaled tolerance.
Definition: CoinFloatEqual.hpp:120
CoinPragma.hpp
OsiCuts::iterator::operator!=
bool operator!=(const iterator &it) const
Definition: OsiCuts.hpp:53
OsiCuts::const_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: OsiCuts.hpp:82
OsiCuts::OsiCutsUnitTest
friend void OsiCutsUnitTest()
A function that tests the methods in the OsiCuts class.
OsiCuts::const_iterator::~const_iterator
~const_iterator()
OsiCuts::iterator::operator=
iterator & operator=(const iterator &rhs)
OsiCuts::rowCut
OsiRowCut & rowCut(int i)
Get reference to i&#39;th row cut.
Definition: OsiCuts.hpp:421
OsiCuts::const_iterator::colCutIndex_
int colCutIndex_
Definition: OsiCuts.hpp:126
OsiCuts::eraseRowCut
void eraseRowCut(int i)
Remove i&#39;th row cut from collection.
Definition: OsiCuts.hpp:471
OsiCuts::const_iterator::operator!=
bool operator!=(const const_iterator &it) const
Definition: OsiCuts.hpp:109
OsiCuts::const_iterator::operator==
bool operator==(const const_iterator &it) const
Definition: OsiCuts.hpp:104
OsiRowCut
Row Cut Class.
Definition: OsiRowCut.hpp:29
OsiCuts::printCuts
void printCuts() const
Print cuts in collection.
Definition: OsiCuts.hpp:452
OsiCuts::eraseAndDumpCuts
void eraseAndDumpCuts(const std::vector< int > to_erase)
Selective delete and clear for row cuts.
Definition: OsiCuts.hpp:494
CoinAbsFltEq
Equality to an absolute tolerance.
Definition: CoinFloatEqual.hpp:46
OsiCuts::insert
void insert(const OsiRowCut &rc)
Insert a row cut.
Definition: OsiCuts.hpp:332
CoinFloatEqual.hpp
Function objects for testing equality of real numbers.
OsiRowCut.hpp
OsiCut
Definition: OsiCut.hpp:35
OsiCuts::sizeCuts
int sizeCuts() const
Number of cuts in collection.
Definition: OsiCuts.hpp:406
OsiCuts::gutsOfCopy
void gutsOfCopy(const OsiCuts &source)
Copy internal data.
OsiCuts::iterator::iterator
iterator()
OsiCuts::const_iterator::begin
const_iterator begin()
OsiCuts::const_iterator::pointer
OsiCut ** pointer
Definition: OsiCuts.hpp:85
OsiColCut.hpp
OsiCuts::colCut
OsiColCut & colCut(int i)
Get reference to i&#39;th column cut.
Definition: OsiCuts.hpp:422
OsiCollections.hpp
OsiCuts::sort
void sort()
Cuts with greatest effectiveness are first.
Definition: OsiCuts.hpp:389
OsiCuts::iterator::operator++
iterator operator++(int)
Definition: OsiCuts.hpp:41
OsiCuts::operator=
OsiCuts & operator=(const OsiCuts &rhs)
Assignment operator.
OsiCuts::iterator::operator<
bool operator<(const iterator &it) const
Definition: OsiCuts.hpp:58
OsiCuts::end
iterator end()
Get iterator to end of collection.
Definition: OsiCuts.hpp:269
OsiCuts::iterator::operator==
bool operator==(const iterator &it) const
Definition: OsiCuts.hpp:48
OsiCuts::OsiCuts
OsiCuts()
Default constructor.
OsiVectorRowCutPtr
std::vector< OsiRowCut * > OsiVectorRowCutPtr
Vector of OsiRowCut pointers.
Definition: OsiCollections.hpp:26
OsiCuts::rowCutPtrs_
OsiVectorRowCutPtr rowCutPtrs_
Vector of row cuts pointers.
Definition: OsiCuts.hpp:323
OsiCuts::iterator::rowCutIndex_
int rowCutIndex_
Definition: OsiCuts.hpp:69
OsiCuts::sizeRowCuts
int sizeRowCuts() const
Number of row cuts in collection.
Definition: OsiCuts.hpp:398
OsiCuts::const_iterator::rowCutIndex_
int rowCutIndex_
Definition: OsiCuts.hpp:125
OsiCuts::OsiCutCompare::operator()
bool operator()(const OsiCut *c1P, const OsiCut *c2P)
Function for sorting cuts by effectiveness.
Definition: OsiCuts.hpp:305
OsiCuts::iterator::end
iterator end()
OsiCuts::sizeColCuts
int sizeColCuts() const
Number of column cuts in collection.
Definition: OsiCuts.hpp:402