1 #include "test_tools.h"
 
     9 #include <lemon/mip_cplex.h>
 
    13 #include <lemon/mip_glpk.h>
 
    17 using namespace lemon;
 
    19 void solveAndCheck(MipSolverBase& lp, MipSolverBase::SolutionStatus stat, 
 
    25   std::ostringstream buf;
 
    26   buf << "Primalstatus should be: " << int(stat)<<" and it is "<<int(lp.primalStatus());
 
    29   //  itoa(stat,buf1, 10);
 
    30   check(lp.mipStatus()==stat, buf.str());
 
    32   if (stat ==  MipSolverBase::OPTIMAL) {
 
    33     std::ostringstream buf;
 
    34     buf << "Wrong optimal value: the right optimum is " << exp_opt; 
 
    35     check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str());
 
    40 void aTest(MipSolverBase& mip)
 
    42  //The following example is very simple
 
    45   typedef MipSolverBase::Row Row;
 
    46   typedef MipSolverBase::Col Col;
 
    50   Col x1 = mip.addCol();
 
    51   Col x2 = mip.addCol();
 
    60   //Unconstrained optimization
 
    65   mip.addRow(2*x1+x2 <=2);  
 
    66   mip.addRow(x1-2*x2 <=0);  
 
    68   //Nonnegativity of the variable x1
 
    69   mip.colLowerBound(x1, 0);
 
    74   //over the triangle with vertices (0,0),(4/5,2/5),(0,2)
 
    75   double expected_opt=4.0/5.0;
 
    76   solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
 
    78   //Restrict x2 to integer
 
    79   mip.colType(x2,MipSolverBase::LEMON_INTEGER);  
 
    81   solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
 
    84   //Restrict both to integer
 
    85   mip.colType(x1,MipSolverBase::LEMON_INTEGER);  
 
    87   solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);