Author: tn Date: Wed May 2 18:28:37 2012 New Revision: 1333146 URL: http://svn.apache.org/viewvc?rev=1333146&view=rev Log: [MATH-781] use epsilon criteria when deciding to drop columns after phase 1.
Modified: commons/proper/math/trunk/src/changes/changes.xml commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/linear/SimplexSolverTest.java Modified: commons/proper/math/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1333146&r1=1333145&r2=1333146&view=diff ============================================================================== --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Wed May 2 18:28:37 2012 @@ -52,6 +52,9 @@ If the output is not quite correct, chec <body> <release version="3.1" date="TBD" description=" "> + <action dev="tn" type="fix" issue="MATH-781" due-to="Scheiber ErnÅ"> + Use epsilon instead of ulp in floating-point comparison when dropping columns after phase 1 in SimplexSolver. + </action> <action dev="luc" type="fix" issue="MATH-721"> Added a workaround for an OpenJDK issue on sparc solaris with too small constants. </action> @@ -179,7 +182,7 @@ counterpart in either Math or StrictMath Broke up bloated "MathUtils" class into "MathArrays", "Precision", "ArithmeticUtils" classes. </action> - <action dev="psteitz" type="fix" issue="MATH-704" due-to="Thomas Niedhart"> + <action dev="psteitz" type="fix" issue="MATH-704" due-to="Thomas Neidhart"> Fixed array indexing error in Variance evaluate method for computing the weighted variance of an array segment. </action> Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java?rev=1333146&r1=1333145&r2=1333146&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/linear/SimplexTableau.java Wed May 2 18:28:37 2012 @@ -335,7 +335,7 @@ class SimplexTableau implements Serializ // positive cost non-artificial variables for (int i = getNumObjectiveFunctions(); i < getArtificialVariableOffset(); i++) { final double entry = tableau.getEntry(0, i); - if (Precision.compareTo(entry, 0d, maxUlps) > 0) { + if (Precision.compareTo(entry, 0d, epsilon) > 0) { columnsToDrop.add(i); } } Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/linear/SimplexSolverTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/linear/SimplexSolverTest.java?rev=1333146&r1=1333145&r2=1333146&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/linear/SimplexSolverTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/linear/SimplexSolverTest.java Wed May 2 18:28:37 2012 @@ -30,6 +30,25 @@ import org.junit.Test; public class SimplexSolverTest { @Test + public void testMath781() { + LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 2, 6, 7 }, 0); + + ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>(); + constraints.add(new LinearConstraint(new double[] { 1, 2, 1 }, Relationship.LEQ, 2)); + constraints.add(new LinearConstraint(new double[] { -1, 1, 1 }, Relationship.LEQ, -1)); + constraints.add(new LinearConstraint(new double[] { 2, -3, 1 }, Relationship.LEQ, -1)); + + double epsilon = 1e-6; + SimplexSolver solver = new SimplexSolver(); + PointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, false); + + Assert.assertTrue(Precision.compareTo(solution.getPoint()[0], 0.0d, epsilon) > 0); + Assert.assertTrue(Precision.compareTo(solution.getPoint()[1], 0.0d, epsilon) > 0); + Assert.assertTrue(Precision.compareTo(solution.getPoint()[2], 0.0d, epsilon) < 0); + Assert.assertEquals(2.0d, solution.getValue(), epsilon); + } + + @Test public void testMath713NegativeVariable() { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {1.0, 1.0}, 0.0d); ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>();