Minor changes.
1 #include "test_tools.h"
4 #include <lemon/mip_cplex.h>
5 #include <lemon/mip_glpk.h>
13 using namespace lemon;
15 void solveAndCheck(MipSolverBase& lp, MipSolverBase::SolutionStatus stat,
21 std::ostringstream buf;
22 buf << "Primalstatus should be: " << int(stat)<<" and it is "<<int(lp.primalStatus());
25 // itoa(stat,buf1, 10);
26 check(lp.mipStatus()==stat, buf.str());
28 if (stat == MipSolverBase::OPTIMAL) {
29 std::ostringstream buf;
30 buf << "Wrong optimal value: the right optimum is " << exp_opt;
31 check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str());
36 void aTest(MipSolverBase& mip)
38 //The following example is very simple
41 typedef MipSolverBase::Row Row;
42 typedef MipSolverBase::Col Col;
46 Col x1 = mip.addCol();
47 Col x2 = mip.addCol();
56 //Unconstrained optimization
61 mip.addRow(2*x1+x2 <=2);
62 mip.addRow(x1-2*x2 <=0);
64 //Nonnegativity of the variable x1
65 mip.colLowerBound(x1, 0);
70 //over the triangle with vertices (0,0),(4/5,2/5),(0,2)
71 double expected_opt=4.0/5.0;
72 solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
74 //Restrict x2 to integer
75 mip.colType(x2,MipSolverBase::LEMON_INTEGER);
77 solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);
80 //Restrict both to integer
81 mip.colType(x1,MipSolverBase::LEMON_INTEGER);
83 solveAndCheck(mip, MipSolverBase::OPTIMAL, expected_opt);