package stoppers; import java.lang.*; import java.io.*; import main.BetterTokenizer; import main.Cell; import main.GeneralInput; import main.Model; /** A stopper that measures the maximum ratio between a node's concentration in two different cells over some time. To avoid large ratio's simply do to very small concentrations, the ratio is calculated as (C(1) + epsilon) / (C(2) + epsilon) where epsilon is some small value. @author Eli @version 3/19/99 */ public class FindMaxRatioStop extends SimpleStop { int nodeNum; float interval; int xPos, yPos, xPos2, yPos2; /** A number added to numerator and denominator of ratio to prevent large ratios simply do to small numbers. */ float epsilon; // No arg constructor for instantiating by name public FindMaxRatioStop() { stopTime = 1; } public FindMaxRatioStop(float stop_time) { stopTime = stop_time; } public boolean stop(float time) { // trivial reasons to return if(time < lastTime + interval) return false; if(time > stopTime) return true; float ratio = (model.cells[yPos * model.arrayWidth + xPos].getValue(nodeNum) + epsilon)/ (model.cells[yPos2 * model.arrayWidth + xPos2].getValue(nodeNum) + epsilon); if(ratio > score) score = ratio; else if(1 / ratio > score) score = 1 / ratio; lastTime = time; return false; } public boolean didPass(float s) { return didPass(); } public boolean didPass() { return true; } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("Node")) { GeneralInput.nextToken(tokenizer); nodeNum = model.cells[0].getNodeNum(tokenizer.sval); } else if(info.equals("Epsilon")) { GeneralInput.nextToken(tokenizer); epsilon = ((float)tokenizer.nval); } else if(info.equals("XPos")) { GeneralInput.nextToken(tokenizer); xPos = ((int)tokenizer.nval); } else if(info.equals("YPos")) { GeneralInput.nextToken(tokenizer); yPos = ((int)tokenizer.nval); } else if(info.equals("XPos2")) { GeneralInput.nextToken(tokenizer); xPos2 = ((int)tokenizer.nval); } else if(info.equals("YPos2")) { GeneralInput.nextToken(tokenizer); yPos2 = ((int)tokenizer.nval); } else if(info.equals("Interval")) { GeneralInput.nextToken(tokenizer); interval = (float)tokenizer.nval; } else super.loadParameter(info,tokenizer); } }