Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 17549 invoked from network); 15 Oct 2009 07:43:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Oct 2009 07:43:55 -0000 Received: (qmail 47457 invoked by uid 500); 15 Oct 2009 07:43:54 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 47353 invoked by uid 500); 15 Oct 2009 07:43:54 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 47343 invoked by uid 99); 15 Oct 2009 07:43:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2009 07:43:54 +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.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2009 07:43:52 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 41BA0234C045 for ; Thu, 15 Oct 2009 00:43:31 -0700 (PDT) Message-ID: <466165158.1255592611264.JavaMail.jira@brutus> Date: Thu, 15 Oct 2009 00:43:31 -0700 (PDT) From: "Christian Winter (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (MATH-302) Bugs in Simplex Implementation In-Reply-To: <1307627350.1255528711422.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/MATH-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765952#action_12765952 ] Christian Winter commented on MATH-302: --------------------------------------- Alright. It works with the version from SVN. Thanks. > Bugs in Simplex Implementation > ------------------------------ > > Key: MATH-302 > URL: https://issues.apache.org/jira/browse/MATH-302 > Project: Commons Math > Issue Type: Bug > Affects Versions: 2.0 > Reporter: Christian Winter > > Simplex routine may return infeasible solution: > {code:title=Bug1.java|borderstyle=solid} > import java.util.ArrayList; > import org.apache.commons.math.linear.ArrayRealVector; > import org.apache.commons.math.optimization.GoalType; > import org.apache.commons.math.optimization.OptimizationException; > import org.apache.commons.math.optimization.linear.*; > public class Bug1 { > > public static void main(String[] args) throws OptimizationException { > > LinearObjectiveFunction c = new LinearObjectiveFunction(new double[7], 0.0d); > > ArrayList cnsts = new ArrayList(5); > LinearConstraint cnst; > cnst = new LinearConstraint(new double[] {1.00d, 1.00d, 0.00d, 0.00d, 0.0d, 0.00d, 0.00d}, Relationship.EQ, 1.0d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.00d, 0.00d, 1.00d, 1.00d, 1.0d, 0.00d, 0.00d}, Relationship.EQ, 1.0d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.00d, 0.00d, 0.00d, 0.00d, 0.0d, 1.00d, 1.00d}, Relationship.EQ, 1.0d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.54d, 0.00d, 0.34d, 0.00d, 0.0d, 0.12d, 0.00d}, Relationship.EQ, 0.54d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.00d, 0.54d, 0.00d, 0.34d, 0.0d, 0.00d, 0.12d}, Relationship.EQ, 0.34d); > cnsts.add(cnst); > System.out.println("Constraints:"); > for(LinearConstraint con : cnsts) { > System.out.println(con.getCoefficients().toString() + " " + con.getRelationship() + " " + con.getValue()); > } > > SimplexSolver simplex = new SimplexSolver(); > double[] sol = simplex.optimize(c, cnsts, GoalType.MINIMIZE, true).getPointRef(); > System.out.println("Solution:\n" + new ArrayRealVector(sol)); > System.out.println("Third constraint is violated!"); > } > } > {code} > or may find no solution where some exist: > {code:title=Bug1.java|borderstyle=solid} > import java.util.ArrayList; > import org.apache.commons.math.linear.ArrayRealVector; > import org.apache.commons.math.optimization.GoalType; > import org.apache.commons.math.optimization.OptimizationException; > import org.apache.commons.math.optimization.linear.*; > public class Bug2 { > > public static void main(String[] args) throws OptimizationException { > > LinearObjectiveFunction c = new LinearObjectiveFunction(new double[13], 0.0d); > > ArrayList cnsts = new ArrayList(5); > LinearConstraint cnst; > cnst = new LinearConstraint(new double[] {1.00d, 1.00d, 1.0d, 0.00d, 0.00d, 0.00d, 0.0d, 0.0d, 0.0d, 0.0d, 0.00d, 0.00d, 0.0d}, Relationship.EQ, 1.0d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.00d, 0.00d, 0.0d, 1.00d, 1.00d, 1.00d, 1.0d, 0.0d, 0.0d, 0.0d, 0.00d, 0.00d, 0.0d}, Relationship.EQ, 1.0d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.00d, 0.00d, 0.0d, 0.00d, 0.00d, 0.00d, 0.0d, 1.0d, 1.0d, 1.0d, 0.00d, 0.00d, 0.0d}, Relationship.EQ, 1.0d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.00d, 0.00d, 0.0d, 0.00d, 0.00d, 0.00d, 0.0d, 0.0d, 0.0d, 0.0d, 1.00d, 1.00d, 1.0d}, Relationship.EQ, 1.0d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.54d, 0.00d, 0.0d, 0.32d, 0.00d, 0.00d, 0.0d, 0.1d, 0.0d, 0.0d, 0.02d, 0.00d, 0.0d}, Relationship.EQ, 0.54d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.00d, 0.54d, 0.0d, 0.00d, 0.32d, 0.00d, 0.0d, 0.0d, 0.1d, 0.0d, 0.00d, 0.02d, 0.0d}, Relationship.EQ, 0.32d); > cnsts.add(cnst); > cnst = new LinearConstraint(new double[] {0.00d, 0.00d, 0.0d, 0.00d, 0.00d, 0.32d, 0.0d, 0.0d, 0.0d, 0.0d, 0.00d, 0.00d, 0.0d}, Relationship.EQ, 0.1d); > cnsts.add(cnst); > System.out.println("Constraints:"); > for(LinearConstraint con : cnsts) { > System.out.println(con.getCoefficients().toString() + " " + con.getRelationship() + " " + con.getValue()); > } > > System.out.println("verifying a known solution:"); > ArrayRealVector sol = new ArrayRealVector(new double[] {4.0d/9.0d, 5.0d/9.0d, 0.0d, 11.0d/16.0d, 0.0d, 5.0d/16.0d, 0.0d, 4.0d/5.0d, 0.0d, 1.0d/5.0d, 0.0d, 1.0d, 0.0d}); > System.out.println("sol = " + sol); > for(LinearConstraint con : cnsts) { > System.out.println(sol.dotProduct(con.getCoefficients()) + " = " + con.getValue()); > } > > SimplexSolver simplex = new SimplexSolver(); > double[] newsol = simplex.optimize(c, cnsts, GoalType.MINIMIZE, true).getPointRef(); > System.out.println("Solution:\n" + new ArrayRealVector(newsol)); > } > } > {code} -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.