# SimplexSolver bug?

XMLWordPrintableJSON

#### Details

• Type: Bug
• Status: Closed
• Priority: Major
• Resolution: Duplicate
• Affects Version/s: 3.0
• Fix Version/s:
• Labels:
None
• Environment:

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

{ 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));

{ 0, 1, 0, 0, 0, 0, 0, 0 }

, Relationship.GEQ, 0));

{ 0, 0, 1, 0, 0, 0, 0, 0 }

, Relationship.GEQ, 0));

{ 0, 0, 0, 1, 0, 0, 0, 0 }

, Relationship.GEQ, 0));

{ 0, 0, 0, 0, 1, 0, 0, 0 }

, Relationship.GEQ, 0));

{ 0, 0, 0, 0, 0, 1, 0, 0 }

, Relationship.GEQ, 0));

{ 0, 0, 0, 0, 0, 0, 1, 0 }

, Relationship.GEQ, 0));

{ 0, 0, 0, 0, 0, 0, 0, 1 }

, Relationship.GEQ, 0));

{ -1,-1, -1, -1, -1, -1, 1, 0 }

, Relationship.EQ, 0));

{ -1, -1, -1, -1, -1, -1,0 , 1 }

, Relationship.EQ, 0));

{ 1, 0, 0, 0, 0, 0, 0, -0.2841121495327103 }

, Relationship.GEQ, 0));

{ 0, 1, 0, 0, 0, 0, 0, -0.25420560747663556 }

, Relationship.GEQ, 0));

{ 0, 0, 0, 1, 0, 0, 0, -0.04485981308411215 }

, Relationship.GEQ, 0));

/*---------------
Swapping the sequence of the below two constraints produces two different results
------------------*/

{ 0, 0, 0, 0, 1, 0, 0, -0.12710280373831778 }

, Relationship.GEQ, 0));

{ 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());
}
}
----------------------------------

#### Attachments

1. Commons_Solver.java
4 kB
Raghu Rangarajan

#### People

• Assignee:
Unassigned
Reporter:
Raghu Rangarajan