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 #include <cstdio> 6 7 #ifdef NDEBUG 8 #undef NDEBUG 9 #endif 10 11 #include <cassert> 12 #include "CoinPragma.hpp" 13 #include "CglMixedIntegerRounding2.hpp" 14 15 16 void CglMixedIntegerRounding2UnitTest(const OsiSolverInterface * baseSiP,const std::string mpsDir)17CglMixedIntegerRounding2UnitTest(const OsiSolverInterface *baseSiP, 18 const std::string mpsDir) 19 { 20 // Test default constructor 21 { 22 CglMixedIntegerRounding2 aGenerator; 23 } 24 25 // Test copy & assignment 26 { 27 CglMixedIntegerRounding2 rhs; 28 { 29 CglMixedIntegerRounding2 bGenerator; 30 CglMixedIntegerRounding2 cGenerator(bGenerator); 31 rhs=bGenerator; 32 } 33 } 34 35 // Test get/set methods 36 { 37 CglMixedIntegerRounding2 getset; 38 39 int gagg = 10 * getset.getMAXAGGR_(); 40 getset.setMAXAGGR_(gagg); 41 int gagg2 = getset.getMAXAGGR_(); 42 assert(gagg == gagg2); 43 44 bool gmult = !getset.getMULTIPLY_(); 45 getset.setMULTIPLY_(gmult); 46 bool gmult2 = getset.getMULTIPLY_(); 47 assert(gmult == gmult2); 48 49 int gcrit = getset.getCRITERION_(); 50 gcrit = (gcrit) % 3 + 1; 51 getset.setCRITERION_(gcrit); 52 int gcrit2 = getset.getCRITERION_(); 53 assert(gcrit == gcrit2); 54 55 int gpre = getset.getDoPreproc(); 56 gpre = (gpre + 1) % 3 - 1; 57 getset.setDoPreproc(gpre); 58 int gpre2 = getset.getDoPreproc(); 59 assert(gpre == gpre2); 60 } 61 62 // Test generateCuts 63 { 64 CglMixedIntegerRounding2 gct; 65 OsiSolverInterface *siP = baseSiP->clone(); 66 std::string fn = mpsDir+"capPlan1"; 67 std::string fn2 = mpsDir+"capPlan1.mps"; 68 FILE *in_f = fopen(fn2.c_str(), "r"); 69 if(in_f == NULL) { 70 std::cout<<"Can not open file "<<fn2<<std::endl<<"Skip test of CglMixedIntegerRounding2::generateCuts()"<<std::endl; 71 } 72 else { 73 fclose(in_f); 74 siP->readMps(fn.c_str(),"mps"); 75 76 siP->initialSolve(); 77 double lpRelax = siP->getObjValue(); 78 79 OsiCuts cs; 80 gct.setDoPreproc(1); // Needed for DyLP 81 gct.generateCuts(*siP, cs); 82 int nRowCuts = cs.sizeRowCuts(); 83 std::cout<<"There are "<<nRowCuts<<" MIR2 cuts"<<std::endl; 84 assert(cs.sizeRowCuts() > 0); 85 OsiSolverInterface::ApplyCutsReturnCode rc = siP->applyCuts(cs); 86 87 siP->resolve(); 88 89 double lpRelaxAfter= siP->getObjValue(); 90 printf("Initial LP value: %f\n", lpRelax); 91 printf("LP value with cuts: %f\n", lpRelaxAfter); 92 assert( lpRelax < lpRelaxAfter ); 93 assert(lpRelaxAfter < 964); 94 } 95 delete siP; 96 } 97 98 } 99 100