package iterators; import java.io.*; import main.BetterTokenizer; import java.lang.*; import main.Model; import main.Cell; import affectors.Affector; import parameters.ParameterSet; import stoppers.NoChangeStop; public class RandInitRunIterator extends ModelIterator implements Runnable { float minVal, maxVal; int [] nodes = new int[5]; float [] nodeRanges = new float[10]; int numNodes; int delay; public RandInitRunIterator() { setPrint(true); } // Have a no argument initializer so we can do new_by_name public ModelIterator copy() throws Exception { RandInitRunIterator newIter = new RandInitRunIterator(); newIter.init(this.network, this.model); newIter.nParsTV = this.nParsTV; newIter.parsTV = this.parsTV.copy(); newIter.theFunction = this.theFunction.copy(); newIter.minVal = minVal; newIter.maxVal = maxVal; return newIter; } public void loadParameters(BetterTokenizer tokenizer) throws Exception { super.loadParameters(tokenizer); // The grunt work is done by parent class // This is initialization stuff we need to do after figuring out how many // parameters will be varied. } // Put any parameters specific to this iterator class in here, as if clauses. protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("Node")) { if(numNodes == nodes.length) { int [] tempnodes = new int[numNodes + 5]; System.arraycopy(nodes, 0, tempnodes, 0, numNodes); nodes = tempnodes; float [] tempnoderanges = new float[numNodes * 2 + 10]; System.arraycopy(nodeRanges, 0, tempnoderanges, 0, numNodes * 2); nodeRanges = tempnoderanges; } tokenizer.nextToken(); nodes[numNodes] = cells[0].getNodeNum(tokenizer.sval); tokenizer.nextToken(); nodeRanges[numNodes * 2] = (float)tokenizer.nval; tokenizer.nextToken(); nodeRanges[numNodes * 2 + 1] = (float)tokenizer.nval; numNodes++; } else if(info.equals("DelayOnEnd")) { tokenizer.nextToken(); delay = (int)tokenizer.nval; } else super.loadParameter(info, tokenizer); } public void doRun() { int x, y, i; Cell cell; float [] ststPts = new float[20 * 4]; int [] numPtsFound = new int[20]; int numPts = 0; reset(); numPts = 0; for(x = 0; x < Cell.arrayWidth; x++) { for(y = 0; y < Cell.arrayHeight; y++) { for(int n = 0; n < numNodes; n++) { cell = cells[y * Cell.arrayWidth + x]; cell.setInitialValue(nodes[n], (float)Math.random() * (nodeRanges[n*2+1] - nodeRanges[n*2]) + nodeRanges[n*2]); } } } finalScore = F(p); if(delay > 0) try { Thread.sleep(delay); } catch(InterruptedException e) {} super.stopRun(); } }