diff -r 305ce06287c9 -r 0219ee65ffcc test/lp_test.cc --- a/test/lp_test.cc Thu Jul 07 09:04:39 2005 +0000 +++ b/test/lp_test.cc Thu Jul 07 15:00:04 2005 +0000 @@ -1,6 +1,7 @@ #include #include "test_tools.h" + #ifdef HAVE_CONFIG_H #include #endif @@ -182,11 +183,26 @@ #endif } +void solveAndCheck(LpSolverBase& lp, LpSolverBase::SolutionStatus stat, + double exp_opt){ + lp.solve(); + //int decimal,sign; + std::string buf1; + // itoa(stat,buf1, 10); + check(lp.primalStatus()==stat,"Primalstatus should be "+buf1); + + if (stat == LpSolverBase::OPTIMAL){ + check(std::abs(lp.primalValue()-exp_opt)<1e-3, + "Wrong optimal value: the right optimum is "); + //+ecvt(exp_opt,2) + } +} + void aTest(LpSolverBase & lp) { typedef LpSolverBase LP; - //The following example is taken from the book by Gáspár and Temesi, page 39. + //The following example is very simple typedef LpSolverBase::Row Row; typedef LpSolverBase::Col Col; @@ -197,38 +213,62 @@ //Constraints - lp.addRow(3*x1+2*x2 >=6); - lp.addRow(-1*x1+x2<=4); - lp.addRow(5*x1+8*x2<=40); - lp.addRow(x1-2*x2<=4); + Row upright=lp.addRow(x1+x2 <=1); + lp.addRow(x1+x2 >=-1); + lp.addRow(x1-x2 <=1); + lp.addRow(x1-x2 >=-1); //Nonnegativity of the variables lp.colLowerBound(x1, 0); lp.colLowerBound(x2, 0); //Objective function - lp.setObj(2*x1+x2); + lp.setObj(x1+x2); lp.max(); - lp.solve(); - double opt=122.0/9.0; + //Maximization of x1+x2 + //over the triangle with vertices (0,0) (0,1) (1,0) + double expected_opt=1; + solveAndCheck(lp, LpSolverBase::OPTIMAL, expected_opt); - if (lp.primalStatus()==LpSolverBase::OPTIMAL){ - std::cout<< "Z = "<