replaced remaining getEpsilon by using ulps in double comparisons

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1091143 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-04-11 17:43:40 +00:00
parent b278d97dce
commit f69fd48e53
2 changed files with 7 additions and 17 deletions

View File

@ -33,7 +33,6 @@ import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.RealVector;
import org.apache.commons.math.optimization.GoalType;
import org.apache.commons.math.optimization.RealPointValuePair;
import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.util.MathUtils;
/**
@ -312,9 +311,9 @@ class SimplexTableau implements Serializable {
Integer row = null;
for (int i = 0; i < getHeight(); i++) {
final double entry = getEntry(i, col);
if (MathUtils.equals(entry, 1d, getEpsilon(entry)) && (row == null)) {
if (MathUtils.equals(entry, 1d, maxUlps) && (row == null)) {
row = i;
} else if (!MathUtils.equals(entry, 0d, getEpsilon(entry))) {
} else if (!MathUtils.equals(entry, 0d, maxUlps)) {
return null;
}
}
@ -336,7 +335,7 @@ class SimplexTableau implements Serializable {
// positive cost non-artificial variables
for (int i = getNumObjectiveFunctions(); i < getArtificialVariableOffset(); i++) {
final double entry = tableau.getEntry(0, i);
if (MathUtils.compareTo(entry, 0d, getEpsilon(entry)) > 0) {
if (MathUtils.compareTo(entry, 0d, maxUlps) > 0) {
columnsToDrop.add(i);
}
}
@ -615,14 +614,5 @@ class SimplexTableau implements Serializable {
throws ClassNotFoundException, IOException {
ois.defaultReadObject();
MatrixUtils.deserializeRealMatrix(this, "tableau", ois);
}
/**
* Get an epsilon that is adjusted to the magnitude of the given value.
* @param value the value for which to get the epsilon
* @return magnitude-adjusted epsilon using {@link FastMath.ulp}
*/
private double getEpsilon(double value) {
return FastMath.ulp(value) * (double) maxUlps;
}
}

View File

@ -31,7 +31,7 @@ import org.junit.Test;
public class SimplexSolverTest {
@Test
public void test434NegativeVariable() throws OptimizationException
public void testMath434NegativeVariable() throws OptimizationException
{
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {0.0, 0.0, 1.0}, 0.0d);
ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
@ -49,7 +49,7 @@ public class SimplexSolverTest {
}
@Test(expected = NoFeasibleSolutionException.class)
public void test434UnfeasibleSolution() throws OptimizationException
public void testMath434UnfeasibleSolution() throws OptimizationException
{
double epsilon = 1e-6;
@ -64,7 +64,7 @@ public class SimplexSolverTest {
}
@Test
public void test434PivotRowSelection() throws OptimizationException
public void testMath434PivotRowSelection() throws OptimizationException
{
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {1.0}, 0.0);
@ -81,7 +81,7 @@ public class SimplexSolverTest {
}
@Test
public void test434PivotRowSelection2() throws OptimizationException
public void testMath434PivotRowSelection2() throws OptimizationException
{
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {0.0d, 1.0d, 1.0d, 0.0d, 0.0d, 0.0d, 0.0d}, 0.0d);