import mit16_410_13.*; import java.util.LinkedList; public class ProblemSet4 { public static void main (String [] args) throws Exception { { System.out.println("\nProblem set 4 Problem 1"); Simplex problem=new Simplex(); LinkedList ofl=new LinkedList(); ofl.add(new Variable("x1", 1)); ofl.add(new Variable("x2", 2)); problem.addObjectiveFunction("z", ofl); LinkedList c1l=new LinkedList(); c1l.add(new Variable("x1", 1)); c1l.add(new Variable("x2", 3)); problem.addConstraint("<=", 8, c1l, "y1"); LinkedList c2l=new LinkedList(); c2l.add(new Variable("x1", 1)); c2l.add(new Variable("x2", 1)); problem.addConstraint("<=", 4, c2l, "y2"); problem.describeProblem(System.out); try { problem.solveProblem(); System.out.print("\n\nSolved in "); System.out.print(problem.getSolutionTime()/1000.0); System.out.println(" seconds.\n"); problem.printSolution(System.out); } catch (SimplexException e) { System.out.println("Simplex Exception"); } } { System.out.println("\nProblem set 4 Problem 2"); Simplex problem=new Simplex(); LinkedList ofl=new LinkedList(); ofl.add(new Variable("x1", 8)); ofl.add(new Variable("x2", 3)); ofl.add(new Variable("x3", 18)); ofl.add(new Variable("x4", 20)); problem.addObjectiveFunction("z", ofl); LinkedList c1l=new LinkedList(); c1l.add(new Variable("x1", 1)); c1l.add(new Variable("x2", 1)); problem.addConstraint(">=", 8, c1l, "y1"); LinkedList c2l=new LinkedList(); c2l.add(new Variable("x1", 1)); c2l.add(new Variable("x3", -15)); problem.addConstraint("<=", 0, c2l, "y2"); LinkedList c3l=new LinkedList(); c3l.add(new Variable("x2", 1)); c3l.add(new Variable("x4", -10)); problem.addConstraint("<=", 0, c3l, "y3"); LinkedList c4l=new LinkedList(); c4l.add(new Variable("x3", 1)); c4l.add(new Variable("x4", 1)); problem.addConstraint("<=", 1, c4l, "y4"); problem.describeProblem(System.out); try { problem.solveProblem(); System.out.print("\n\nSolved in "); System.out.print(problem.getSolutionTime()/1000.0); System.out.println(" seconds.\n"); problem.printSolution(System.out); } catch (SimplexException e) { System.out.println("Simplex Exception"); } } { System.out.println("\nProblem set 4 Problem 3"); Simplex problem=new Simplex(); LinkedList ofl=new LinkedList(); ofl.add(new Variable("red", 4)); ofl.add(new Variable("green", 2)); ofl.add(new Variable("mixed", 3)); problem.addObjectiveFunction("z", ofl); LinkedList c1l=new LinkedList(); c1l.add(new Variable("red", 1)); problem.addConstraint("<=", 5, c1l); LinkedList c2l=new LinkedList(); c2l.add(new Variable("red", 100)); c2l.add(new Variable("mixed", 50)); problem.addConstraint("<=", 800, c2l); LinkedList c3l=new LinkedList(); c3l.add(new Variable("green", 100)); c3l.add(new Variable("mixed", 50)); problem.addConstraint("<=", 600, c3l); problem.describeProblem(System.out); try { problem.solveProblem(); System.out.print("\n\nSolved in "); System.out.print(problem.getSolutionTime()/1000.0); System.out.println(" seconds.\n"); problem.printSolution(System.out); } catch (SimplexException e) { System.out.println("Simplex Exception"); } } { System.out.println("\nProblem set 4 Problem 4"); Simplex problem=new Simplex(); LinkedList ofl=new LinkedList(); ofl.add(new Variable("x1", 3)); ofl.add(new Variable("x2", 2)); problem.addObjectiveFunction("z", ofl); LinkedList c1l=new LinkedList(); c1l.add(new Variable("x1", 2)); c1l.add(new Variable("x2", 1)); problem.addConstraint(">=", 10, c1l, "y1"); LinkedList c2l=new LinkedList(); c2l.add(new Variable("x1", -3)); c2l.add(new Variable("x2", 2)); problem.addConstraint("<=", 6, c2l, "y2"); LinkedList c3l=new LinkedList(); c3l.add(new Variable("x1", 1)); c3l.add(new Variable("x2", 1)); problem.addConstraint(">=", 6, c3l, "y3"); problem.describeProblem(System.out); try { problem.solveProblem(); System.out.print("\n\nSolved in "); System.out.print(problem.getSolutionTime()/1000.0); System.out.println(" seconds.\n"); problem.printSolution(System.out); } catch (SimplexException e) { System.out.println("Simplex Exception"); } } } }