package parameterrules; import java.io.*; import java.lang.Math; import main.BetterTokenizer; import main.GeneralInput; import parameters.ParameterSet; /** Implements the rule that the "leftSide" must be greater than or less than the ratio of two products of input parameters. */ public class BoundaryRule extends ParameterRule { /** These store the lower and upper bounds that the ratio of the parameters have to be between (inclusive of edges) */ private int leftSideNum; private int [] denomNums = new int[5]; private int numDenoms = 0; private boolean greaterThan = true; BoundaryRule() {} public ParameterRule copy() { BoundaryRule pr = (BoundaryRule)super.copy(); pr.denomNums = new int[numDenoms]; System.arraycopy(denomNums, 0, pr.denomNums, 0, numDenoms); return pr; } public float getFuzzyScore(float [] params) { float rval = 1f; float lval = 0f; for(int i = 0; i < numParams; i++) { rval *= params[paramNums[i]]; } for(int i = 0; i < numDenoms; i++) { rval /= params[denomNums[i]]; } lval = params[leftSideNum]; if(greaterThan) { if(lval >= rval) return 0f; else if((lval < rval) && (lval > rval / 10)) return (float)((Math.log((double)(rval/lval)))/Math.log((double)10)); else if(lval <= rval / 10) return 1.0f; } else { if(lval <= rval) return 0f; else if((lval > rval) && (lval < rval * 10)) return (float)((Math.log((double)(lval/rval)))/Math.log((double)10)); else if(lval >= rval * 10) return 1.0f; } // not the most ideal fuzzy score but it'll do. return 1.0f; // not sure why I need this here, but compiler demands it } 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("LeftSide")) { GeneralInput.nextToken(tokenizer); leftSideNum = refParams.getPosition(tokenizer.sval); } else if(info.equals("Numerator")) { if(numParams == paramNums.length) { // Expand array length int [] temp = new int[paramNums.length + 5]; System.arraycopy(paramNums, 0, temp, 0, numParams); paramNums = temp; } GeneralInput.nextToken(tokenizer); paramNums[numParams] = refParams.getPosition(tokenizer.sval); // Should throw exception if param doesn't exist numParams++; } else if(info.equals("Denominator")) { if(numDenoms == denomNums.length) { // Expand array length int [] temp = new int[denomNums.length + 5]; System.arraycopy(denomNums, 0, temp, 0, numDenoms); denomNums = temp; } GeneralInput.nextToken(tokenizer); denomNums[numDenoms] = refParams.getPosition(tokenizer.sval); // Should throw exception if param doesn't exist numDenoms++; } else if(info.equals("GreaterThan")) { greaterThan = true; } else if(info.equals("LessThan")) { greaterThan = false; } else super.loadParameter(info, tokenizer); } }