Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9636995E1 for ; Mon, 28 Nov 2011 20:16:52 +0000 (UTC) Received: (qmail 80724 invoked by uid 500); 28 Nov 2011 20:16:52 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 80647 invoked by uid 500); 28 Nov 2011 20:16:52 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 80640 invoked by uid 99); 28 Nov 2011 20:16:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Nov 2011 20:16:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Nov 2011 20:16:51 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9D16823889FA for ; Mon, 28 Nov 2011 20:16:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1207566 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java site/xdoc/changes.xml test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java Date: Mon, 28 Nov 2011 20:16:30 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111128201630.9D16823889FA@eris.apache.org> Author: luc Date: Mon Nov 28 20:16:28 2011 New Revision: 1207566 URL: http://svn.apache.org/viewvc?rev=1207566&view=rev Log: Fixed case of unconstrained variables that still occur in the objective function in simplex solver. Patch provided by Thomas Neidhart Jira: MATH-713 Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java commons/proper/math/trunk/src/site/xdoc/changes.xml commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java?rev=1207566&r1=1207565&r2=1207566&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexTableau.java Mon Nov 28 20:16:28 2011 @@ -407,7 +407,12 @@ class SimplexTableau implements Serializ 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); 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=1207566&r1=1207565&r2=1207566&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Nov 28 20:16:28 2011 @@ -52,6 +52,10 @@ The type attribute can be add,u If the output is not quite correct, check for invisible trailing spaces! --> + + Fixed case of unconstrained variables that still occur in the objective function + in simplex solver. + The fast cryptographically secure pseudorandom number generator ISAAC has been added. Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java?rev=1207566&r1=1207565&r2=1207566&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java Mon Nov 28 20:16:28 2011 @@ -30,6 +30,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 constraints = new ArrayList(); + 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); ArrayList constraints = new ArrayList();