Some tests have been developed, bugs got fixed.
1.1 --- a/lemon/lp_cplex.cc Fri Jun 10 12:22:22 2005 +0000
1.2 +++ b/lemon/lp_cplex.cc Fri Jun 10 12:50:43 2005 +0000
1.3 @@ -391,8 +391,8 @@
1.4 return UNDEFINED; //Everything else comes here
1.5 //FIXME error
1.6 }
1.7 + }
1.8
1.9 -
1.10 LpCplex::ProblemTypes LpCplex::_getProblemType()
1.11 {
1.12 int stat = CPXgetstat (env, lp);
1.13 @@ -410,7 +410,7 @@
1.14 return UNKNOWN;
1.15 //FIXME error
1.16 }
1.17 -
1.18 + }
1.19
1.20 void LpCplex::_setMax()
1.21 {
2.1 --- a/lemon/lp_glpk.cc Fri Jun 10 12:22:22 2005 +0000
2.2 +++ b/lemon/lp_glpk.cc Fri Jun 10 12:50:43 2005 +0000
2.3 @@ -21,7 +21,7 @@
2.4 ///\brief Implementation of the LEMON-GLPK lp solver interface.
2.5
2.6 #include <lemon/lp_glpk.h>
2.7 -
2.8 +//#include <iostream>
2.9 namespace lemon {
2.10
2.11
2.12 @@ -439,15 +439,18 @@
2.13
2.14 LpGlpk::SolutionStatus LpGlpk::_getDualStatus()
2.15 {
2.16 +// std::cout<<"Itt megy: "<<lpx_get_dual_stat(lp)<<std::endl;
2.17 +// std::cout<<"Itt a primal: "<<lpx_get_prim_stat(lp)<<std::endl;
2.18 +
2.19 switch (lpx_get_dual_stat(lp)) {
2.20 case LPX_D_UNDEF://Undefined (no solve has been run yet)
2.21 return UNDEFINED;
2.22 case LPX_D_NOFEAS://There is no feasible solution (primal, I guess)
2.23 // case LPX_D_INFEAS://Infeasible
2.24 return INFEASIBLE;
2.25 - case LPX_FEAS://Feasible
2.26 - switch (lpx_get_prim_stat(lp)) {
2.27 - case LPX_P_NOFEAS:
2.28 + case LPX_D_FEAS://Feasible
2.29 + switch (lpx_get_status(lp)) {
2.30 + case LPX_NOFEAS:
2.31 return INFINITE;
2.32 case LPX_OPT:
2.33 return OPTIMAL;
3.1 --- a/test/lp_test.cc Fri Jun 10 12:22:22 2005 +0000
3.2 +++ b/test/lp_test.cc Fri Jun 10 12:50:43 2005 +0000
3.3 @@ -1,4 +1,5 @@
3.4 #include<lemon/lp_skeleton.h>
3.5 +#include "test_tools.h"
3.6
3.7 #ifdef HAVE_CONFIG_H
3.8 #include <config.h>
3.9 @@ -170,6 +171,53 @@
3.10
3.11 }
3.12
3.13 +void aTest(LpSolverBase & lp)
3.14 +{
3.15 + typedef LpSolverBase LP;
3.16 +
3.17 + //The following example is taken from the book by Gáspár and Temesi, page 39.
3.18 +
3.19 + typedef LpSolverBase::Row Row;
3.20 + typedef LpSolverBase::Col Col;
3.21 +
3.22 +
3.23 + Col x1 = lp.addCol();
3.24 + Col x2 = lp.addCol();
3.25 +
3.26 +
3.27 + //Constraints
3.28 + lp.addRow(3*x1+2*x2 >=6);
3.29 + lp.addRow(-1*x1+x2<=4);
3.30 + lp.addRow(5*x1+8*x2<=40);
3.31 + lp.addRow(x1-2*x2<=4);
3.32 + //Nonnegativity of the variables
3.33 + lp.colLowerBound(x1, 0);
3.34 + lp.colLowerBound(x2, 0);
3.35 + //Objective function
3.36 + lp.setObj(2*x1+x2);
3.37 +
3.38 + lp.max();
3.39 + lp.solve();
3.40 +
3.41 +
3.42 + if (lp.primalStatus()==LpSolverBase::OPTIMAL){
3.43 + printf("Z = %g; x1 = %g; x2 = %g\n",
3.44 + lp.primalValue(),
3.45 + lp.primal(x1), lp.primal(x2));
3.46 + }
3.47 + else{
3.48 + std::cout<<"Optimal solution not found!"<<std::endl;
3.49 + }
3.50 +
3.51 + check(lp.primalStatus()==LpSolverBase::OPTIMAL,"Primalstatus should be OPTIMAL");
3.52 +
3.53 + double opt=123/9;
3.54 + check(lp.primalValue()==opt,"The optimum value is 122/9");
3.55 +
3.56 +
3.57 +}
3.58 +
3.59 +
3.60 int main()
3.61 {
3.62 LpSkeleton lp_skel;
3.63 @@ -178,11 +226,12 @@
3.64 #ifdef HAVE_GLPK
3.65 LpGlpk lp_glpk;
3.66 lpTest(lp_glpk);
3.67 + aTest(lp_glpk);
3.68 #endif
3.69
3.70 #ifdef HAVE_CPLEX
3.71 -// LpCplex lp_cplex;
3.72 -// lpTest(lp_cplex);
3.73 + LpCplex lp_cplex;
3.74 + lpTest(lp_cplex);
3.75 #endif
3.76
3.77 return 0;