The recent progresses on the tutorial due to Mark.
2 #include "test_tools.h"
6 void solveAndCheck(Mip& lp, LpSolverBase::SolutionStatus stat,
11 std::ostringstream buf;
12 buf << "Primalstatus should be: " << int(stat)<<" and it is "<<int(lp.primalStatus());
14 // itoa(stat,buf1, 10);
15 check(lp.mipStatus()==stat, buf.str());
17 if (stat == LpSolverBase::OPTIMAL) {
18 std::ostringstream buf;
19 buf << "Wrong optimal value: the right optimum is " << exp_opt;
20 check(std::abs(lp.primalValue()-exp_opt) < 1e-3, buf.str());
27 //The following example is very simple
33 Col x1 = mip.addCol();
34 Col x2 = mip.addCol();
47 //Unconstrained optimization
52 mip.addRow(2*x1+x2 <=2);
53 mip.addRow(x1-2*x2 <=0);
55 //Nonnegativity of the variable x1
56 mip.colLowerBound(x1, 0);
61 //over the triangle with vertices
62 double expected_opt=4.0/5.0;
63 solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
65 //Restrict x2 to integer
66 mip.colType(x2,Mip::INTEGER);
68 solveAndCheck(mip, Mip::OPTIMAL, expected_opt);
71 //Restrict both to integer
72 mip.colType(x1,Mip::INTEGER);
74 solveAndCheck(mip, Mip::OPTIMAL, expected_opt);