simplex - package mit16_410_13; import...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
package mit16_410_13; import java.util.LinkedList; import java.io.PrintStream; class KpBmax { int kp; double bmax; KpBmax(int kp, double bmax) { this.kp=kp; this.bmax=bmax; } } class Constraint { double value; LinkedList vars; String slack; Constraint (double value, LinkedList vars, String slack) { this.value=value; this.vars=vars; if (slack!=null) this.slack=slack.intern(); } Constraint (double value, LinkedList vars) { this.value=value; this.vars=vars; this.slack=null; } } public class Simplex { boolean solved; String objectivevariable; int varindex; LinkedList variables; LinkedList slackvars; LinkedList m1; LinkedList m2; LinkedList m3; Constraint ofun; int [] izrov, iposv; int N, M, NM1M2; double [][]a; long startTime; long stopTime; public Simplex () { solved=false; varindex=0; ofun=null; startTime=0; stopTime=0; objectivevariable=null; variables=new LinkedList(); slackvars=new LinkedList(); m1=new LinkedList(); m2=new LinkedList(); m3=new LinkedList(); } public void addConstraint (String inequality, double value, LinkedList vars, String slack)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
if (slack!=null) { slack=slack.intern(); slackvars.add(slack); } if (inequality.equals("<=")) { //M1 maybeAddVariables(vars); m1.add(new Constraint(value, vars, slack)); } else if (inequality.equals(">=")) { //M2 maybeAddVariables(vars); m2.add(new Constraint(value, vars, slack)); } else if (inequality.equals("=")) { //M3 if (slack!=null) System.out.println("Unnecessary slack variable specified in equality constraint - ignored"); maybeAddVariables(vars); m3.add(new Constraint(value, vars)); } else System.out.println("Bad inequality in constraint."); } public void addConstraint (String inequality, double value, LinkedList vars) { maybeAddVariables(vars); addConstraint(inequality, value, vars, null); } public void addObjectiveFunction (String name, LinkedList vars) { objectivevariable=name; maybeAddVariables(vars); ofun=new Constraint(0.0, vars); } public void describeProblem (PrintStream out) { if (ofun==null) out.println("WARNING: No Objective Function"); out.print("Objective Function: "); if (ofun!=null) { out.print(objectivevariable); out.print(" = "); printCoefVars(out, ofun.vars, false); out.println(""); } out.println("Constraints:"); // Print M1 for (int i=0; i<m1.size(); i++) { Constraint c=(Constraint)m1.get(i); printCoefVars(out, c.vars, false); out.print(" <= "); out.println(c.value); } // Print M2 for (int i=0; i<m2.size(); i++) { Constraint c=(Constraint)m2.get(i); printCoefVars(out, c.vars, false); out.print(" >= "); out.println(c.value);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

simplex - package mit16_410_13; import...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online