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) {
|
private Integer getBasicRow(final int col) {
|
||||||
Integer row = null;
|
Integer row = null;
|
||||||
for (int i = getNumObjectiveFunctions(); i < getHeight(); i++) {
|
for (int i = getNumObjectiveFunctions(); i < getHeight(); i++) {
|
||||||
if (!MathUtils.equals(getEntry(i, col), 0.0, epsilon)) {
|
if (MathUtils.equals(getEntry(i, col), 1.0, epsilon) && (row == null)) {
|
||||||
if (row == null) {
|
row = i;
|
||||||
row = i;
|
} else if (!MathUtils.equals(getEntry(i, col), 0.0, epsilon)) {
|
||||||
} else {
|
return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return row;
|
return row;
|
||||||
|
|
|
@ -39,6 +39,9 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
</properties>
|
</properties>
|
||||||
<body>
|
<body>
|
||||||
<release version="2.0" date="TBD" description="TBD">
|
<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">
|
<action dev="luc" type="fix" issue="MATH-272" due-to="Benjamin McCann">
|
||||||
Fixed a problem when setting some variables (several variables were set
|
Fixed a problem when setting some variables (several variables were set
|
||||||
instead of only one)
|
instead of only one)
|
||||||
|
|
|
@ -64,6 +64,18 @@ public class SimplexSolverTest {
|
||||||
assertEquals(57.0, solution.getValue(), 0.0);
|
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
|
* With no artificial variables needed (no equals and no greater than
|
||||||
* constraints) we can go straight to Phase 2.
|
* constraints) we can go straight to Phase 2.
|
||||||
|
|
Loading…
Reference in New Issue