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:
parent
b278d97dce
commit
f69fd48e53
|
@ -33,7 +33,6 @@ import org.apache.commons.math.linear.RealMatrix;
|
||||||
import org.apache.commons.math.linear.RealVector;
|
import org.apache.commons.math.linear.RealVector;
|
||||||
import org.apache.commons.math.optimization.GoalType;
|
import org.apache.commons.math.optimization.GoalType;
|
||||||
import org.apache.commons.math.optimization.RealPointValuePair;
|
import org.apache.commons.math.optimization.RealPointValuePair;
|
||||||
import org.apache.commons.math.util.FastMath;
|
|
||||||
import org.apache.commons.math.util.MathUtils;
|
import org.apache.commons.math.util.MathUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -312,9 +311,9 @@ class SimplexTableau implements Serializable {
|
||||||
Integer row = null;
|
Integer row = null;
|
||||||
for (int i = 0; i < getHeight(); i++) {
|
for (int i = 0; i < getHeight(); i++) {
|
||||||
final double entry = getEntry(i, col);
|
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;
|
row = i;
|
||||||
} else if (!MathUtils.equals(entry, 0d, getEpsilon(entry))) {
|
} else if (!MathUtils.equals(entry, 0d, maxUlps)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,7 +335,7 @@ class SimplexTableau implements Serializable {
|
||||||
// positive cost non-artificial variables
|
// positive cost non-artificial variables
|
||||||
for (int i = getNumObjectiveFunctions(); i < getArtificialVariableOffset(); i++) {
|
for (int i = getNumObjectiveFunctions(); i < getArtificialVariableOffset(); i++) {
|
||||||
final double entry = tableau.getEntry(0, 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);
|
columnsToDrop.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -616,13 +615,4 @@ class SimplexTableau implements Serializable {
|
||||||
ois.defaultReadObject();
|
ois.defaultReadObject();
|
||||||
MatrixUtils.deserializeRealMatrix(this, "tableau", ois);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.junit.Test;
|
||||||
public class SimplexSolverTest {
|
public class SimplexSolverTest {
|
||||||
|
|
||||||
@Test
|
@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);
|
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {0.0, 0.0, 1.0}, 0.0d);
|
||||||
ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
|
ArrayList<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
|
||||||
|
@ -49,7 +49,7 @@ public class SimplexSolverTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NoFeasibleSolutionException.class)
|
@Test(expected = NoFeasibleSolutionException.class)
|
||||||
public void test434UnfeasibleSolution() throws OptimizationException
|
public void testMath434UnfeasibleSolution() throws OptimizationException
|
||||||
{
|
{
|
||||||
double epsilon = 1e-6;
|
double epsilon = 1e-6;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class SimplexSolverTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test434PivotRowSelection() throws OptimizationException
|
public void testMath434PivotRowSelection() throws OptimizationException
|
||||||
{
|
{
|
||||||
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {1.0}, 0.0);
|
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {1.0}, 0.0);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class SimplexSolverTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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);
|
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] {0.0d, 1.0d, 1.0d, 0.0d, 0.0d, 0.0d, 0.0d}, 0.0d);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue