#include <OsiCuts.hpp>
Public Member Functions | |
Inserting a cut into collection | |
void | insert (const OsiRowCut &rc) |
Insert row cut. | |
void | insert (const OsiColCut &cc) |
Insert column cut. | |
Inserting a cut into collection using a pointer reference | |
The OsiCuts class takes control of and manages the storage for the cut including the deletion of the cut. | |
void | insert (OsiRowCut *&rcPtr) |
Insert row cut. On return rcPtr is NULL. | |
void | insert (OsiColCut *&ccPtr) |
Insert column cut. On return ccPtr is NULL. | |
Number of cuts in collection | |
int | sizeRowCuts () const |
Number of row cuts in collection. | |
int | sizeColCuts () const |
Number of column cuts in collection. | |
int | sizeCuts () const |
Number of cuts in collection. | |
Debug stuff | |
void | printCuts () const |
Print cuts in collection. | |
Get a cut from collection | |
OsiRowCut * | rowCutPtr (int i) |
Get pointer to i'th row cut. | |
const OsiRowCut * | rowCutPtr (int i) const |
Get const pointer to i'th row cut. | |
OsiColCut * | colCutPtr (int i) |
Get pointer to i'th column cut. | |
const OsiColCut * | colCutPtr (int i) const |
Get const pointer to i'th column cut. | |
OsiRowCut & | rowCut (int i) |
Get reference to i'th row cut. | |
const OsiRowCut & | rowCut (int i) const |
Get const reference to i'th row cut. | |
OsiColCut & | colCut (int i) |
Get reference to i'th column cut. | |
const OsiColCut & | colCut (int i) const |
Get const reference to i'th column cut. | |
const OsiCut * | mostEffectiveCutPtr () const |
Get const pointer to the most effective cut. | |
OsiCut * | mostEffectiveCutPtr () |
Get pointer to the most effective cut. | |
Deleting cut from collection | |
void | eraseRowCut (int i) |
Remove i'th row cut from collection. | |
void | eraseColCut (int i) |
Remove i'th column cut from collection. | |
Sorting collection | |
void | sort () |
Cuts with greatest effectiveness are first. | |
Iterators | |
Example of using an iterator to sum effectiveness of all cuts in the collection.
| |
iterator | begin () |
Get iterator to beginning of collection. | |
const_iterator | begin () const |
Get const iterator to beginning of collection. | |
iterator | end () |
Get iterator to end of collection. | |
const_iterator | end () const |
Get const iterator to end of collection. | |
Constructors and destructors | |
OsiCuts () | |
Default constructor. | |
OsiCuts (const OsiCuts &) | |
Copy constructor. | |
OsiCuts & | operator= (const OsiCuts &rhs) |
Assignment operator. | |
virtual | ~OsiCuts () |
Destructor. | |
Private Member Functions | |
Private methods | |
void | gutsOfCopy (const OsiCuts &source) |
Copy internal data. | |
void | gutsOfDestructor () |
Delete internal data. | |
Private Attributes | |
Private member data | |
OsiVectorRowCutPtr | rowCutPtrs_ |
Vector of row cuts pointers. | |
OsiVectorColCutPtr | colCutPtrs_ |
Vector of column cuts pointers. | |
Friends | |
void | OsiCutsUnitTest () |
Definition at line 19 of file OsiCuts.hpp.
|
A function that tests the methods in the OsiCuts class. The only reason for it not to be a member method is that this way it doesn't have to be compiled into the library. And that's a gain, because the library should be compiled with optimization on, but this method should be compiled with debugging. Definition at line 18 of file OsiCutsTest.cpp.
00019 { 00020 CoinRelFltEq eq; 00021 // Test default constructor 00022 { 00023 OsiCuts r; 00024 assert( r.colCutPtrs_.empty() ); 00025 assert( r.rowCutPtrs_.empty() ); 00026 assert( r.sizeColCuts()==0 ); 00027 assert( r.sizeRowCuts()==0 ); 00028 assert( r.sizeCuts()==0 ); 00029 assert( r.mostEffectiveCutPtr()==NULL ); 00030 } 00031 00032 // Create some cuts 00033 OsiRowCut rcv[5]; 00034 OsiColCut ccv[5]; 00035 int i; 00036 for ( i=0; i<5; i++ ) { 00037 rcv[i].setEffectiveness(100.+i); 00038 ccv[i].setEffectiveness(200.+i); 00039 } 00040 00041 OsiCuts rhs; 00042 { 00043 OsiCuts cs; 00044 00045 // test inserting & accessing cut 00046 for ( i=0; i<5; i++ ) { 00047 assert( cs.sizeRowCuts()==i); 00048 assert( cs.sizeCuts()==2*i); 00049 cs.insert(rcv[i]); 00050 assert( cs.sizeRowCuts()==i+1); 00051 assert( cs.sizeCuts()==2*i+1); 00052 assert( cs.rowCut(i)==rcv[i] ); 00053 #if 0 00054 const OsiCut * cp = cs.cutPtr(2*i); 00055 assert( cs.rowCut(i).effectiveness() == cp->effectiveness() ); 00056 const OsiRowCut * rcP = dynamic_cast<const OsiRowCut*>( cp ); 00057 assert( rcP != NULL ); 00058 assert( *rcP == rcv[i] ); 00059 const OsiColCut * ccP = dynamic_cast<const OsiColCut*>( cs.cutPtr(2*i) ); 00060 assert( ccP == NULL ); 00061 #endif 00062 00063 assert( cs.sizeColCuts()==i); 00064 assert( cs.sizeCuts()==2*i+1); 00065 cs.insert(ccv[i]); 00066 assert( cs.sizeColCuts()==i+1); 00067 assert( cs.sizeCuts()==2*i+2); 00068 assert( cs.colCut(i)==ccv[i] ); 00069 #if 0 00070 rcP = dynamic_cast<const OsiRowCut*>( cs.cutPtr(2*i+1) ); 00071 assert( rcP == NULL ); 00072 ccP = dynamic_cast<const OsiColCut*>( cs.cutPtr(2*i+1) ); 00073 assert( ccP != NULL ); 00074 assert( *ccP == ccv[i] ); 00075 #endif 00076 assert( eq(cs.mostEffectiveCutPtr()->effectiveness(),200.0+i) ); 00077 } 00078 00079 { 00080 OsiCuts cs; 00081 // test inserting cut ptr & accessing cut 00082 for ( i=0; i<5; i++ ) { 00083 assert( cs.sizeRowCuts()==i); 00084 OsiRowCut * rcP = rcv[i].clone(); 00085 assert( rcP != NULL ); 00086 cs.insert(rcP); 00087 assert( rcP == NULL ); 00088 assert( cs.sizeRowCuts()==i+1); 00089 assert( cs.rowCut(i)==rcv[i] ); 00090 00091 00092 OsiColCut * ccP = ccv[i].clone(); 00093 assert( ccP != NULL ); 00094 assert( cs.sizeColCuts()==i); 00095 cs.insert(ccP); 00096 assert( ccP == NULL ); 00097 assert( cs.sizeColCuts()==i+1); 00098 assert( cs.colCut(i)==ccv[i] ); 00099 00100 assert( eq(cs.mostEffectiveCutPtr()->effectiveness(),200.0+i) ); 00101 } 00102 } 00103 00104 // Test copy constructor 00105 OsiCuts csC(cs); 00106 assert( csC.sizeRowCuts()==5 ); 00107 assert( csC.sizeColCuts()==5 ); 00108 for ( i=0; i<5; i++ ) { 00109 assert( csC.rowCut(i) == rcv[i] ); 00110 assert( csC.colCut(i) == ccv[i] ); 00111 assert( csC.rowCut(i) == cs.rowCut(i) ); 00112 assert( csC.colCut(i) == cs.colCut(i) ); 00113 } 00114 assert( eq(csC.mostEffectiveCutPtr()->effectiveness(),204.0) ); 00115 00116 rhs=cs; 00117 } 00118 00119 // Test results of assigmnet operation 00120 for ( i=0; i<5; i++ ) { 00121 assert( rhs.rowCut(i) == rcv[i] ); 00122 assert( rhs.colCut(i) == ccv[i] ); 00123 } 00124 assert( eq(rhs.mostEffectiveCutPtr()->effectiveness(),204.0) ); 00125 00126 // Test removing cuts 00127 { 00128 OsiCuts t(rhs); 00129 assert( t.sizeRowCuts()==5 ); 00130 assert( t.sizeColCuts()==5 ); 00131 assert( eq(rhs.mostEffectiveCutPtr()->effectiveness(),204.0) ); 00132 assert( eq(t.mostEffectiveCutPtr()->effectiveness(),204.0) ); 00133 00134 t.eraseRowCut(3); 00135 assert( t.sizeRowCuts()==4 ); 00136 assert( t.sizeColCuts()==5 ); 00137 for ( i=0; i<5; i++ ) { 00138 assert( t.colCut(i) == ccv[i] ); 00139 } 00140 assert( t.rowCut(0)==rcv[0] ); 00141 assert( t.rowCut(1)==rcv[1] ); 00142 assert( t.rowCut(2)==rcv[2] ); 00143 assert( t.rowCut(3)==rcv[4] ); 00144 assert( eq(t.mostEffectiveCutPtr()->effectiveness(),204.0) ); 00145 00146 t.eraseColCut(4); 00147 assert( t.sizeRowCuts()==4 ); 00148 assert( t.sizeColCuts()==4 ); 00149 for ( i=0; i<4; i++ ) { 00150 assert( t.colCut(i) == ccv[i] ); 00151 } 00152 assert( t.rowCut(0)==rcv[0] ); 00153 assert( t.rowCut(1)==rcv[1] ); 00154 assert( t.rowCut(2)==rcv[2] ); 00155 assert( t.rowCut(3)==rcv[4] ); 00156 assert( eq(t.mostEffectiveCutPtr()->effectiveness(),203.0) ); 00157 } 00158 00159 00160 00161 // sorting cuts 00162 { 00163 OsiCuts t(rhs); 00164 assert( t.sizeRowCuts()==5 ); 00165 assert( t.sizeColCuts()==5 ); 00166 t.rowCut(0).setEffectiveness(9.); 00167 t.rowCut(1).setEffectiveness(1.); 00168 t.rowCut(2).setEffectiveness(7.); 00169 t.rowCut(3).setEffectiveness(3.); 00170 t.rowCut(4).setEffectiveness(5.); 00171 t.colCut(0).setEffectiveness(2.); 00172 t.colCut(1).setEffectiveness(8.); 00173 t.colCut(2).setEffectiveness(4.); 00174 t.colCut(3).setEffectiveness(6.); 00175 t.colCut(4).setEffectiveness(.5); 00176 double totEff=1.+2.+3.+4.+5.+6.+7.+8.+9.+0.5; 00177 00178 { 00179 // Test iterator over all cuts 00180 double sumEff=0.; 00181 for ( OsiCuts::iterator it=t.begin(); it!=t.end(); ++it ) { 00182 double eff=(*it)->effectiveness(); 00183 sumEff+= eff; 00184 } 00185 assert( sumEff == totEff ); 00186 } 00187 00188 t.sort(); 00189 for ( i=1; i<5; i++ ) assert( t.colCut(i-1)>t.colCut(i) ); 00190 for ( i=1; i<5; i++ ) assert( t.rowCut(i-1)>t.rowCut(i) ); 00191 00192 { 00193 // Test iterator over all cuts 00194 double sumEff=0.; 00195 for ( OsiCuts::iterator it=t.begin(); it!=t.end(); ++it ) { 00196 sumEff+= (*it)->effectiveness(); 00197 } 00198 assert( sumEff == totEff ); 00199 } 00200 00201 { 00202 OsiCuts::iterator it=t.begin(); 00203 OsiCut * cm1 = *it; 00204 ++it; 00205 for( ; it!=t.end(); it++ ) { 00206 OsiCut * c = *it; 00207 assert( (*cm1)>(*c) ); 00208 cm1 = c; 00209 } 00210 } 00211 } 00212 } |