Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 33913 invoked from network); 25 Aug 2009 18:07:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 25 Aug 2009 18:07:11 -0000 Received: (qmail 46315 invoked by uid 500); 25 Aug 2009 18:07:36 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 46223 invoked by uid 500); 25 Aug 2009 18:07:36 -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 46214 invoked by uid 99); 25 Aug 2009 18:07:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Aug 2009 18:07:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Tue, 25 Aug 2009 18:07:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7070023888E6; Tue, 25 Aug 2009 18:07:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r807738 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java site/xdoc/changes.xml test/java/org/apache/commons/math/optimization/linear/SimplexSolverTest.java Date: Tue, 25 Aug 2009 18:07:14 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090825180714.7070023888E6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Tue Aug 25 18:07:13 2009 New Revision: 807738 URL: http://svn.apache.org/viewvc?rev=807738&view=rev Log: fixed an error induced by zero entries in simplex solver JIRA: MATH-288 Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.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/SimplexSolver.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java?rev=807738&r1=807737&r2=807738&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/linear/SimplexSolver.java Tue Aug 25 18:07:13 2009 @@ -77,9 +77,10 @@ double minRatio = Double.MAX_VALUE; Integer minRatioPos = null; for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getHeight(); i++) { - double rhs = tableau.getEntry(i, tableau.getWidth() - 1); - if (MathUtils.compareTo(tableau.getEntry(i, col), 0, epsilon) >= 0) { - double ratio = rhs / tableau.getEntry(i, col); + final double rhs = tableau.getEntry(i, tableau.getWidth() - 1); + final double entry = tableau.getEntry(i, col); + if (MathUtils.compareTo(entry, 0, epsilon) > 0) { + final double ratio = rhs / entry; if (ratio < minRatio) { minRatio = ratio; minRatioPos = i; 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=807738&r1=807737&r2=807738&view=diff ============================================================================== --- commons/proper/math/trunk/src/site/xdoc/changes.xml (original) +++ commons/proper/math/trunk/src/site/xdoc/changes.xml Tue Aug 25 18:07:13 2009 @@ -39,6 +39,9 @@ + + Fixed an error induced by entries set to 0 + Fixed an error leading the simplex solver to compute the right solution but return another one 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=807738&r1=807737&r2=807738&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 Tue Aug 25 18:07:13 2009 @@ -57,7 +57,22 @@ RealPointValuePair solution = new SimplexSolver().optimize(f, constraints, GoalType.MAXIMIZE, true); assertEquals(6.9, solution.getValue(), .0000001); } - + + @Test + public void testMath288() throws OptimizationException { + LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 7, 3, 0, 0 }, 0 ); + Collection constraints = new ArrayList(); + constraints.add(new LinearConstraint(new double[] { 3, 0, -5, 0 }, Relationship.LEQ, 0.0)); + constraints.add(new LinearConstraint(new double[] { 2, 0, 0, -5 }, Relationship.LEQ, 0.0)); + constraints.add(new LinearConstraint(new double[] { 0, 3, 0, -5 }, Relationship.LEQ, 0.0)); + constraints.add(new LinearConstraint(new double[] { 1, 0, 0, 0 }, Relationship.LEQ, 1.0)); + constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 0 }, Relationship.LEQ, 1.0)); + + SimplexSolver solver = new SimplexSolver(); + RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MAXIMIZE, true); + assertEquals(10.0, solution.getValue(), .0000001); + } + @Test public void testSimplexSolver() throws OptimizationException { LinearObjectiveFunction f =