package iterators; import java.io.*; import main.BetterTokenizer; import java.lang.*; import main.Model; import stoppers.SimpleStop; import main.ModelRunner; import main.GeneralInput; import parameters.ParameterSet; public class Function extends Object { public ModelRunner runner; public Function() { } // no arg constructor for instantiating by name public Function(ModelRunner run) { // initializing constructor this.init(run); } public void init(ModelRunner run) { runner = run; } public Function copy() throws Exception { throw new Exception("copy() not supported in this version of function"); } public void setStopper(SimpleStop stopper) { runner.setStopper(stopper); } public SimpleStop getStopper() { return runner.getStopper(); } /** Called by the iterator when it stops running. The iterator may stop running because it finished or because the user stopped it. This function should be overridden to handle the latter case gracefully. The default behavior is to call runner.stopRun() */ public void stopRun() { if(runner != null) runner.stopRun(); } // this is the default evaluate mode: run the model for a specific // stopping condition and then return the score public void addObject(Model model, BetterTokenizer tokenizer, String eval_type, String class_name) throws Exception {} // override in specific functions /** this is the default evaluate method that just runs this models runner with its native stopper and parameter values defined by pars. The state of pars reflects any parameter changes and the resultant score is returned. */ public float evaluate(ParameterSet pars) throws Exception { pars.setModel(); // temporarily set model parameters runner.doStartRun(); runner.doRun(); return runner.stopper.getScore(); } /** //ELI 7/7/99 Use this method to continue evaluating a function without resetting anything. You should have called evaluate() before using this one. You can call this repeatedly to run a model in short steps and do something inbetween (as long as the stopping condition is set to stop appropriately. The return values are the same as with evaluate. */ public float continueEvaluate(ParameterSet pars) throws Exception { pars.setModel(); // temporarily set model parameters runner.doRun(); return runner.stopper.getScore(); } public void loadParameters(BetterTokenizer tokenizer) throws Exception { GeneralInput.indent++; String info = GeneralInput.findNextIDToken(tokenizer); while(!info.equals("endFunction")) { loadParameter(info, tokenizer); info = GeneralInput.findNextIDToken(tokenizer); } GeneralInput.indent--; } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { // empty } }