public RuleSet(FISOperatorAnd andOperator, FISOperatorOr orOperator, FISImplicator implicator, FISAggregator aggregator, FISDefuzzifier defuzzifier) { _andOp = andOperator; _orOp = orOperator; _implicator = implicator; _aggregator = aggregator; _defuzzifier = defuzzifier; _init(); }
/// <summary> /// Parse the system section of the FIS File /// </summary> /// <param name="sLines"></param> private void parseSystem(List <string> sLines) { FISOperatorAnd andOp = FISOperatorAnd.FISOpAnd_None; FISOperatorOr orOp = FISOperatorOr.FISOpOr_None; FISImplicator imp = FISImplicator.FISImp_None; FISAggregator agg = FISAggregator.FISAgg_None; FISDefuzzifier defuzz = FISDefuzzifier.FISDefuzz_None; foreach (string line in sLines) { string[] sLSplit = line.Split('='); sLSplit[0] = sLSplit[0].ToLower(); switch (sLSplit[0]) { case "numinputs": if (!Int32.TryParse(sLSplit[1], out _numInputs)) { throw new Exception("Invalid number of inputs: " + line); } break; case "numoutputs": if (!Int32.TryParse(sLSplit[1], out _numOutputs)) { throw new Exception("Invalid number of outputs: " + line); } break; case "numrules": if (!Int32.TryParse(sLSplit[1], out _numRules)) { throw new Exception("Invalid number of rules: " + line); } break; case "andmethod": if ("'min'" == sLSplit[1]) { andOp = FISOperatorAnd.FISOpAnd_Min; } else if ("'product'" == sLSplit[1]) { andOp = FISOperatorAnd.FISOpAnd_Product; } else { throw new Exception("Unsupported AndMethod: " + line); } break; case "ormethod": if ("'max'" == sLSplit[1]) { orOp = FISOperatorOr.FISOpOr_Max; } else if ("'probor'" == sLSplit[1]) { orOp = FISOperatorOr.FISOpOr_Probor; } else { throw new Exception("Unsupported OrMethod: " + line); } break; case "impmethod": if ("'min'" == sLSplit[1]) { imp = FISImplicator.FISImp_Min; } else if ("'product'" == sLSplit[1]) { imp = FISImplicator.FISImp_Product; } else { throw new Exception("Unsupported ImplicatorMethod: " + line); } break; case "aggmethod": if ("'max'" == sLSplit[1]) { agg = FISAggregator.FISAgg_Max; } else if ("'probor'" == sLSplit[1]) { agg = FISAggregator.FISAgg_Probor; } else if ("'sum'" == sLSplit[1]) { agg = FISAggregator.FISAgg_Sum; } else { throw new Exception("Unsupported Aggregator Method: " + line); } break; case "defuzzmethod": if ("'centroid'" == sLSplit[1]) { defuzz = FISDefuzzifier.FISDefuzz_Centroid; } else if ("'bisect'" == sLSplit[1]) { defuzz = FISDefuzzifier.FISDefuzz_Bisect; } else if ("'midmax'" == sLSplit[1]) { defuzz = FISDefuzzifier.FISDefuzz_MidMax; } else if ("'largemax'" == sLSplit[1]) { defuzz = FISDefuzzifier.FISDefuzz_LargeMax; } else if ("'smallmax'" == sLSplit[1]) { defuzz = FISDefuzzifier.FISDefuzz_SmallMax; } else { throw new Exception("Unsupported DefuzzMethod: " + line); } break; } } if (andOp == FISOperatorAnd.FISOpAnd_None) { throw new Exception("No AndMethod set."); } else if (orOp == FISOperatorOr.FISOpOr_None) { throw new Exception("No OrMethod set."); } else if (imp == FISImplicator.FISImp_None) { throw new Exception("No ImpMethod set."); } else if (agg == FISAggregator.FISAgg_None) { throw new Exception("No AggMethod set."); } else if (defuzz == FISDefuzzifier.FISDefuzz_None) { throw new Exception("No DefuzzMethod set."); } // Initialize our new ruleset ruleset = new RuleSet(andOp, orOp, imp, agg, defuzz); }