Fixed a wrong check for basic variables
JIRA: MATH-273 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@781304 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
10cdc1066f
commit
59434c2dce
|
@ -272,12 +272,10 @@ class SimplexTableau implements Serializable {
|
|||
private Integer getBasicRow(final int col) {
|
||||
Integer row = null;
|
||||
for (int i = getNumObjectiveFunctions(); i < getHeight(); i++) {
|
||||
if (!MathUtils.equals(getEntry(i, col), 0.0, epsilon)) {
|
||||
if (row == null) {
|
||||
row = i;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if (MathUtils.equals(getEntry(i, col), 1.0, epsilon) && (row == null)) {
|
||||
row = i;
|
||||
} else if (!MathUtils.equals(getEntry(i, col), 0.0, epsilon)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return row;
|
||||
|
|
|
@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
</properties>
|
||||
<body>
|
||||
<release version="2.0" date="TBD" description="TBD">
|
||||
<action dev="luc" type="fix" issue="MATH-273" due-to="Benjamin McCann">
|
||||
Fixed a wrong check for basic variables
|
||||
</action>
|
||||
<action dev="luc" type="fix" issue="MATH-272" due-to="Benjamin McCann">
|
||||
Fixed a problem when setting some variables (several variables were set
|
||||
instead of only one)
|
||||
|
|
|
@ -64,6 +64,18 @@ public class SimplexSolverTest {
|
|||
assertEquals(57.0, solution.getValue(), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleVariableAndConstraint() throws OptimizationException {
|
||||
LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 3 }, 0);
|
||||
Collection<LinearConstraint> constraints = new ArrayList<LinearConstraint>();
|
||||
constraints.add(new LinearConstraint(new double[] { 1 }, Relationship.LEQ, 10));
|
||||
|
||||
SimplexSolver solver = new SimplexSolver();
|
||||
RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, false);
|
||||
assertEquals(10.0, solution.getPoint()[0], 0.0);
|
||||
assertEquals(30.0, solution.getValue(), 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* With no artificial variables needed (no equals and no greater than
|
||||
* constraints) we can go straight to Phase 2.
|
||||
|
|
Loading…
Reference in New Issue