[Lemon-commits] [lemon_svn] athos: r1953 - in hugo/trunk: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:49:02 CET 2006
Author: athos
Date: Fri Jun 10 14:50:43 2005
New Revision: 1953
Modified:
hugo/trunk/lemon/lp_cplex.cc
hugo/trunk/lemon/lp_glpk.cc
hugo/trunk/test/lp_test.cc
Log:
Some tests have been developed, bugs got fixed.
Modified: hugo/trunk/lemon/lp_cplex.cc
==============================================================================
--- hugo/trunk/lemon/lp_cplex.cc (original)
+++ hugo/trunk/lemon/lp_cplex.cc Fri Jun 10 14:50:43 2005
@@ -391,8 +391,8 @@
return UNDEFINED; //Everything else comes here
//FIXME error
}
+ }
-
LpCplex::ProblemTypes LpCplex::_getProblemType()
{
int stat = CPXgetstat (env, lp);
@@ -410,7 +410,7 @@
return UNKNOWN;
//FIXME error
}
-
+ }
void LpCplex::_setMax()
{
Modified: hugo/trunk/lemon/lp_glpk.cc
==============================================================================
--- hugo/trunk/lemon/lp_glpk.cc (original)
+++ hugo/trunk/lemon/lp_glpk.cc Fri Jun 10 14:50:43 2005
@@ -21,7 +21,7 @@
///\brief Implementation of the LEMON-GLPK lp solver interface.
#include <lemon/lp_glpk.h>
-
+//#include <iostream>
namespace lemon {
@@ -439,15 +439,18 @@
LpGlpk::SolutionStatus LpGlpk::_getDualStatus()
{
+// std::cout<<"Itt megy: "<<lpx_get_dual_stat(lp)<<std::endl;
+// std::cout<<"Itt a primal: "<<lpx_get_prim_stat(lp)<<std::endl;
+
switch (lpx_get_dual_stat(lp)) {
case LPX_D_UNDEF://Undefined (no solve has been run yet)
return UNDEFINED;
case LPX_D_NOFEAS://There is no feasible solution (primal, I guess)
// case LPX_D_INFEAS://Infeasible
return INFEASIBLE;
- case LPX_FEAS://Feasible
- switch (lpx_get_prim_stat(lp)) {
- case LPX_P_NOFEAS:
+ case LPX_D_FEAS://Feasible
+ switch (lpx_get_status(lp)) {
+ case LPX_NOFEAS:
return INFINITE;
case LPX_OPT:
return OPTIMAL;
Modified: hugo/trunk/test/lp_test.cc
==============================================================================
--- hugo/trunk/test/lp_test.cc (original)
+++ hugo/trunk/test/lp_test.cc Fri Jun 10 14:50:43 2005
@@ -1,4 +1,5 @@
#include<lemon/lp_skeleton.h>
+#include "test_tools.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -170,6 +171,53 @@
}
+void aTest(LpSolverBase & lp)
+{
+ typedef LpSolverBase LP;
+
+ //The following example is taken from the book by Gáspár and Temesi, page 39.
+
+ typedef LpSolverBase::Row Row;
+ typedef LpSolverBase::Col Col;
+
+
+ Col x1 = lp.addCol();
+ Col x2 = lp.addCol();
+
+
+ //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);
+ //Nonnegativity of the variables
+ lp.colLowerBound(x1, 0);
+ lp.colLowerBound(x2, 0);
+ //Objective function
+ lp.setObj(2*x1+x2);
+
+ lp.max();
+ lp.solve();
+
+
+ if (lp.primalStatus()==LpSolverBase::OPTIMAL){
+ printf("Z = %g; x1 = %g; x2 = %g\n",
+ lp.primalValue(),
+ lp.primal(x1), lp.primal(x2));
+ }
+ else{
+ std::cout<<"Optimal solution not found!"<<std::endl;
+ }
+
+ check(lp.primalStatus()==LpSolverBase::OPTIMAL,"Primalstatus should be OPTIMAL");
+
+ double opt=123/9;
+ check(lp.primalValue()==opt,"The optimum value is 122/9");
+
+
+}
+
+
int main()
{
LpSkeleton lp_skel;
@@ -178,11 +226,12 @@
#ifdef HAVE_GLPK
LpGlpk lp_glpk;
lpTest(lp_glpk);
+ aTest(lp_glpk);
#endif
#ifdef HAVE_CPLEX
-// LpCplex lp_cplex;
-// lpTest(lp_cplex);
+ LpCplex lp_cplex;
+ lpTest(lp_cplex);
#endif
return 0;
More information about the Lemon-commits
mailing list