public void RemoveWME() { Production prod = new Production(); prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block"; Variable x = new Variable("x"); Variable y = new Variable("y"); Variable z = new Variable("z"); prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y)); prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z)); prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red")); AssertCondition rhs = new AssertCondition("C4", x, "is", "on top"); rhs.ConditionType = ConditionType.Assert; prod.AddConditionToRHS(rhs); Rete rete = new Rete(); rete.AddProduction(prod); WME wme1 = new WME("W1"); wme1.Fields[0] = "B1"; wme1.Fields[1] = "on"; wme1.Fields[2] = "B2"; rete.AddWME(wme1); WME wme2 = new WME("W2"); wme2.Fields[0] = "B1"; wme2.Fields[1] = "on"; wme2.Fields[2] = "B3"; rete.AddWME(wme2); WME wme3 = new WME("W3"); wme3.Fields[0] = "B1"; wme3.Fields[1] = "color"; wme3.Fields[2] = "red"; rete.AddWME(wme3); WME wme4 = new WME("W4"); wme4.Fields[0] = "B2"; wme4.Fields[1] = "on"; wme4.Fields[2] = "table"; rete.AddWME(wme4); WME wme5 = new WME("W5"); wme5.Fields[0] = "B2"; wme5.Fields[1] = "left of"; wme5.Fields[2] = "B3"; rete.AddWME(wme5); WME wme6 = new WME("W6"); wme6.Fields[0] = "B2"; wme6.Fields[1] = "color"; wme6.Fields[2] = "blue"; rete.AddWME(wme6); WME wme7 = new WME("W7"); wme7.Fields[0] = "B3"; wme7.Fields[1] = "left of"; wme7.Fields[2] = "B4"; rete.AddWME(wme7); WME wme8 = new WME("W8"); wme8.Fields[0] = "B3"; wme8.Fields[1] = "on"; wme8.Fields[2] = "table"; rete.AddWME(wme8); WME wme9 = new WME("W9"); wme9.Fields[0] = "B3"; wme9.Fields[1] = "color"; wme9.Fields[2] = "red"; rete.AddWME(wme9); Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions"); Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad"); rete.RemoveWME(wme9); Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions"); Assert.IsTrue(rete.WorkingMemory.Count == 8, "Bad"); }
/// <summary> /// Retracts the specified fact. /// </summary> /// <param name="fact">The fact.</param> private void Retract(WME fact) { _inferredFacts.Remove(fact); _rete.RemoveWME(fact); }
public void RemoveWME() { Production prod = new Production(); prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block"; Variable x = new Variable("x"); Variable y = new Variable("y"); Variable z = new Variable("z"); prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y)); prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z)); prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red")); AssertCondition rhs = new AssertCondition("C4", x, "is", "on top"); rhs.ConditionType = ConditionType.Assert; prod.AddConditionToRHS(rhs); Rete rete = new Rete(); rete.AddProduction(prod); WME wme1 = new WME("W1"); wme1.Fields[0] = "B1"; wme1.Fields[1] = "on"; wme1.Fields[2] = "B2"; rete.AddWME(wme1); WME wme2 = new WME("W2"); wme2.Fields[0] = "B1"; wme2.Fields[1] = "on"; wme2.Fields[2] = "B3"; rete.AddWME(wme2); WME wme3 = new WME("W3"); wme3.Fields[0] = "B1"; wme3.Fields[1] = "color"; wme3.Fields[2] = "red"; rete.AddWME(wme3); WME wme4 = new WME("W4"); wme4.Fields[0] = "B2"; wme4.Fields[1] = "on"; wme4.Fields[2] = "table"; rete.AddWME(wme4); WME wme5 = new WME("W5"); wme5.Fields[0] = "B2"; wme5.Fields[1] = "left of"; wme5.Fields[2] = "B3"; rete.AddWME(wme5); WME wme6 = new WME("W6"); wme6.Fields[0] = "B2"; wme6.Fields[1] = "color"; wme6.Fields[2] = "blue"; rete.AddWME(wme6); WME wme7 = new WME("W7"); wme7.Fields[0] = "B3"; wme7.Fields[1] = "left of"; wme7.Fields[2] = "B4"; rete.AddWME(wme7); WME wme8 = new WME("W8"); wme8.Fields[0] = "B3"; wme8.Fields[1] = "on"; wme8.Fields[2] = "table"; rete.AddWME(wme8); WME wme9 = new WME("W9"); wme9.Fields[0] = "B3"; wme9.Fields[1] = "color"; wme9.Fields[2] = "red"; rete.AddWME(wme9); Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions"); Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad"); rete.RemoveWME(wme9); Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions"); Assert.IsTrue(rete.WorkingMemory.Count == 8, "Bad"); }