fixed an error induced by zero entries in simplex solver
JIRA: MATH-288 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@807738 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dbdff0758b
commit
38983e8207
|
@ -77,9 +77,10 @@ public class SimplexSolver extends AbstractLinearOptimizer {
|
|||
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;
|
||||
|
|
|
@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
</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
|
||||
|
|
|
@ -57,7 +57,22 @@ public class SimplexSolverTest {
|
|||
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 =
|
||||
|
|
Loading…
Reference in New Issue