/// <summary> Retract from the right works in the following order. 1. Remove the fact /// from the right memory 2. check which left memory matched 3. propogate the /// retract /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void retractRight(IFact rfact, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); rightmem.Remove(rfact); IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); IEnumerator itr = leftmem.Values.GetEnumerator(); while (itr.MoveNext()) { IBetaMemory bmem = (IBetaMemory)itr.Current; if (evaluate(bmem.LeftFacts, rfact, engine)) { bmem.removeMatch(rfact); propogateRetract(bmem.Index, engine, mem); } } }
/// <summary> Retract from the right works in the following order. /// 1. Remove the fact from the right memory /// 2. check which left memory matched /// 3. propogate the retract /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void retractRight(IFact rfact, Rete engine, IWorkingMemory mem) { Index linx = new Index(new IFact[0]); IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); if (rightmem.RemoveWithReturn(rfact) != null) { // now we see the left memory matched and Remove it also IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); IEnumerator itr = leftmem.Values.GetEnumerator(); while (itr.MoveNext()) { IBetaMemory bmem = (IBetaMemory)itr.Current; int prevCount = bmem.matchCount(); if (bmem.matched(rfact)) { // we Remove the fact from the memory bmem.removeMatch(rfact); // since 1 or more matches prevents propogation // we don't need to propogate retract. if the // match count is now zero, we need to propogate // assert if (prevCount != 0 && bmem.matchCount() == 0) { try { propogateAssert(bmem.Index, engine, mem); } catch (AssertException e) { throw new RetractException("NotJion - " + e.Message); } } } } } }