private void ProcessConditionalRules(System.Collections.BitArray factBase)
{
bool moreRules = true;
List<FuzzyRule> tmpRuleSet = new List<FuzzyRule>(10);
Console.Out.WriteLine(Environment.NewLine + "Processing conditional fuzzy rules ");
while (moreRules)
{
// Create a rule set:
// Examine all conditional rules.
// If a rule has fired, ignore it.
// If a rule has not fired, and if it can be fired given
// the current fact base, add it to the rule set.
if (moCndRuleList != null)
{
foreach (FuzzyRule rule in moCndRuleList)
{
if (!rule.Fired)
{
// The rule has not fired; check the rule's antecedents reference
System.Collections.BitArray tmpRuleFacts = rule.RdReferences;
System.Collections.BitArray tempFacts = rule.RdReferences;
tempFacts.And(factBase);
// If the antecedents reference variables whose values have been
// determined, the rule can fire, so add it to the rule set.
if (BitArrayEquality(tempFacts, tmpRuleFacts) == true)
{
tmpRuleSet.Add(rule);
}
}
}
}
// If the rule set is empty, no rules can be fired; exit the loop.
if ((tmpRuleSet.Count == 0))
{
moreRules = false;
break;
}
// Okay, we have some rules in the generated rule set;
// Attempt to fire them all. Rules that fire successfully
// update the fact base directly.
for (int i = 0; i < tmpRuleSet.Count; i++)
{
FuzzyRule rule = (FuzzyRule)tmpRuleSet[i];
Console.Out.WriteLine(Environment.NewLine + "Firing fuzzy rule: " + rule.Name);
rule.Fire(mdAlphaCut, factBase);
}
// We may or may not have fired all the rules in the rule set;
// In any event, do a purge of the rule set to get ready for the
// next iteration of the while loop.
tmpRuleSet.Clear();
}
}