// Copyright (C) 2000, International Business Machines // Corporation and others. All Rights Reserved. #if defined(_MSC_VER) // Turn off compiler warning about long names # pragma warning(disable:4786) #endif #include #include #include "OsiRowCut.hpp" #include "OsiFloatEqual.hpp" #ifdef NDEBUG #undef NDEBUG #endif //-------------------------------------------------------------------------- void OsiRowCutUnitTest(const OsiSolverInterface * baseSiP, const std::string & mpsDir ) { OsiRelFltEq eq; // Test default constructor { OsiRowCut r; assert( r.row_.getIndices()==NULL ); assert( r.row_.getElements()==NULL ); assert( r.lb_==-/*std::numeric_limits::max()*/DBL_MAX ); assert( r.ub_== /*std::numeric_limits::max()*/DBL_MAX ); } // Test set and get methods const int ne = 4; int inx[ne] = { 1, 3, 4, 7 }; double el[ne] = { 1.2, 3.4, 5.6, 7.8 }; { OsiRowCut r; assert( r.row().getNumElements()==0 ); assert( r.effectiveness()==0. ); //assert( r.timesUsed()==0 ); //assert( r.timesTested()==0 ); // Test setting getting bounds r.setLb(65.432); r.setUb(123.45); assert( r.lb()==65.432 ); assert( r.ub()==123.45 ); // Test setting/getting of effectiveness,timesUsed,timesTested r.setEffectiveness(45.); assert( r.effectiveness()==45. ); #if 0 r.setTimesUsed(11); assert( r.timesUsed()==11 ); r.incrementTimesUsed(); assert( r.timesUsed()==12 ); r.setTimesTested(111); assert( r.timesTested()==111 ); r.incrementTimesTested(); assert( r.timesTested()==112 ); #endif // Test setting/getting elements with int* & float* vectors r.setRow( ne, inx, el ); assert( r.row().getNumElements()==ne ); for ( int i=0; i rc) ); assert( !(rc > c ) ); } { OsiRowCut c(rc); const int ne1 = 4; int inx1[ne] = { 1, 3, 4, 7 }; double el1[ne] = { 1.2, 3.4, 5.6, 7.9 }; c.setRow(ne1,inx1,el1); assert( !(c == rc) ); assert( c != rc ); assert( !(rc < c) ); } { OsiRowCut c(rc); c.setEffectiveness(3.); assert( !(c == rc) ); assert( c != rc ); assert( rc < c ); assert( !(c < rc) ); assert( !(rc > c) ); assert( c > rc ); } { OsiRowCut c(rc); c.setLb(4.0); assert( !(c == rc) ); assert( c != rc ); } { OsiRowCut c(rc); c.setUb(5.0); assert( !(c == rc) ); assert( c != rc ); } } { // Test consistent OsiSolverInterface * imP = baseSiP->clone(); std::string fn = mpsDir+"exmip1"; imP->readMps(fn.c_str(),"mps"); OsiRowCut c; const int ne = 3; int inx[ne] = { -1, 5, 4 }; double el[ne] = { 1., 1., 1. }; c.setRow(ne,inx,el); assert( !c.consistent() );; inx[0]=5; #if 0 c.setRow(ne,inx,el); assert( !c.consistent() ); #else bool errorThrown = false; try { c.setRow(ne,inx,el); } catch (CoinError e) { errorThrown = true; } assert(errorThrown); #endif inx[0]=3; c.setRow(ne,inx,el); assert( c.consistent() ); c.setLb(5.); c.setUb(5.); assert( c.consistent() ); c.setLb(5.5); assert( c.consistent() ); assert( c.infeasible(*imP) ); delete imP; } { // Test consistent(IntegerModel) method. OsiSolverInterface * imP = baseSiP->clone(); std::string fn = mpsDir+"exmip1"; imP->readMps(fn.c_str(),"mps"); OsiRowCut cut; const int ne = 3; int inx[ne] = { 3, 5, 4 }; double el[ne] = { 1., 1., 1. }; cut.setRow(ne,inx,el); assert( cut.consistent() ); inx[0]=7; cut.setRow(ne,inx,el); assert( cut.consistent(*imP) ); inx[0]=8; cut.setRow(ne,inx,el); assert( cut.consistent() ); assert( !cut.consistent(*imP) ); delete imP; } { //Test infeasible(im) method OsiSolverInterface * imP = baseSiP->clone(); std::string fn = mpsDir+"exmip1"; imP->readMps(fn.c_str(),"mps"); OsiRowCut cut; const int ne = 3; int inx[ne] = { 3, 5, 4 }; double el[ne] = { 1., 1., 1. }; cut.setRow(ne,inx,el); assert( !cut.infeasible(*imP) ); OsiRowCut c1; assert( !c1.infeasible(*imP) ); assert( c1.consistent() ); assert( c1.consistent(*imP) ); delete imP; } }