1.1 --- a/test/lp_test.cc Fri Jun 10 12:22:22 2005 +0000
1.2 +++ b/test/lp_test.cc Fri Jun 10 12:50:43 2005 +0000
1.3 @@ -1,4 +1,5 @@
1.4 #include<lemon/lp_skeleton.h>
1.5 +#include "test_tools.h"
1.6
1.7 #ifdef HAVE_CONFIG_H
1.8 #include <config.h>
1.9 @@ -170,6 +171,53 @@
1.10
1.11 }
1.12
1.13 +void aTest(LpSolverBase & lp)
1.14 +{
1.15 + typedef LpSolverBase LP;
1.16 +
1.17 + //The following example is taken from the book by Gáspár and Temesi, page 39.
1.18 +
1.19 + typedef LpSolverBase::Row Row;
1.20 + typedef LpSolverBase::Col Col;
1.21 +
1.22 +
1.23 + Col x1 = lp.addCol();
1.24 + Col x2 = lp.addCol();
1.25 +
1.26 +
1.27 + //Constraints
1.28 + lp.addRow(3*x1+2*x2 >=6);
1.29 + lp.addRow(-1*x1+x2<=4);
1.30 + lp.addRow(5*x1+8*x2<=40);
1.31 + lp.addRow(x1-2*x2<=4);
1.32 + //Nonnegativity of the variables
1.33 + lp.colLowerBound(x1, 0);
1.34 + lp.colLowerBound(x2, 0);
1.35 + //Objective function
1.36 + lp.setObj(2*x1+x2);
1.37 +
1.38 + lp.max();
1.39 + lp.solve();
1.40 +
1.41 +
1.42 + if (lp.primalStatus()==LpSolverBase::OPTIMAL){
1.43 + printf("Z = %g; x1 = %g; x2 = %g\n",
1.44 + lp.primalValue(),
1.45 + lp.primal(x1), lp.primal(x2));
1.46 + }
1.47 + else{
1.48 + std::cout<<"Optimal solution not found!"<<std::endl;
1.49 + }
1.50 +
1.51 + check(lp.primalStatus()==LpSolverBase::OPTIMAL,"Primalstatus should be OPTIMAL");
1.52 +
1.53 + double opt=123/9;
1.54 + check(lp.primalValue()==opt,"The optimum value is 122/9");
1.55 +
1.56 +
1.57 +}
1.58 +
1.59 +
1.60 int main()
1.61 {
1.62 LpSkeleton lp_skel;
1.63 @@ -178,11 +226,12 @@
1.64 #ifdef HAVE_GLPK
1.65 LpGlpk lp_glpk;
1.66 lpTest(lp_glpk);
1.67 + aTest(lp_glpk);
1.68 #endif
1.69
1.70 #ifdef HAVE_CPLEX
1.71 -// LpCplex lp_cplex;
1.72 -// lpTest(lp_cplex);
1.73 + LpCplex lp_cplex;
1.74 + lpTest(lp_cplex);
1.75 #endif
1.76
1.77 return 0;