package parameterrules; import java.io.*; import java.lang.Math; import main.BetterTokenizer; import main.GeneralInput; import main.MoreMath; import parameters.ParameterSet; /** Implements the rule that the "SmallerParameter" must be less than the "LargerParameter". */ public class LessThanRule extends ParameterRule { /** The number of the parameter whose value must be smaller. */ private int smallerParam = -1, /** The number of the parameter whose value must be larger. */ largerParam = -1; LessThanRule() {} public ParameterRule copy() { LessThanRule pr = (LessThanRule)super.copy(); return pr; } public float getFuzzyScore(float [] params) { float rval = 1f; float lval = 0f; if(params[smallerParam] < params[largerParam]) return 0f; else return params[smallerParam] - params[largerParam] + 0.00000001f; } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("Param")) { System.out.println("BoundaryRule ignoring inappropriate parameter specification"); } else if(info.equals("SmallerParameter")) { GeneralInput.nextToken(tokenizer); smallerParam = refParams.getPosition(tokenizer.sval); } else if(info.equals("LargerParameter")) { GeneralInput.nextToken(tokenizer); largerParam = refParams.getPosition(tokenizer.sval); } else super.loadParameter(info, tokenizer); } public boolean changeParameters(float [] params, int mode, ParameterSet set) { float val = 1f; // First check if its already good. If so, return true if(getFuzzyScore(params) <= 0) return true; // Not already good, so randomly pick one value to change if(MoreMath.random() < 0.5) // Change lower one pickNewParameterValue(params, smallerParam, set.getLowerBound(smallerParam), params[largerParam], mode, set); else pickNewParameterValue(params, largerParam, params[smallerParam], set.getUpperBound(largerParam), mode, set); return false; } }