package stoppers; import java.lang.*; import java.io.*; import main.BetterTokenizer; import java.math.*; import main.Cell; import main.GeneralInput; import main.Model; public class FPStripeStop extends SimpleStop { int stripeWidth, nonStripeWidth; String node; int fpos= -1, lpos= -1; // left and right bounds of stripe, matches array index boolean done=false; // stripe parameters float sMin=0.5f; // higher is better float sFloor = 0.1f; float [] stripeMeans; boolean evaluating = false; float howStable = 0f; // No arg constructor for instantiating by name public FPStripeStop() { stopTime = 1; } public void init(Model model) { super.init(model); stripeMeans = new float[model.arrayWidth]; } public void loadParameters(BetterTokenizer tokenizer) throws Exception { super.loadParameters(tokenizer); if((lpos < 0) || (fpos < 0) || (lpos >= model.arrayWidth) || (fpos >= model.arrayWidth) || (lpos - fpos < 0) || ((lpos - fpos) == (model.arrayWidth - 1))) throw new Exception("Error in StripeStop: Stripe not properly specified"); stripeWidth = (lpos - fpos + 1); nonStripeWidth = model.arrayWidth - stripeWidth; } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("Node")) { GeneralInput.nextToken(tokenizer); node = tokenizer.sval; } else if(info.equals("LeftStripeBorder")) { GeneralInput.nextToken(tokenizer); fpos = ((int)tokenizer.nval-1); } // subtract 1 to make pos an array index else if(info.equals("RightStripeBorder")) { GeneralInput.nextToken(tokenizer); lpos = ((int)tokenizer.nval-1); } // subtract 1 to make pos an array index else if(info.equals("StripeThreshold")) { GeneralInput.nextToken(tokenizer); sMin = (float)tokenizer.nval; } else if(info.equals("StripeFloor")) { GeneralInput.nextToken(tokenizer); sMin = (float)tokenizer.nval; } else super.loadParameter(info,tokenizer); } public void setEvaluating(boolean emode) { if(emode == true) { howStable = 0f; evaluating = true; } else evaluating = emode; } public boolean stop(float time) { if(time > stopTime) { score = computeStripeScore(); return done=true; } else return false; } public float getHowStable() { return howStable; } public float computeStripeScore() { float instripe=0, exstripe=0; float lastScore; for(int i = 0; i < model.arrayWidth; i++) stripeMeans[i] = 0; for(int i = 0; i< model.arrayHeight; i++) { int pos = i*model.arrayWidth; for(int j = 0; j < model.arrayWidth; j++) stripeMeans[j] += model.cells[pos + j].nodePeek(node); } for(int j = 0; j < fpos; j++) exstripe += stripeMeans[j]; for(int j = fpos; j <= lpos; j++) instripe += stripeMeans[j]; for(int j = lpos + 1; j < model.arrayWidth; j++) exstripe += stripeMeans[j]; instripe = instripe/stripeWidth; exstripe = exstripe/nonStripeWidth; lastScore = score; score = (1/(1 + sMin))/sFloor - (instripe/(sMin + instripe))/(sFloor + exstripe); if(evaluating) { lastScore -= score; howStable += lastScore*lastScore; // add up SQR(score(t+1) - score) } return score; } public void initCells() { for(int col = fpos; col <= lpos; col++) { for(int row = 0; row < model.arrayHeight; row++) { try { model.cells[row * model.arrayWidth + col].setValue(node, 1f); // set each column full on } catch(Exception e) { System.out.println(e.toString()); } } } } }