commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1207566 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java site/xdoc/changes.xml test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
Date Mon, 28 Nov 2011 20:16:30 GMT
Author: luc
Date: Mon Nov 28 20:16:28 2011
New Revision: 1207566

URL: http://svn.apache.org/viewvc?rev=1207566&view=rev
Log:
Fixed case of unconstrained variables that still occur in the objective
function in simplex solver.

Patch provided by Thomas Neidhart

Jira: MATH-713

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.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/SimplexTableau.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java?rev=1207566&r1=1207565&r2=1207566&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
Mon Nov 28 20:16:28 2011
@@ -407,7 +407,12 @@ class SimplexTableau implements Serializ
             continue;
           }
           Integer basicRow = getBasicRow(colIndex);
-          if (basicRows.contains(basicRow)) {
+          if (basicRow != null && basicRow == 0) {
+              // if the basic row is found to be the objective function row
+              // set the coefficient to 0 -> this case handles unconstrained 
+              // variables that are still part of the objective function
+              coefficients[i] = 0;
+          } else if (basicRows.contains(basicRow)) {
               // if multiple variables can take a given value
               // then we choose the first and set the rest equal to 0
               coefficients[i] = 0 - (restrictToNonNegative ? 0 : mostNegative);

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=1207566&r1=1207565&r2=1207566&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Nov 28 20:16:28 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="luc" type="fix" issue="MATH-713" due-to="Thomas Neidhart">
+        Fixed case of unconstrained variables that still occur in the objective function
+        in simplex solver.
+      </action>
       <action dev="luc" type="add" issue="MATH-710" due-to="Eldar Agalarov">
         The fast cryptographically secure pseudorandom number generator ISAAC has been added.
       </action>

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=1207566&r1=1207565&r2=1207566&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
Mon Nov 28 20:16:28 2011
@@ -30,6 +30,20 @@ import org.junit.Test;
 public class SimplexSolverTest {
 
     @Test
+    public void testMath713NegativeVariable() {
+        LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {1.0, 1.0},
0.0d);
+        ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
+        constraints.add(new LinearConstraint(new double[] {1, 0}, Relationship.EQ, 1));
+
+        double epsilon = 1e-6;
+        SimplexSolver solver = new SimplexSolver();
+        RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE,
true);
+
+        Assert.assertTrue(Precision.compareTo(solution.getPoint()[0], 0.0d, epsilon) >=
0);
+        Assert.assertTrue(Precision.compareTo(solution.getPoint()[1], 0.0d, epsilon) >=
0);
+    }
+
+    @Test
     public void testMath434NegativeVariable() {
         LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {0.0, 0.0, 1.0},
0.0d);
         ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>();



Mime
View raw message