Lab 9: Simplex method part 2
Professor: Ronaldo Menezes
TA: Ivan Bogun
Department of Computer Science
Florida Institute of Technology
March 11, 2014
CSE 2010 Algorithms and Data Structures
Spring 2014
1 Problem statement
1.1 Legend
In this lab you are asked to finalize your implementation of the Simplex method. Consult
handout for the algorithm details.
2 Implementation
Implement the class SimplexSolution.java which will be used as a solution data structure.
// SimplexSolution.java
public class SimplexSolution{
private double[] x;
private double objective;
public SimplexSolution(double[] x_,double objective_) {
this.x=x_;
this.objective=objective_;
}
public String toString(){
// return String representation of the solution and objective value
}
}
Implement the class Simplex.java.
// Simplex.java
public class Simplex {
private LinearProgram lp;
public Simplex(LinearProgram lp_) {
// constructor. Linear program to be passed in this constructor is
assumed to be in a standard form already.
}
public SimplexSolution solveSimplex(boolean debug) {
// implement simplex method here. ’debug’ is a boolean flag which, if
true, should output intermediate steps of the solution
// See Output section for details. If debug is false nothing should be
printed.
}
}
1
CSE 2010 Algorithms and Data Structures
Spring 2014
You have to submit the following files: Simplex.java, SimplexSolution.java,
Objective.java, Constraint.java, LinearProgram.java
3 Sample input-output
Use the following main for testing.
3.1 Input
public static void main(String[] args) {
// TODO Auto-generated method stub
String s1 = "-1 1 <= 11";
String s2 = "1 1 <= 27";
String s3 = "2 5 <= 90";
int nVars = 2;
LinearProgram lp = new LinearProgram(nVars);
String o = "max. 4 6";
lp.addObjective(o);
lp.addConstraint(s1);
lp.addConstraint(s2);
lp.addConstraint(s3);
// System.out.println(lp.toString() + "\n\n\n");
lp.convertToStandardForm();
System.out.println(lp.toString());
Simplex simplex = new Simplex(lp);
SimplexSolution solution=simplex.solveSimplex(true);
System.out.println(solution.toString());
System.out.println("\nWithout debugging output \n");
solution=simplex.solveSimplex(false);
System.out.println(solution.toString());
}
3.2 Output
max. 4.0x_1+6.0x_2
s.t. -1.0x_1+1.0x_2+1.0x_3+0.0x_4+0.0x_5=11.0
1.0x_1+1.0x_2+0.0x_3+1.0x_4+0.0x_5=27.0
2.0x_1+5.0x_2+0.0x_3+0.0x_4+1.0x_5=90.0
2
CSE 2010 Algorithms and Data Structures
Iteration #1 simplex tableau
-1.0
1.0
1.0
0.0
0.0
1.0
1.0
0.0
1.0
0.0
2.0
5.0
0.0
0.0
1.0
-4.0
-6.0
0.0
0.0
0.0
Spring 2014
11.0
27.0
90.0
0.0
Basic variables:
2 3 4
Solution to linear system:
[0, 0, 11.0, 27.0, 90.0]
Entering: 1, departing: 2
Iteration #2 simplex tableau
-1.0
1.0
1.0
0.0
0.0
2.0
0.0
-1.0
1.0
0.0
7.0
0.0
-5.0
0.0
1.0
-10.0 0.0
6.0
0.0
0.0
11.0
16.0
35.0
66.0
Basic variables:
1 3 4
Solution to linear system:
[0, 11.0, 0, 16.0, 35.0]
Entering: 0, departing: 4
Iteration #3 simplex tableau
0.0
1.0
0.2857142857142857 0.0
0.0
0.0
0.4285714285714286 1.0
1.0
0.0
-0.7142857142857143 0.0
0.0
0.0
-1.1428571428571432 0.0
0.14285714285714285 16.0
-0.2857142857142857 6.0
0.14285714285714285 5.0
1.4285714285714284 116.0
Basic variables:
1 3 0
Solution to linear system:
[5.0, 16.0, 0, 6.0, 0]
Entering: 2, departing: 3
Iteration #4 simplex tableau
0.0
1.0
0.0
-0.6666666666666665 0.3333333333333333 12.0
0.0
0.0
1.0
2.333333333333333 -0.6666666666666666 13.999999999999998
1.0
0.0
0.0
1.6666666666666665 -0.3333333333333333 14.999999999999998
0.0
0.0
0.0
2.6666666666666674 0.6666666666666663 132.0
3
CSE 2010 Algorithms and Data Structures
Spring 2014
Basic variables:
1 2 0
Solution to linear system:
[14.999999999999998, 12.0, 13.999999999999998, 0, 0]
Objective: 132.0
Solution: [14.999999999999998, 12.0, 13.999999999999998, 0.0, 0.0]
Without debugging output
Objective: 132.0
Solution: [14.999999999999998, 12.0, 13.999999999999998, 0.0, 0.0]
4 Grade breakdown
basis
Implementation
Simplex
Comments
General
Javadocs
Overall
Compiled
Style
Runtime
Total
4
grade
(60)
60
(20)
10
10
(20)
5
5
10
100
© Copyright 2026 Paperzz