// 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 #include #ifdef NDEBUG #undef NDEBUG #endif //-------------------------------------------------------------------------- void OsiColCutUnitTest(const OsiSolverInterface * baseSiP, const std::string & mpsDir) { // Test default constructor { OsiColCut r; assert( r.lbs_.getIndices()==NULL ); assert( r.lbs_.getElements()==NULL ); assert( r.ubs_.getIndices()==NULL ); assert( r.ubs_.getElements()==NULL ); assert( r.lbs_.getNumElements()==0); assert( r.ubs_.getNumElements()==0); } // 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 }; const int ne3 = 0; int * inx3=NULL; double * el3= NULL; { OsiColCut r; assert( r.lbs().getNumElements()==0 ); assert( r.ubs().getNumElements()==0 ); // Test setting/getting bounds r.setLbs( ne, inx, el ); r.setEffectiveness(222.); assert( r.lbs().getNumElements()==ne ); for ( int i=0; iclone(); std::string fn = mpsDir+"exmip1"; imP->readMps(fn.c_str(),"mps"); assert( !r.consistent(*imP) ); delete imP; } { const int ne = 1; int inx[ne] = { 100 }; double el[ne] = { 1.2 }; const int ne1 = 2; int inx1[ne1] = { 50, 100 }; double el1[ne1] = { 100., 1. }; OsiColCut r; r.setUbs( ne, inx, el ); r.setLbs( ne1, inx1, el1 ); assert( r.consistent() ); } { // Test consistent(IntegerModel) method. OsiSolverInterface * imP = baseSiP->clone(); std::string fn = mpsDir+"exmip1"; imP->readMps(fn.c_str(),"mps"); OsiColCut cut; const int ne=1; int inx[ne]={20}; double el[ne]={0.25}; cut.setLbs(ne,inx,el); assert( !cut.consistent(*imP) ); cut.setLbs(0,NULL,NULL); cut.setUbs(ne,inx,el); assert( !cut.consistent(*imP) ); inx[0]=4; cut.setLbs(ne,inx,el); cut.setUbs(0,NULL,NULL); assert( cut.consistent(*imP) ); el[0]=4.5; cut.setLbs(0,NULL,NULL); cut.setUbs(ne,inx,el); assert( cut.consistent(*imP) ); cut.setLbs(ne,inx,el); cut.setUbs(0,NULL,NULL); assert( cut.consistent(*imP) ); // Vailid but infeasible assert( cut.infeasible(*imP) ); el[0]=3.0; cut.setLbs(ne,inx,el); cut.setUbs(ne,inx,el); assert( cut.consistent(*imP) ); delete imP; } { //Test infeasible(im) method // Test consistent(IntegerModel) method. OsiSolverInterface * imP = baseSiP->clone(); std::string fn = mpsDir+"exmip1"; imP->readMps(fn.c_str(),"mps"); OsiColCut cut; const int ne=1; int inx[ne]={4}; double el[ne]={4.5}; cut.setLbs(ne,inx,el); assert( cut.infeasible(*imP) ); el[0]=0.25; cut.setLbs(0,NULL,NULL); cut.setUbs(ne,inx,el); assert( cut.infeasible(*imP) ); el[0]=3.0; cut.setLbs(ne,inx,el); cut.setUbs(ne,inx,el); assert( !cut.infeasible(*imP) ); delete imP; } { //Test violation double solution[]={1.0}; OsiColCut cut; const int ne=1; int inx[ne]={0}; double el[ne]={4.5}; cut.setLbs(ne,inx,el); assert( cut.violated(solution) ); el[0]=0.25; cut.setLbs(0,NULL,NULL); cut.setUbs(ne,inx,el); assert( cut.violated(solution) ); el[0]=1.0; cut.setLbs(ne,inx,el); cut.setUbs(ne,inx,el); assert( !cut.violated(solution) ); } }