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
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 public:
33 iterator(OsiCuts& cuts);
34 iterator(const iterator & src);
35 iterator & operator=( const iterator& rhs);
36 ~iterator ();
37 OsiCut* operator*() const { return cutP_; }
38 iterator operator++();
39
40 iterator operator++(int)
41 {
42 iterator temp = *this;
43 ++*this;
44 return temp;
45 }
46
47 bool operator==(const iterator& it) const {
48 return (colCutIndex_+rowCutIndex_)==(it.colCutIndex_+it.rowCutIndex_);
49 }
50
51 bool operator!=(const iterator& it) const {
52 return !((*this)==it);
53 }
54
55 bool operator<(const iterator& it) const {
56 return (colCutIndex_+rowCutIndex_)<(it.colCutIndex_+it.rowCutIndex_);
57 }
58
59 private:
60 iterator();
61 // *THINK* : how to inline these without sticking the code here (ugly...)
62 iterator begin();
63 iterator end();
64 OsiCuts& cuts_;
65 int rowCutIndex_;
66 int colCutIndex_;
67 OsiCut * cutP_;
68 };
69
74 class const_iterator {
75 friend class OsiCuts;
76 public:
77 typedef std::forward_iterator_tag iterator_category;
78 typedef OsiCut* value_type;
79 typedef size_t difference_type;
80 typedef OsiCut ** pointer;
81 typedef OsiCut *& reference;
82
83 public:
84 const_iterator(const OsiCuts& cuts);
85 const_iterator(const const_iterator & src);
86 const_iterator & operator=( const const_iterator& rhs);
87 ~const_iterator ();
88 const OsiCut* operator*() const { return cutP_; }
89
90 const_iterator operator++();
91
92 const_iterator operator++(int)
93 {
94 const_iterator temp = *this;
95 ++*this;
96 return temp;
97 }
98
99 bool operator==(const const_iterator& it) const {
100 return (colCutIndex_+rowCutIndex_)==(it.colCutIndex_+it.rowCutIndex_);
101 }
102
103 bool operator!=(const const_iterator& it) const {
104 return !((*this)==it);
105 }
106
107 bool operator<(const const_iterator& it) const {
108 return (colCutIndex_+rowCutIndex_)<(it.colCutIndex_+it.rowCutIndex_);
109 }
110 private:
111 inline const_iterator();
112 // *THINK* : how to inline these without sticking the code here (ugly...)
113 const_iterator begin();
114 const_iterator end();
115 const OsiCuts * cutsPtr_;
116 int rowCutIndex_;
117 int colCutIndex_;
118 const OsiCut * cutP_;
119 };
121
122 //-------------------------------------------------------------------
123 //
124 // Cuts class definition begins here:
125 //
126 //-------------------------------------------------------------------
127
131 inline void insert( const OsiRowCut & rc );
134 void insertIfNotDuplicate( OsiRowCut & rc , CoinAbsFltEq treatAsSame=CoinAbsFltEq(1.0e-12) );
137 void insertIfNotDuplicate( OsiRowCut & rc , CoinRelFltEq treatAsSame );
139 inline void insert( const OsiColCut & cc );
140
146 inline void insert( OsiRowCut * & rcPtr );
152 inline void insert( OsiColCut * & ccPtr );
153 #if 0
154 inline void insert( OsiCut * & cPtr );
155 #endif
156
158 inline void insert(const OsiCuts & cs);
159
161
164 inline int sizeRowCuts() const;
167 inline int sizeColCuts() const;
169 inline int sizeCuts() const;
171
174 inline void printCuts() const;
177
180 inline OsiRowCut * rowCutPtr(int i);
183 inline const OsiRowCut * rowCutPtr(int i) const;
185 inline OsiColCut * colCutPtr(int i);
187 inline const OsiColCut * colCutPtr(int i) const;
188
190 inline OsiRowCut & rowCut(int i);
192 inline const OsiRowCut & rowCut(int i) const;
194 inline OsiColCut & colCut(int i);
196 inline const OsiColCut & colCut(int i) const;
197
199 inline const OsiCut * mostEffectiveCutPtr() const;
201 inline OsiCut * mostEffectiveCutPtr();
203
206 inline void eraseRowCut(int i);
209 inline void eraseColCut(int i);
211 inline OsiRowCut * rowCutPtrAndZap(int i);
218 inline void dumpCuts() ;
226 inline void eraseAndDumpCuts(const std::vector<int> to_erase) ;
228
231 inline void sort();
234
235
246 inline iterator begin() { iterator it(*this); it.begin(); return it; }
249 inline const_iterator begin() const { const_iterator it(*this); it.begin(); return it; }
251 inline iterator end() { iterator it(*this); it.end(); return it; }
253 inline const_iterator end() const { const_iterator it(*this); it.end(); return it; }
255
256
259 OsiCuts ();
261
263 OsiCuts ( const OsiCuts &);
264
266 OsiCuts & operator=( const OsiCuts& rhs);
267
269 virtual ~OsiCuts ();
271
272 private:
273 //*@name Function operator for sorting cuts by efectiveness */
275 class OsiCutCompare
276 {
277 public:
279 inline bool operator()(const OsiCut * c1P,const OsiCut * c2P)
280 { return c1P->effectiveness() > c2P->effectiveness(); }
281 };
283
286 void gutsOfCopy( const OsiCuts & source );
289 void gutsOfDestructor();
291
294 OsiVectorRowCutPtr rowCutPtrs_;
297 OsiVectorColCutPtr colCutPtrs_;
299
300 };
301
302
303 //-------------------------------------------------------------------
304 // insert cuts into collection
305 //-------------------------------------------------------------------
306 void OsiCuts::insert( const OsiRowCut & rc )
307 {
308 OsiRowCut * newCutPtr = rc.clone();
309 //assert(dynamic_cast<OsiRowCut*>(newCutPtr) != NULL );
310 rowCutPtrs_.push_back(static_cast<OsiRowCut*>(newCutPtr));
311 }
312 void OsiCuts::insert( const OsiColCut & cc )
313 {
314 OsiColCut * newCutPtr = cc.clone();
315 //assert(dynamic_cast<OsiColCut*>(newCutPtr) != NULL );
316 colCutPtrs_.push_back(static_cast<OsiColCut*>(newCutPtr));
317 }
318
319 void OsiCuts::insert( OsiRowCut* & rcPtr )
320 {
321 rowCutPtrs_.push_back(rcPtr);
322 rcPtr = NULL;
323 }
324 void OsiCuts::insert( OsiColCut* &ccPtr )
325 {
326 colCutPtrs_.push_back(ccPtr);
327 ccPtr = NULL;
328 }
329 #if 0
330 void OsiCuts::insert( OsiCut* & cPtr )
331 {
332 OsiRowCut * rcPtr = dynamic_cast<OsiRowCut*>(cPtr);
333 if ( rcPtr != NULL ) {
334 insert( rcPtr );
335 cPtr = rcPtr;
336 }
337 else {
338 OsiColCut * ccPtr = dynamic_cast<OsiColCut*>(cPtr);
339 assert( ccPtr != NULL );
340 insert( ccPtr );
341 cPtr = ccPtr;
342 }
343 }
344 #endif
345
346 // LANNEZ SEBASTIEN added Thu May 25 01:22:51 EDT 2006
347 void OsiCuts::insert(const OsiCuts & cs)
348 {
349 for (OsiCuts::const_iterator it = cs.begin (); it != cs.end (); it++)
350 {
351 const OsiRowCut * rCut = dynamic_cast <const OsiRowCut * >(*it);
352 const OsiColCut * cCut = dynamic_cast <const OsiColCut * >(*it);
353 assert (rCut || cCut);
354 if (rCut)
355 insert (*rCut);
356 else
357 insert (*cCut);
358 }
359 }
360
361 //-------------------------------------------------------------------
362 // sort
363 //-------------------------------------------------------------------
364 void OsiCuts::sort()
365 {
366 std::sort(colCutPtrs_.begin(),colCutPtrs_.end(),OsiCutCompare());
367 std::sort(rowCutPtrs_.begin(),rowCutPtrs_.end(),OsiCutCompare());
368 }
369
370
371 //-------------------------------------------------------------------
372 // Get number of in collections
373 //-------------------------------------------------------------------
374 int OsiCuts::sizeRowCuts() const {
375 return static_cast<int>(rowCutPtrs_.size()); }
376 int OsiCuts::sizeColCuts() const {
377 return static_cast<int>(colCutPtrs_.size()); }
378 int OsiCuts::sizeCuts() const {
379 return static_cast<int>(sizeRowCuts()+sizeColCuts()); }
380
381 //----------------------------------------------------------------
382 // Get i'th cut from the collection
383 //----------------------------------------------------------------
384 const OsiRowCut * OsiCuts::rowCutPtr(int i) const { return rowCutPtrs_[i]; }
385 const OsiColCut * OsiCuts::colCutPtr(int i) const { return colCutPtrs_[i]; }
386 OsiRowCut * OsiCuts::rowCutPtr(int i) { return rowCutPtrs_[i]; }
387 OsiColCut * OsiCuts::colCutPtr(int i) { return colCutPtrs_[i]; }
388
389 const OsiRowCut & OsiCuts::rowCut(int i) const { return *rowCutPtr(i); }
390 const OsiColCut & OsiCuts::colCut(int i) const { return *colCutPtr(i); }
391 OsiRowCut & OsiCuts::rowCut(int i) { return *rowCutPtr(i); }
392 OsiColCut & OsiCuts::colCut(int i) { return *colCutPtr(i); }
393
394 //----------------------------------------------------------------
395 // Get most effective cut from collection
396 //----------------------------------------------------------------
397 const OsiCut * OsiCuts::mostEffectiveCutPtr() const
398 {
399 const_iterator b=begin();
400 const_iterator e=end();
401 return *(std::min_element(b,e,OsiCutCompare()));
402 }
403 OsiCut * OsiCuts::mostEffectiveCutPtr()
404 {
405 iterator b=begin();
406 iterator e=end();
407 //return *(std::min_element(b,e,OsiCutCompare()));
408 OsiCut * retVal = NULL;
409 double maxEff = COIN_DBL_MIN;
410 for ( OsiCuts::iterator it=b; it!=e; ++it ) {
411 if (maxEff < (*it)->effectiveness() ) {
412 maxEff = (*it)->effectiveness();
413 retVal = *it;
414 }
415 }
416 return retVal;
417 }
418
419 //----------------------------------------------------------------
420 // Print all cuts
421 //----------------------------------------------------------------
422 void
423 OsiCuts::printCuts() const
424 {
425 // do all column cuts first
426 int i;
427 int numberColCuts=sizeColCuts();
428 for (i=0;i<numberColCuts;i++) {
429 const OsiColCut * cut = colCutPtr(i);
430 cut->print();
431 }
432 int numberRowCuts=sizeRowCuts();
433 for (i=0;i<numberRowCuts;i++) {
434 const OsiRowCut * cut = rowCutPtr(i);
435 cut->print();
436 }
437 }
438
439 //----------------------------------------------------------------
440 // Erase i'th cut from the collection
441 //----------------------------------------------------------------
442 void OsiCuts::eraseRowCut(int i)
443 {
444 delete rowCutPtrs_[i];
445 rowCutPtrs_.erase( rowCutPtrs_.begin()+i );
446 }
447 void OsiCuts::eraseColCut(int i)
448 {
449 delete colCutPtrs_[i];
450 colCutPtrs_.erase( colCutPtrs_.begin()+i );
451 }
453 OsiRowCut *
454 OsiCuts::rowCutPtrAndZap(int i)
455 {
456 OsiRowCut * cut = rowCutPtrs_[i];
457 rowCutPtrs_[i]=NULL;
458 rowCutPtrs_.erase( rowCutPtrs_.begin()+i );
459 return cut;
460 }
461 void OsiCuts::dumpCuts()
462 {
463 rowCutPtrs_.clear() ;
464 }
465 void OsiCuts::eraseAndDumpCuts(const std::vector<int> to_erase)
466 {
467 for (unsigned i=0; i<to_erase.size(); i++) {
468 delete rowCutPtrs_[to_erase[i]];
469 }
470 rowCutPtrs_.clear();
471 }
472
473
474 #endif
OsiCuts::gutsOfDestructor
void gutsOfDestructor()
Delete internal data.
OsiCuts::colCutPtrs_
OsiVectorColCutPtr colCutPtrs_
Vector of column cuts pointers.
Definition: OsiCuts.hpp:297
OsiCuts::const_iterator::operator++
const_iterator operator++(int)
Definition: OsiCuts.hpp:92
OsiVectorRowCutPtr
std::vector< OsiRowCut * > OsiVectorRowCutPtr
Vector of OsiRowCut pointers.
Definition: OsiCollections.hpp:28
OsiCuts::const_iterator::reference
OsiCut *& reference
Definition: OsiCuts.hpp:81
OsiCuts::dumpCuts
void dumpCuts()
Clear all row cuts without deleting them.
Definition: OsiCuts.hpp:461
OsiCuts::~OsiCuts
virtual ~OsiCuts()
Destructor.
OsiCuts::const_iterator::const_iterator
const_iterator()
OsiColCut::clone
virtual OsiColCut * clone() const
Clone.
OsiVectorColCutPtr
std::vector< OsiColCut * > OsiVectorColCutPtr
Vector of OsiColCut pointers.
Definition: OsiCollections.hpp:26
OsiCuts::begin
iterator begin()
Get iterator to beginning of collection.
Definition: OsiCuts.hpp:247
OsiCuts::rowCutPtrAndZap
OsiRowCut * rowCutPtrAndZap(int i)
Get pointer to i&#39;th row cut and remove ptr from collection.
Definition: OsiCuts.hpp:454
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:210
OsiCuts::rowCutPtr
OsiRowCut * rowCutPtr(int i)
Get pointer to i&#39;th row cut.
Definition: OsiCuts.hpp:386
OsiCuts::const_iterator::value_type
OsiCut * value_type
Definition: OsiCuts.hpp:78
OsiCuts::begin
const_iterator begin() const
Get const iterator to beginning of collection.
Definition: OsiCuts.hpp:249
OsiCuts::eraseColCut
void eraseColCut(int i)
Remove i&#39;th column cut from collection.
Definition: OsiCuts.hpp:447
OsiCuts::const_iterator::difference_type
size_t difference_type
Definition: OsiCuts.hpp:79
OsiCuts::iterator::cuts_
OsiCuts & cuts_
Definition: OsiCuts.hpp:64
OsiCuts::iterator::operator*
OsiCut * operator*() const
Definition: OsiCuts.hpp:37
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:74
OsiCuts::iterator::operator++
iterator operator++()
OsiRowCut::clone
virtual OsiRowCut * clone() const
Clone.
OsiCuts::iterator::~iterator
~iterator()
OsiCuts::iterator::cutP_
OsiCut * cutP_
Definition: OsiCuts.hpp:67
OsiCuts::OsiCutCompare
Definition: OsiCuts.hpp:275
OsiCuts::iterator::colCutIndex_
int colCutIndex_
Definition: OsiCuts.hpp:66
OsiCuts::const_iterator::cutsPtr_
const OsiCuts * cutsPtr_
Definition: OsiCuts.hpp:115
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:107
OsiCuts::end
const_iterator end() const
Get const iterator to end of collection.
Definition: OsiCuts.hpp:253
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:387
OsiCuts::mostEffectiveCutPtr
const OsiCut * mostEffectiveCutPtr() const
Get const pointer to the most effective cut.
Definition: OsiCuts.hpp:397
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:88
OsiCuts::const_iterator::cutP_
const OsiCut * cutP_
Definition: OsiCuts.hpp:118
OsiCuts::iterator
Iterator.
Definition: OsiCuts.hpp:30
CoinRelFltEq
Equality to a scaled tolerance.
Definition: CoinFloatEqual.hpp:110
CoinPragma.hpp
OsiCuts::iterator::operator!=
bool operator!=(const iterator &it) const
Definition: OsiCuts.hpp:51
OsiCuts::const_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: OsiCuts.hpp:77
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:391
OsiCuts::const_iterator::colCutIndex_
int colCutIndex_
Definition: OsiCuts.hpp:117
OsiCuts::eraseRowCut
void eraseRowCut(int i)
Remove i&#39;th row cut from collection.
Definition: OsiCuts.hpp:442
OsiCuts::const_iterator::operator!=
bool operator!=(const const_iterator &it) const
Definition: OsiCuts.hpp:103
OsiCuts::const_iterator::operator==
bool operator==(const const_iterator &it) const
Definition: OsiCuts.hpp:99
OsiRowCut
Row Cut Class.
Definition: OsiRowCut.hpp:29
OsiCuts::printCuts
void printCuts() const
Print cuts in collection.
Definition: OsiCuts.hpp:423
OsiCuts::eraseAndDumpCuts
void eraseAndDumpCuts(const std::vector< int > to_erase)
Selective delete and clear for row cuts.
Definition: OsiCuts.hpp:465
CoinAbsFltEq
Equality to an absolute tolerance.
Definition: CoinFloatEqual.hpp:46
OsiCuts::insert
void insert(const OsiRowCut &rc)
Insert a row cut.
Definition: OsiCuts.hpp:306
CoinFloatEqual.hpp
Function objects for testing equality of real numbers.
OsiRowCut.hpp
OsiCut
Definition: OsiCut.hpp:36
OsiCuts::sizeCuts
int sizeCuts() const
Number of cuts in collection.
Definition: OsiCuts.hpp:378
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:80
OsiColCut.hpp
OsiCuts::colCut
OsiColCut & colCut(int i)
Get reference to i&#39;th column cut.
Definition: OsiCuts.hpp:392
OsiCollections.hpp
OsiCuts::sort
void sort()
Cuts with greatest effectiveness are first.
Definition: OsiCuts.hpp:364
OsiCuts::iterator::operator++
iterator operator++(int)
Definition: OsiCuts.hpp:40
OsiCuts::operator=
OsiCuts & operator=(const OsiCuts &rhs)
Assignment operator.
OsiCuts::iterator::operator<
bool operator<(const iterator &it) const
Definition: OsiCuts.hpp:55
OsiCuts::end
iterator end()
Get iterator to end of collection.
Definition: OsiCuts.hpp:251
OsiCuts::iterator::operator==
bool operator==(const iterator &it) const
Definition: OsiCuts.hpp:47
OsiCuts::OsiCuts
OsiCuts()
Default constructor.
OsiCuts::rowCutPtrs_
OsiVectorRowCutPtr rowCutPtrs_
Vector of row cuts pointers.
Definition: OsiCuts.hpp:295
OsiCuts::iterator::rowCutIndex_
int rowCutIndex_
Definition: OsiCuts.hpp:65
OsiCuts::sizeRowCuts
int sizeRowCuts() const
Number of row cuts in collection.
Definition: OsiCuts.hpp:374
OsiCuts::const_iterator::rowCutIndex_
int rowCutIndex_
Definition: OsiCuts.hpp:116
OsiCuts::OsiCutCompare::operator()
bool operator()(const OsiCut *c1P, const OsiCut *c2P)
Function for sorting cuts by effectiveness.
Definition: OsiCuts.hpp:279
OsiCuts::iterator::end
iterator end()
OsiCuts::sizeColCuts
int sizeColCuts() const
Number of column cuts in collection.
Definition: OsiCuts.hpp:376