commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Raghu Rangarajan (JIRA)" <j...@apache.org>
Subject [jira] [Created] (MATH-813) SimplexSolver bug?
Date Tue, 10 Jul 2012 14:58:34 GMT
Raghu Rangarajan created MATH-813:
-------------------------------------

             Summary: SimplexSolver bug?
                 Key: MATH-813
                 URL: https://issues.apache.org/jira/browse/MATH-813
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 3.0
         Environment: Windows 7, JDK 1.7.0_03
            Reporter: Raghu Rangarajan


I am trying to use the SimplexSolver in commons-math3-3.0 and am getting unpredictable results.
I am pasting the problem code below. Basically swapping the sequence of the last two constraints
results in two different results (of which one is pure sub-optimal). Am I not using the solver
correctly?

------------------------------
import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.math3.optimization.*;
import org.apache.commons.math3.optimization.linear.*;

public class Commons_Solver {
  public static void main(String[] args) {

 // describe the optimization problem
    
    LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 1, 1, 1, 1, 1,
1, 0, 0 }, 0);
    Collection <LinearConstraint>constraints = new ArrayList<LinearConstraint>();
    
    //variables upper bounds
    constraints.add(new LinearConstraint(new double[] { 1, 0, 0, 0, 0, 0, 0, 0 }, Relationship.LEQ,
38));
    constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 0, 0, 0, 0, 0 }, Relationship.LEQ,
34));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 1, 0, 0, 0, 0, 0 }, Relationship.LEQ,
1));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 1, 0, 0, 0, 0 }, Relationship.LEQ,
6));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 1, 0, 0, 0 }, Relationship.LEQ,
17));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 0, 1, 0, 0 }, Relationship.LEQ,
11));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 0, 0, 1, 0 }, Relationship.LEQ,
101));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 0, 0, 0, 1 }, Relationship.LEQ,
1e10));

    //variables lower bounds
    constraints.add(new LinearConstraint(new double[] { 1, 0, 0, 0, 0, 0, 0, 0 }, Relationship.GEQ,
0));
    constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 0, 0, 0, 0, 0 }, Relationship.GEQ,
0));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 1, 0, 0, 0, 0, 0 }, Relationship.GEQ,
0));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 1, 0, 0, 0, 0 }, Relationship.GEQ,
0));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 1, 0, 0, 0 }, Relationship.GEQ,
0));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 0, 1, 0, 0 }, Relationship.GEQ,
0));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 0, 0, 1, 0 }, Relationship.GEQ,
0));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 0, 0, 0, 1 }, Relationship.GEQ,
0));


    constraints.add(new LinearConstraint(new double[] { -1,-1, -1, -1, -1, -1, 1, 0 }, Relationship.EQ,
0));

    constraints.add(new LinearConstraint(new double[] { -1, -1, -1, -1, -1, -1,0 , 1 }, Relationship.EQ,
0));

    constraints.add(new LinearConstraint(new double[] { 1, 0, 0, 0, 0, 0, 0, -0.2841121495327103
 }, Relationship.GEQ, 0));
    constraints.add(new LinearConstraint(new double[] { 0, 1, 0, 0, 0, 0, 0, -0.25420560747663556
 }, Relationship.GEQ, 0));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 1, 0, 0, 0, -0.04485981308411215
}, Relationship.GEQ, 0));
    
    /*---------------
    Swapping the sequence of the below two constraints produces two different results 
    ------------------*/
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 1, 0, 0, -0.12710280373831778
 }, Relationship.GEQ, 0));
    constraints.add(new LinearConstraint(new double[] { 0, 0, 0, 0, 0, 1, 0, -0.08224299065420561
 }, Relationship.GEQ, 0));
    /*------------------*/
    
    PointValuePair solution = new SimplexSolver().optimize(f, constraints, GoalType.MAXIMIZE,
false);

    // get the solution
    for (int i = 0 ; i < solution.getPoint().length; i++)      
      System.out.println("x[" + i + "] = " +  solution.getPoint()[i]);
    
    System.out.println("value = " + solution.getValue());
  }
}
----------------------------------

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message