Changeset 459:ed54c0d13df0 in lemon1.2 for test/mip_test.cc
 Timestamp:
 12/02/08 22:48:28 (11 years ago)
 Branch:
 default
 Children:
 460:76ec7bd57026, 502:17cabb114d52
 Phase:
 public
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

test/mip_test.cc
r458 r459 25 25 26 26 #ifdef HAVE_CPLEX 27 #include <lemon/ mip_cplex.h>27 #include <lemon/lp_cplex.h> 28 28 #endif 29 29 30 30 #ifdef HAVE_GLPK 31 #include <lemon/ mip_glpk.h>31 #include <lemon/lp_glpk.h> 32 32 #endif 33 33 … … 35 35 using namespace lemon; 36 36 37 void solveAndCheck(MipSolver Base& lp, MipSolverBase::SolutionStatusstat,37 void solveAndCheck(MipSolver& mip, MipSolver::ProblemType stat, 38 38 double exp_opt) { 39 39 using std::string; 40 40 41 lp.solve();41 mip.solve(); 42 42 //int decimal,sign; 43 43 std::ostringstream buf; 44 buf << "Primalstatus should be: " << int(stat) 45 <<" and it is "<<int(lp.mipStatus()); 44 buf << "Type should be: " << int(stat)<<" and it is "<<int(mip.type()); 46 45 47 46 48 47 // itoa(stat,buf1, 10); 49 check( lp.mipStatus()==stat, buf.str());48 check(mip.type()==stat, buf.str()); 50 49 51 if (stat == MipSolver Base::OPTIMAL) {50 if (stat == MipSolver::OPTIMAL) { 52 51 std::ostringstream sbuf; 53 52 buf << "Wrong optimal value: the right optimum is " << exp_opt; 54 check(std::abs( lp.primalValue()exp_opt) < 1e3, sbuf.str());53 check(std::abs(mip.solValue()exp_opt) < 1e3, sbuf.str()); 55 54 //+ecvt(exp_opt,2) 56 55 } 57 56 } 58 57 59 void aTest(MipSolver Base& mip)58 void aTest(MipSolver& mip) 60 59 { 61 60 //The following example is very simple 62 61 63 62 64 typedef MipSolver Base::Row Row;65 typedef MipSolver Base::Col Col;63 typedef MipSolver::Row Row; 64 typedef MipSolver::Col Col; 66 65 67 66 … … 91 90 //over the triangle with vertices (0,0),(4/5,2/5),(0,2) 92 91 double expected_opt=4.0/5.0; 93 solveAndCheck(mip, MipSolver Base::OPTIMAL, expected_opt);92 solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt); 94 93 95 94 //Restrict x2 to integer 96 mip.colType(x2,MipSolver Base::INT);95 mip.colType(x2,MipSolver::INTEGER); 97 96 expected_opt=1.0/2.0; 98 solveAndCheck(mip, MipSolver Base::OPTIMAL, expected_opt);97 solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt); 99 98 100 99 101 100 //Restrict both to integer 102 mip.colType(x1,MipSolver Base::INT);101 mip.colType(x1,MipSolver::INTEGER); 103 102 expected_opt=0; 104 solveAndCheck(mip, MipSolver Base::OPTIMAL, expected_opt);103 solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt); 105 104 106 105 … … 113 112 114 113 #ifdef HAVE_GLPK 115 MipGlpk mip1; 116 aTest(mip1); 114 { 115 MipGlpk mip1; 116 aTest(mip1); 117 } 117 118 #endif 118 119 119 120 #ifdef HAVE_CPLEX 120 MipCplex mip2; 121 aTest(mip2); 121 try { 122 MipCplex mip2; 123 aTest(mip2); 124 } catch (CplexEnv::LicenseError& error) { 125 #ifdef LEMON_FORCE_CPLEX_CHECK 126 check(false, error.what()); 127 #else 128 std::cerr << error.what() << std::endl; 129 std::cerr << "Cplex license check failed, lp check skipped" << std::endl; 130 #endif 131 } 122 132 #endif 123 133
Note: See TracChangeset
for help on using the changeset viewer.