/// <summary> /// <p> /// If this is an unconditional rule (there are no antecedents), /// simply evaluates the consequent for its side-effects. /// <p> /// If this is a conditional rule (there are antecedents), /// evaluates the antecedents: /// <ul> /// <li> If the value of an antecedent clause is below the alphacut /// threshold, the rule does not fire. /// <li> Keep track of the minimum truthvalue returned when evaluating /// each antecedent clause. /// <li> Pass the minimum to the correlation method ('eval' on the /// consequent clause). /// <li> Update working memory to show that the variable in the /// consequent clause has changed. /// </ul> /// </summary> /// <param name="alphaCut"></param> /// <param name="workingSet"></param> internal virtual void Fire(double alphaCut, System.Collections.BitArray workingSet) { // (If there are no antecedents or a consequent, serious error!) if ((moAntecedents.Count == 0)) { // unconditional rule if (moConsequent != null) { moConsequent.Evaluate(); workingSet.Or(moWrRefs); return; } else { // If there are no antecedents, there must at least be a consequent! Console.Out.WriteLine("Error: FuzzyRule cannot fire" + msName); } } // This is a conditional rule (there are antecedents), FuzzyClause clause; double truthValue; double truthValueMin = 1.0; bool skipConsequent = false; for (int i = 0; i < moAntecedents.Count; i++) { // Get an antecedent clause and evaluate it. clause = (FuzzyClause)(moAntecedents[i]); truthValue = clause.Evaluate(); mbFiredFlag = true; // Check the truth value against the alphacut threshold. // If the truth value is less than the threshold // stop evaluating the antecedent clauses and // prevent the consequent from being evaluated. if (truthValue <= alphaCut) { skipConsequent = true; break; } // Keep track of the smallest truth value from each // evaluated antecedent clause. if (truthValue < truthValueMin) { truthValueMin = truthValue; } } // If all the antecedent clauses evaluated successfully, // evaluate the consequent clause, and if that is evaluated // successfully, update the fact base. if (!skipConsequent) { if (moConsequent != null) { moConsequent.Evaluate(truthValueMin); workingSet.Or(moWrRefs); } } }
public static void TestOrIntervals() { var a = new[] {1, 2, 2, 3}.ToList(); var b = new[] {2, 2}.ToList(); Assert.That(a.Or(a), Is.EqualTo(a)); Assert.That(b.Or(b), Is.EqualTo(b)); Assert.That(a.Or(b), Is.EqualTo(new[] {1, 4})); Assert.That(b.Or(a), Is.EqualTo(new[] {1, 4})); }