00001
00002
00003 #if defined(_MSC_VER)
00004
00005 # pragma warning(disable:4786)
00006 #endif
00007
00008
00009 #include <cassert>
00010
00011
00012 #include <OsiColCut.hpp>
00013
00014 #ifdef NDEBUG
00015 #undef NDEBUG
00016 #endif
00017
00018
00019 void
00020 OsiColCutUnitTest(const OsiSolverInterface * baseSiP,
00021 const std::string & mpsDir)
00022 {
00023
00024
00025 {
00026 OsiColCut r;
00027 assert( r.lbs_.getIndices()==NULL );
00028 assert( r.lbs_.getElements()==NULL );
00029 assert( r.ubs_.getIndices()==NULL );
00030 assert( r.ubs_.getElements()==NULL );
00031 assert( r.lbs_.getNumElements()==0);
00032 assert( r.ubs_.getNumElements()==0);
00033 }
00034
00035
00036 const int ne = 4;
00037 int inx[ne] = { 1, 3, 4, 7 };
00038 double el[ne] = { 1.2, 3.4, 5.6, 7.8 };
00039 const int ne3 = 0;
00040 int * inx3=NULL;
00041 double * el3= NULL;
00042 {
00043 OsiColCut r;
00044 assert( r.lbs().getNumElements()==0 );
00045 assert( r.ubs().getNumElements()==0 );
00046
00047
00048 r.setLbs( ne, inx, el );
00049 r.setEffectiveness(222.);
00050 assert( r.lbs().getNumElements()==ne );
00051 for ( int i=0; i<ne; i++ ) {
00052 assert( r.lbs().getIndices()[i] == inx[i] );
00053 assert( r.lbs().getElements()[i] == el[i] );
00054 }
00055 assert( r.effectiveness()==222. );
00056
00057 r.setUbs( ne3, inx3, el3 );
00058 assert( r.ubs().getNumElements()==0 );
00059 assert( r.ubs().getIndices()==NULL );
00060 assert( r.ubs().getElements()==NULL );
00061
00062 }
00063
00064
00065 {
00066 OsiColCut rhs;
00067 {
00068 OsiColCut r;
00069 OsiColCut rC1(r);
00070 assert( rC1.lbs().getNumElements()==r.lbs().getNumElements() );
00071 assert( rC1.ubs().getNumElements()==r.ubs().getNumElements() );
00072
00073 r.setLbs( ne, inx, el );
00074 r.setUbs( ne, inx, el );
00075 r.setEffectiveness(121.);
00076
00077 assert( rC1.lbs().getNumElements()!=r.lbs().getNumElements() );
00078 assert( rC1.ubs().getNumElements()!=r.ubs().getNumElements() );
00079
00080 OsiColCut rC2(r);
00081 assert( rC2.lbs().getNumElements()==r.lbs().getNumElements() );
00082 assert( rC2.ubs().getNumElements()==r.ubs().getNumElements() );
00083 assert( rC2.lbs().getNumElements()==ne );
00084 assert( rC2.ubs().getNumElements()==ne );
00085 for ( int i=0; i<ne; i++ ) {
00086 assert( rC2.lbs().getIndices()[i] == inx[i] );
00087 assert( rC2.lbs().getElements()[i] == el[i] );
00088 assert( rC2.ubs().getIndices()[i] == inx[i] );
00089 assert( rC2.ubs().getElements()[i] == el[i] );
00090 }
00091 assert( rC2.effectiveness()==121. );
00092
00093 rhs=rC2;
00094 }
00095
00096 assert( rhs.lbs().getNumElements()==ne );
00097 assert( rhs.ubs().getNumElements()==ne );
00098 for ( int i=0; i<ne; i++ ) {
00099 assert( rhs.lbs().getIndices()[i] == inx[i] );
00100 assert( rhs.lbs().getElements()[i] == el[i] );
00101 assert( rhs.ubs().getIndices()[i] == inx[i] );
00102 assert( rhs.ubs().getElements()[i] == el[i] );
00103 }
00104 assert( rhs.effectiveness()==121. );
00105 }
00106
00107
00108 {
00109 const int ne1 = 4;
00110 int inx1[ne] = { 1, 3, 4, 7 };
00111 double el1[ne] = { 1.2, 3.4, 5.6, 7.8 };
00112 const int ne2 = 2;
00113 int inx2[ne2]={ 1, 3 };
00114 double el2[ne2]= { 1.2, 3.4 };
00115 CoinPackedVector v1,v2;
00116 v1.setVector(ne1,inx1,el1);
00117 v2.setVector(ne2,inx2,el2);
00118
00119 OsiColCut c1,c2;
00120 assert( c1==c2 );
00121 assert( !(c1!=c2) );
00122
00123 c1.setLbs(v1);
00124 assert( c1 != c2 );
00125 assert( !(c1 == c2) );
00126
00127 assert( c1.lbs()==v1 );
00128 c1.setUbs(v2);
00129 assert( c1.ubs()==v2 );
00130 c1.setEffectiveness(3.);
00131 assert( c1.effectiveness()==3. );
00132
00133 {
00134 OsiColCut c3(c1);
00135 assert( c3==c1 );
00136 assert( !(c3!=c1) );
00137 }
00138 {
00139 OsiColCut c3(c1);
00140 c3.setLbs(v2);
00141 assert( c3!=c1 );
00142 assert( !(c3==c1) );
00143 }
00144 {
00145 OsiColCut c3(c1);
00146 c3.setUbs(v1);
00147 assert( c3!=c1 );
00148 assert( !(c3==c1) );
00149 }
00150 {
00151 OsiColCut c3(c1);
00152 c3.setEffectiveness(5.);
00153 assert( c3!=c1 );
00154 assert( !(c3==c1) );
00155 }
00156 }
00157
00158
00159 {
00160 const int ne = 1;
00161 int inx[ne] = { -3 };
00162 double el[ne] = { 1.2 };
00163 OsiColCut r;
00164 r.setLbs( ne, inx, el );
00165 assert( !r.consistent() );
00166 }
00167 {
00168 const int ne = 1;
00169 int inx[ne] = { -3 };
00170 double el[ne] = { 1.2 };
00171 OsiColCut r;
00172 r.setUbs( ne, inx, el );
00173 assert( !r.consistent() );
00174 }
00175 {
00176 const int ne = 1;
00177 int inx[ne] = { 100 };
00178 double el[ne] = { 1.2 };
00179 const int ne1 = 2;
00180 int inx1[ne1] = { 50, 100 };
00181 double el1[ne1] = { 100., 100. };
00182 OsiColCut r;
00183 r.setUbs( ne, inx, el );
00184 r.setLbs( ne1, inx1, el1 );
00185 assert( r.consistent() );
00186
00187 OsiSolverInterface * imP = baseSiP->clone();
00188 std::string fn = mpsDir+"exmip1";
00189 imP->readMps(fn.c_str(),"mps");
00190 assert( !r.consistent(*imP) );
00191 delete imP;
00192 }
00193 {
00194 const int ne = 1;
00195 int inx[ne] = { 100 };
00196 double el[ne] = { 1.2 };
00197 const int ne1 = 2;
00198 int inx1[ne1] = { 50, 100 };
00199 double el1[ne1] = { 100., 1. };
00200 OsiColCut r;
00201 r.setUbs( ne, inx, el );
00202 r.setLbs( ne1, inx1, el1 );
00203 assert( r.consistent() );
00204 }
00205 {
00206
00207 OsiSolverInterface * imP = baseSiP->clone();
00208 std::string fn = mpsDir+"exmip1";
00209 imP->readMps(fn.c_str(),"mps");
00210
00211 OsiColCut cut;
00212 const int ne=1;
00213 int inx[ne]={20};
00214 double el[ne]={0.25};
00215 cut.setLbs(ne,inx,el);
00216 assert( !cut.consistent(*imP) );
00217
00218 cut.setLbs(0,NULL,NULL);
00219 cut.setUbs(ne,inx,el);
00220 assert( !cut.consistent(*imP) );
00221
00222 inx[0]=4;
00223 cut.setLbs(ne,inx,el);
00224 cut.setUbs(0,NULL,NULL);
00225 assert( cut.consistent(*imP) );
00226
00227 el[0]=4.5;
00228 cut.setLbs(0,NULL,NULL);
00229 cut.setUbs(ne,inx,el);
00230 assert( cut.consistent(*imP) );
00231
00232 cut.setLbs(ne,inx,el);
00233 cut.setUbs(0,NULL,NULL);
00234 assert( cut.consistent(*imP) );
00235 assert( cut.infeasible(*imP) );
00236
00237 el[0]=3.0;
00238 cut.setLbs(ne,inx,el);
00239 cut.setUbs(ne,inx,el);
00240 assert( cut.consistent(*imP) );
00241 delete imP;
00242 }
00243 {
00244
00245
00246 OsiSolverInterface * imP = baseSiP->clone();
00247 std::string fn = mpsDir+"exmip1";
00248 imP->readMps(fn.c_str(),"mps");
00249
00250 OsiColCut cut;
00251 const int ne=1;
00252 int inx[ne]={4};
00253 double el[ne]={4.5};
00254 cut.setLbs(ne,inx,el);
00255 assert( cut.infeasible(*imP) );
00256
00257 el[0]=0.25;
00258 cut.setLbs(0,NULL,NULL);
00259 cut.setUbs(ne,inx,el);
00260 assert( cut.infeasible(*imP) );
00261
00262 el[0]=3.0;
00263 cut.setLbs(ne,inx,el);
00264 cut.setUbs(ne,inx,el);
00265 assert( !cut.infeasible(*imP) );
00266
00267 delete imP;
00268 }
00269 {
00270
00271
00272 double solution[]={1.0};
00273 OsiColCut cut;
00274 const int ne=1;
00275 int inx[ne]={0};
00276 double el[ne]={4.5};
00277 cut.setLbs(ne,inx,el);
00278 assert( cut.violated(solution) );
00279
00280 el[0]=0.25;
00281 cut.setLbs(0,NULL,NULL);
00282 cut.setUbs(ne,inx,el);
00283 assert( cut.violated(solution) );
00284
00285 el[0]=1.0;
00286 cut.setLbs(ne,inx,el);
00287 cut.setUbs(ne,inx,el);
00288 assert( !cut.violated(solution) );
00289
00290 }
00291 }