mirror of
https://github.com/apache/commons-math.git
synced 2025-02-07 02:29:20 +00:00
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;
|
continue;
|
||||||
}
|
}
|
||||||
Integer basicRow = getBasicRow(colIndex);
|
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
|
// if multiple variables can take a given value
|
||||||
// then we choose the first and set the rest equal to 0
|
// then we choose the first and set the rest equal to 0
|
||||||
coefficients[i] = 0 - (restrictToNonNegative ? 0 : mostNegative);
|
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!
|
If the output is not quite correct, check for invisible trailing spaces!
|
||||||
-->
|
-->
|
||||||
<release version="3.0" date="TBD" description="TBD">
|
<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">
|
<action dev="luc" type="add" issue="MATH-710" due-to="Eldar Agalarov">
|
||||||
The fast cryptographically secure pseudorandom number generator ISAAC has been added.
|
The fast cryptographically secure pseudorandom number generator ISAAC has been added.
|
||||||
</action>
|
</action>
|
||||||
|
@ -29,6 +29,20 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class SimplexSolverTest {
|
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
|
@Test
|
||||||
public void testMath434NegativeVariable() {
|
public void testMath434NegativeVariable() {
|
||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user