test/mip_test.cc
changeset 482 ed54c0d13df0
parent 481 7afc121e0689
child 484 08d495d48089
     1.1 --- a/test/mip_test.cc	Tue Dec 02 21:40:33 2008 +0100
     1.2 +++ b/test/mip_test.cc	Tue Dec 02 22:48:28 2008 +0100
     1.3 @@ -24,45 +24,44 @@
     1.4  #endif
     1.5  
     1.6  #ifdef HAVE_CPLEX
     1.7 -#include <lemon/mip_cplex.h>
     1.8 +#include <lemon/lp_cplex.h>
     1.9  #endif
    1.10  
    1.11  #ifdef HAVE_GLPK
    1.12 -#include <lemon/mip_glpk.h>
    1.13 +#include <lemon/lp_glpk.h>
    1.14  #endif
    1.15  
    1.16  
    1.17  using namespace lemon;
    1.18  
    1.19 -void solveAndCheck(MipSolverBase& lp, MipSolverBase::SolutionStatus stat,
    1.20 +void solveAndCheck(MipSolver& mip, MipSolver::ProblemType stat,
    1.21                     double exp_opt) {
    1.22    using std::string;
    1.23  
    1.24 -  lp.solve();
    1.25 +  mip.solve();
    1.26    //int decimal,sign;
    1.27    std::ostringstream buf;
    1.28 -  buf << "Primalstatus should be: " << int(stat)
    1.29 -      <<" and it is "<<int(lp.mipStatus());
    1.30 +  buf << "Type should be: " << int(stat)<<" and it is "<<int(mip.type());
    1.31  
    1.32  
    1.33    //  itoa(stat,buf1, 10);
    1.34 -  check(lp.mipStatus()==stat, buf.str());
    1.35 +  check(mip.type()==stat, buf.str());
    1.36  
    1.37 -  if (stat ==  MipSolverBase::OPTIMAL) {
    1.38 +  if (stat ==  MipSolver::OPTIMAL) {
    1.39      std::ostringstream sbuf;
    1.40      buf << "Wrong optimal value: the right optimum is " << exp_opt;
    1.41 -    check(std::abs(lp.primalValue()-exp_opt) < 1e-3, sbuf.str());
    1.42 +    check(std::abs(mip.solValue()-exp_opt) < 1e-3, sbuf.str());
    1.43      //+ecvt(exp_opt,2)
    1.44    }
    1.45  }
    1.46  
    1.47 -void aTest(MipSolverBase& mip)
    1.48 +void aTest(MipSolver& mip)
    1.49  {
    1.50   //The following example is very simple
    1.51  
    1.52  
    1.53 -  typedef MipSolverBase::Row Row;
    1.54 -  typedef MipSolverBase::Col Col;
    1.55 +  typedef MipSolver::Row Row;
    1.56 +  typedef MipSolver::Col Col;
    1.57  
    1.58  
    1.59  
    1.60 @@ -90,18 +89,18 @@
    1.61    //Maximization of x1
    1.62    //over the triangle with vertices (0,0),(4/5,2/5),(0,2)
    1.63    double expected_opt=4.0/5.0;
    1.64 -  solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
    1.65 +  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
    1.66  
    1.67    //Restrict x2 to integer
    1.68 -  mip.colType(x2,MipSolverBase::INT);
    1.69 +  mip.colType(x2,MipSolver::INTEGER);
    1.70    expected_opt=1.0/2.0;
    1.71 -  solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
    1.72 +  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
    1.73  
    1.74  
    1.75    //Restrict both to integer
    1.76 -  mip.colType(x1,MipSolverBase::INT);
    1.77 +  mip.colType(x1,MipSolver::INTEGER);
    1.78    expected_opt=0;
    1.79 -  solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
    1.80 +  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
    1.81  
    1.82  
    1.83  
    1.84 @@ -112,13 +111,24 @@
    1.85  {
    1.86  
    1.87  #ifdef HAVE_GLPK
    1.88 -  MipGlpk mip1;
    1.89 -  aTest(mip1);
    1.90 +  {
    1.91 +    MipGlpk mip1;
    1.92 +    aTest(mip1);
    1.93 +  }
    1.94  #endif
    1.95  
    1.96  #ifdef HAVE_CPLEX
    1.97 -  MipCplex mip2;
    1.98 -  aTest(mip2);
    1.99 +  try {
   1.100 +    MipCplex mip2;
   1.101 +    aTest(mip2);
   1.102 +  } catch (CplexEnv::LicenseError& error) {
   1.103 +#ifdef LEMON_FORCE_CPLEX_CHECK
   1.104 +    check(false, error.what());
   1.105 +#else
   1.106 +    std::cerr << error.what() << std::endl;
   1.107 +    std::cerr << "Cplex license check failed, lp check skipped" << std::endl;
   1.108 +#endif
   1.109 +  }
   1.110  #endif
   1.111  
   1.112    return 0;