commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r807738 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java site/xdoc/changes.xml test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
Date Tue, 25 Aug 2009 18:07:14 GMT
Author: luc
Date: Tue Aug 25 18:07:13 2009
New Revision: 807738

URL: http://svn.apache.org/viewvc?rev=807738&view=rev
Log:
fixed an error induced by zero entries in simplex solver
JIRA: MATH-288

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java?rev=807738&r1=807737&r2=807738&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java
Tue Aug 25 18:07:13 2009
@@ -77,9 +77,10 @@
         double minRatio = Double.MAX_VALUE;
         Integer minRatioPos = null;
         for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getHeight(); i++)
{
-            double rhs = tableau.getEntry(i, tableau.getWidth() - 1);
-            if (MathUtils.compareTo(tableau.getEntry(i, col), 0, epsilon) >= 0) {
-                double ratio = rhs / tableau.getEntry(i, col);
+            final double rhs = tableau.getEntry(i, tableau.getWidth() - 1);
+            final double entry = tableau.getEntry(i, col);
+            if (MathUtils.compareTo(entry, 0, epsilon) > 0) {
+                final double ratio = rhs / entry;
                 if (ratio < minRatio) {
                     minRatio = ratio;
                     minRatioPos = i; 

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=807738&r1=807737&r2=807738&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Tue Aug 25 18:07:13 2009
@@ -39,6 +39,9 @@
   </properties>
   <body>
     <release version="2.1" date="TBD" description="TBD">
+      <action dev="luc" type="fix" issue="MATH-288" due-to="Benjamin McCann">
+        Fixed an error induced by entries set to 0
+      </action>
       <action dev="luc" type="fix" issue="MATH-286" due-to="Benjamin McCann">
         Fixed an error leading the simplex solver to compute the right solution
         but return another one

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java?rev=807738&r1=807737&r2=807738&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
Tue Aug 25 18:07:13 2009
@@ -57,7 +57,22 @@
       RealPointValuePair solution = new SimplexSolver().optimize(f, constraints, GoalType.MAXIMIZE,
true);
       assertEquals(6.9, solution.getValue(), .0000001);
     }
-    
+
+    @Test
+    public void testMath288() throws OptimizationException {
+        LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 7, 3, 0, 0
}, 0 );
+        Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
+        constraints.add(new LinearConstraint(new double[] { 3, 0, -5, 0 }, Relationship.LEQ,
0.0));
+        constraints.add(new LinearConstraint(new double[] { 2, 0, 0, -5 }, Relationship.LEQ,
0.0));
+        constraints.add(new LinearConstraint(new double[] { 0, 3, 0, -5 }, Relationship.LEQ,
0.0));
+        constraints.add(new LinearConstraint(new double[] { 1, 0, 0, 0 }, Relationship.LEQ,
1.0));
+        constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 0 }, Relationship.LEQ,
1.0));
+
+        SimplexSolver solver = new SimplexSolver();
+        RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE,
true);
+        assertEquals(10.0, solution.getValue(), .0000001);
+    }
+
     @Test
     public void testSimplexSolver() throws OptimizationException {
         LinearObjectiveFunction f =



Mime
View raw message