public Rule[] Infer(FuzzifiedValueContainer fuzzyContainer) { Rule[] result = new Rule[m_RuleBase.RuleCount()]; m_RuleBase.ResetFulfillmentValues(); for (int i = 0; i < m_RuleBase.RuleCount(); i++) { Rule currentRule = m_RuleBase.GetRule(i); for (int j = 0; j < currentRule.ConditionCount(); j++) { RuleCondition currentCondition = currentRule.GetCondition(j); FuzzifiedValue fuzzyVal = null; if ((fuzzyVal = fuzzyContainer.Get(currentCondition.VariableName, currentCondition.TermName)) != null) { currentCondition.Fulfillment = fuzzyVal.FuzzyValue; } else { LogWriter.Write("Error in rule " + i + " condition " + j); } } currentRule.CalculateConclusionFulfillments(); result[i] = currentRule; } return(result); }
public static void MakeReady(RuleBase ruleBase) { ruleBase.m_Rules.Clear(); string line; char[] separator = { ' ', '\t', '\n' }; string[] tokens; string[] s = Rules.GetRules(); for (int i = 0; i < s.Length; i++) { line = s[i].Trim(); if (line.Length > 0 && line[0] != ';') { Rule rule = new Rule(); tokens = line.Split(separator); int idx = 0; while (!tokens[idx].Equals("then")) { RuleCondition ruleCondition = new RuleCondition(tokens[idx + 1], tokens[idx + 3]); rule.AddCondition(ruleCondition); idx += 4; } RuleConclusion ruleConclusion = new RuleConclusion(tokens[idx + 2]); rule.SetConclusion(ruleConclusion); ruleBase.AddRule(rule); } } }
public void AddCondition( RuleCondition condition ) { for ( int i = 0; i < ConditionCount(); i++ ) { if ( condition.Equals( GetCondition( i ) ) ) return; } m_Conditions.Add( condition ); }
public void AddCondition(RuleCondition condition) { for (int i = 0; i < ConditionCount(); i++) { if (condition.Equals(GetCondition(i))) { return; } } m_Conditions.Add(condition); }
public override bool Equals(object obj) { RuleCondition r = ( RuleCondition )obj; if (this.VariableName.Equals(r.VariableName) && this.TermName.Equals(r.TermName)) { return(true); } else { return(false); } }
public static void MakeReady( RuleBase ruleBase ) { ruleBase.m_Rules.Clear(); string line; char[] separator = {' ', '\t', '\n'}; string[] tokens; string[] s = Rules.GetRules(); for ( int i = 0; i < s.Length; i++ ) { line = s[i].Trim(); if ( line.Length > 0 && line[0] != ';' ) { Rule rule = new Rule(); tokens = line.Split( separator ); int idx = 0; while ( !tokens[idx].Equals( "then" ) ) { RuleCondition ruleCondition = new RuleCondition( tokens[idx+1], tokens[idx+3] ); rule.AddCondition( ruleCondition ); idx += 4; } RuleConclusion ruleConclusion = new RuleConclusion( tokens[idx+2] ); rule.SetConclusion( ruleConclusion ); ruleBase.AddRule( rule ); } } }