Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
3.0
-
None
-
None
-
Windows 7, JDK 1.7.0_03
Description
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[]
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[]
, Relationship.GEQ, 0));
constraints.add(new LinearConstraint(new double[]
, Relationship.GEQ, 0));
constraints.add(new LinearConstraint(new double[]
, Relationship.GEQ, 0));
constraints.add(new LinearConstraint(new double[]
, Relationship.GEQ, 0));
constraints.add(new LinearConstraint(new double[]
, Relationship.GEQ, 0));
constraints.add(new LinearConstraint(new double[]
, Relationship.GEQ, 0));
constraints.add(new LinearConstraint(new double[]
, 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[]
, Relationship.GEQ, 0));
constraints.add(new LinearConstraint(new double[]
, Relationship.GEQ, 0));
/*---------------
Swapping the sequence of the below two constraints produces two different results
------------------*/
constraints.add(new LinearConstraint(new double[]
, Relationship.GEQ, 0));
constraints.add(new LinearConstraint(new double[]
, 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());
}
}
----------------------------------
Attachments
Attachments
Issue Links
- duplicates
-
MATH-781 SimplexSolver gives bad results
- Closed