Fixed case of unconstrained variables that still occur in the objective
function in simplex solver. Patch provided by Thomas Neidhart Jira: MATH-713 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1207566 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f14fdb5447
commit
f656676e3a
|
@ -407,7 +407,12 @@ class SimplexTableau implements Serializable {
|
|||
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);
|
||||
|
|
|
@ -52,6 +52,10 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
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>
|
||||
|
|
|
@ -29,6 +29,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);
|
||||
|
|
Loading…
Reference in New Issue