You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/06/03 11:06:08 UTC
svn commit: r781304 - in /commons/proper/math/trunk/src:
java/org/apache/commons/math/optimization/linear/SimplexTableau.java
site/xdoc/changes.xml
test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
Author: luc
Date: Wed Jun 3 09:06:08 2009
New Revision: 781304
URL: http://svn.apache.org/viewvc?rev=781304&view=rev
Log:
Fixed a wrong check for basic variables
JIRA: MATH-273
Modified:
commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
commons/proper/math/trunk/src/site/xdoc/changes.xml
commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java?rev=781304&r1=781303&r2=781304&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java Wed Jun 3 09:06:08 2009
@@ -272,12 +272,10 @@
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;
Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=781304&r1=781303&r2=781304&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Wed Jun 3 09:06:08 2009
@@ -39,6 +39,9 @@
</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)
Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java?rev=781304&r1=781303&r2=781304&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java Wed Jun 3 09:06:08 2009
@@ -64,6 +64,18 @@
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.