package stoppers; import java.lang.*; import java.io.*; import main.BetterTokenizer; import main.Cell; import main.GeneralInput; import main.Model; import main.Node; public class MultiNodeThresholdStop extends SimpleStop { String [] nodes = new String[5]; int [] nodeNums = new int[5]; int numNodes = 0; float [] thresholds = new float[5]; float epsilon, interval; public final static int HIGH = 1, LOW = 2; int mode = HIGH; // No arg constructor for instantiating by name public MultiNodeThresholdStop() { this(1); } public MultiNodeThresholdStop(float stop_time) { stopTime = stop_time; } public void init(Model model) { super.init(model); } public boolean stop(float time) { boolean done = true; int cell, node; float val, deriv; // trivial reasons to return if(time < lastTime + interval) return false; if(time > stopTime) return true; for(cell = 0; cell < model.numCells && done; cell++) { for(node = 0; node < numNodes && done; node++) { if(mode == HIGH && model.cells[cell].getValue(nodeNums[node]) < thresholds[node] - epsilon) done = false; else if(mode == LOW && model.cells[cell].getValue(nodeNums[node]) > thresholds[node] + epsilon) done = false; } } lastTime = time; return done; } public void reset() { super.reset(); } public void clearNodes() { numNodes = 0; } public void addNode(String node_name, float threshold) throws Exception { nodes[numNodes] = node_name; nodeNums[numNodes] = model.cells[0].getNodeNum(node_name); thresholds[numNodes] = threshold; numNodes++; } public void setMode(int mode) { this.mode = mode; } public void setEpsilon(float epsilon) { this.epsilon = epsilon; } public void setInterval(float interval) { this.interval = interval; } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("Node")) { GeneralInput.nextToken(tokenizer); String node_name = tokenizer.sval; GeneralInput.nextToken(tokenizer); float thresh = (float)tokenizer.nval; addNode(node_name, thresh); } else if(info.equals("Epsilon")) { GeneralInput.nextToken(tokenizer); epsilon = ((float)tokenizer.nval); } else if(info.equals("Mode")) { GeneralInput.nextToken(tokenizer); if(tokenizer.sval.equals("High")) mode = HIGH; else mode = LOW; } else if(info.equals("Interval")) { GeneralInput.nextToken(tokenizer); interval = ((float)tokenizer.nval); } else super.loadParameter(info,tokenizer); } }