public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { long time = RightTime; IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); EqHashIndex inx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); TemporalHashedAlphaMem rightmem = (TemporalHashedAlphaMem) mem.getBetaRightMemory(this); IEnumerator itr = rightmem.iterator(inx); if (itr != null) { try { while (itr.MoveNext()) { IFact vl = (IFact) itr.Current; if (vl != null) { if (vl.timeStamp() > time) { propogateAssert(linx.add(vl), engine, mem); } else { rightmem.removePartialMatch(inx, vl); propogateRetract(linx.add(vl), engine, mem); } } } } catch (RetractException e) { // there shouldn't be any retract exceptions } } }
/// <summary> /// it's unlikely 2 rules are identical, except for the name. The implementation /// gets the current memory and propogates, but I wonder how much sense this /// makes in a real production environment. An user really shouldn't be deploying /// identical rules with different rule name. /// </summary> /// <param name="node">The node.</param> /// <param name="engine">The engine.</param> /// <param name="mem">The mem.</param> public virtual void addSuccessorNode(TerminalNode node, Rete engine, IWorkingMemory mem) { if (addNode(node)) { // first, we Get the memory for this node IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); // now we iterate over the entry set IEnumerator itr = leftmem.Values.GetEnumerator(); while (itr.MoveNext()) { Object omem = itr.Current; if (omem is IBetaMemory) { IBetaMemory bmem = (IBetaMemory)omem; Index left = bmem.Index; // iterate over the matches IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); IEnumerator ritr = rightmem.Keys.GetEnumerator(); while (ritr.MoveNext()) { IFact rfcts = (IFact)ritr.Current; // merge the left and right fact into a new Array node.assertFacts(left.add(rfcts), engine, mem); } } } } }
/// <summary> /// assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="linx">The linx.</param> /// <param name="engine">The engine.</param> /// <param name="mem">The mem.</param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); //foreach(IFact rfcts in ((IGenericMap<IFact, IFact>)mem.getBetaRightMemory(this)).Values) //{ // propogateAssert(linx.add(rfcts), engine, mem); //} IGenericMap <IFact, IFact> rightmem = (IGenericMap <IFact, IFact>)mem.getBetaRightMemory(this); foreach (IFact rfcts in rightmem.Values) { propogateAssert(linx.add(rfcts), engine, mem); } //IEnumerator itr = rightmem.Values.GetEnumerator(); //while (itr.MoveNext()) //{ // IFact rfcts = (IFact)itr.Current; // // now we propogate // propogateAssert(linx.add(rfcts), engine, mem); //} }
/// <summary> Assert from the right side is always going to be from an Alpha node. /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertRight(IFact rfact, Rete engine, IWorkingMemory mem) { // Get the memory for the node HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this); NotEqHashIndex inx = new NotEqHashIndex(NodeUtils.getRightBindValues(binds, rfact)); rightmem.addPartialMatch(inx, rfact); // now that we've added the facts to the list, we // proceed with evaluating the fact // else we compare the fact to all facts in the left IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); // since there may be key collisions, we iterate over the // values of the HashMap. If we used keySet to iterate, // we could encounter a ClassCastException in the case of // key collision. IEnumerator itr = leftmem.Values.GetEnumerator(); while (itr.MoveNext()) { Index linx = (Index)itr.Current; if (evaluate(linx.Facts, rfact)) { // now we propogate propogateAssert(linx.add(rfact), engine, mem); } } }
/// <summary> Retracting from the left requires that we propogate the /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Remove(linx); NotEqHashIndex eqinx = new NotEqHashIndex(NodeUtils.getLeftBindValues(binds, linx.Facts)); HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this); Object[] objs = rightmem.iterator(eqinx); for (int idx = 0; idx < objs.Length; idx++) { propogateRetract(linx.add((IFact)objs[idx]), engine, mem); } }
public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { long time = RightTime; IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); EqHashIndex inx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); TemporalHashedAlphaMem rightmem = (TemporalHashedAlphaMem)mem.getBetaRightMemory(this); IEnumerator itr = rightmem.iterator(inx); if (itr != null) { try { while (itr.MoveNext()) { IFact vl = (IFact)itr.Current; if (vl != null) { if (vl.timeStamp() > time) { propogateAssert(linx.add(vl), engine, mem); } else { rightmem.removePartialMatch(inx, vl); propogateRetract(linx.add(vl), engine, mem); } } } } catch (RetractException e) { // there shouldn't be any retract exceptions } } }
public override void assertRight(IFact rfact, Rete engine, IWorkingMemory mem) { long time = LeftTime; TemporalHashedAlphaMem rightmem = (TemporalHashedAlphaMem)mem.getBetaRightMemory(this); EqHashIndex inx = new EqHashIndex(NodeUtils.getRightValues(binds, rfact)); rightmem.addPartialMatch(inx, rfact); // now that we've added the facts to the list, we // proceed with evaluating the fact IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); // since there may be key collisions, we iterate over the // values of the HashMap. If we used keySet to iterate, // we could encounter a ClassCastException in the case of // key collision. IEnumerator itr = leftmem.Values.GetEnumerator(); try { while (itr.MoveNext()) { Index linx = (Index)itr.Current; if (evaluate(linx.Facts, rfact, time)) { // now we propogate propogateAssert(linx.add(rfact), engine, mem); } else { propogateRetract(linx.add(rfact), engine, mem); } } } catch (RetractException e) { // we shouldn't Get a retract exception. if we do, it's a bug } }
/// <summary> Retracting from the left requires that we propogate the /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Remove(linx); IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); IEnumerator itr = rightmem.Keys.GetEnumerator(); if (itr != null) { while (itr.MoveNext()) { propogateRetract(linx.add((IFact)itr.Current), engine, mem); } } }
/// <summary> /// Retracting from the left requires that we propogate the /// </summary> /// <param name="linx">The linx.</param> /// <param name="engine">The engine.</param> /// <param name="mem">The mem.</param> public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = mem.getBetaLeftMemory(this); leftmem.Remove(linx); IGenericMap <IFact, IFact> rightmem = (IGenericMap <IFact, IFact>)mem.getBetaRightMemory(this); foreach (IFact itr in rightmem.Values) { propogateRetract(linx.add(itr), engine, mem); } //IEnumerator itr = rightmem.Values.GetEnumerator(); //while (itr.MoveNext()) //{ // propogateRetract(linx.add((IFact) itr.Current), engine, mem); //} }
/// <summary> assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); // need to think the getLeftValues through better to // account for cases when a join has no bindings NotEqHashIndex inx = new NotEqHashIndex(NodeUtils.getLeftBindValues(binds, linx.Facts)); HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory) mem.getBetaRightMemory(this); Object[] objs = rightmem.iterator(inx); if (objs != null && objs.Length > 0) { for (int idx = 0; idx < objs.Length; idx++) { IFact rfcts = (IFact) objs[idx]; // now we propogate propogateAssert(linx.add(rfcts), 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) { EqHashIndex inx = new EqHashIndex(NodeUtils.getRightValues(binds, rfact)); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this); // first we Remove the fact from the right rightmem.removePartialMatch(inx, rfact); // 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()) { Index linx = (Index)itr.Current; if (evaluate(linx.Facts, rfact)) { propogateRetract(linx.add(rfact), engine, mem); } } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be joining /// against one or more objects, we need to pass all previously matched /// facts. /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); EqHashIndex inx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this); IEnumerator itr = rightmem.iterator(inx); if (itr != null) { while (itr.MoveNext()) { IFact vl = (IFact)itr.Current; if (vl != null) { propogateAssert(linx.add(vl), engine, mem); } } } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be /// joining against one or more objects, we need to pass all /// previously matched facts. /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Put(linx, linx); // need to think the getLeftValues through better to // account for cases when a join has no bindings NotEqHashIndex inx = new NotEqHashIndex(NodeUtils.getLeftBindValues(binds, linx.Facts)); HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this); Object[] objs = rightmem.iterator(inx); if (objs != null && objs.Length > 0) { for (int idx = 0; idx < objs.Length; idx++) { IFact rfcts = (IFact)objs[idx]; // now we propogate propogateAssert(linx.add(rfcts), engine, mem); } } }
/// <summary> Retracting from the left requires that we propogate the /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); leftmem.Remove(linx); EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this); // now we propogate the retract. To do that, we have // merge each item in the list with the Fact array // and call retract in the successor nodes IEnumerator itr = rightmem.iterator(eqinx); if (itr != null) { while (itr.MoveNext()) { propogateRetract(linx.add((IFact)itr.Current), engine, mem); } } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be joining /// against one or more objects, we need to pass all previously matched /// facts. /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); IBetaMemory bmem = new BetaMemoryImpl(linx); leftmem.Put(linx, bmem); IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); IEnumerator itr = rightmem.Keys.GetEnumerator(); if (itr != null) { while (itr.MoveNext()) { IFact vl = (IFact)itr.Current; // we have to evaluate the function if (vl != null && evaluate(linx.Facts, vl, engine)) { bmem.addMatch(vl); propogateAssert(linx.add(vl), engine, mem); } } } }
/// <summary> /// When new Successor nodes are added, we propogate the facts that matched to /// the new join node. /// </summary> /// <param name="node">The node.</param> /// <param name="engine">The engine.</param> /// <param name="mem">The mem.</param> public virtual void addSuccessorNode(BaseJoin node, Rete engine, IWorkingMemory mem) { if (addNode(node)) { // first, we Get the memory for this node IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this); // now we iterate over the entry set IEnumerator itr = leftmem.GetEnumerator(); while (itr.MoveNext()) { IBetaMemory bmem = (IBetaMemory)itr.Current; Index left = bmem.Index; // iterate over the matches IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this); IEnumerator ritr = rightmem.Keys.GetEnumerator(); while (ritr.MoveNext()) { IFact rfcts = (IFact)ritr.Current; // now assert in the new join node node.assertLeft(left.add(rfcts), engine, mem); } } } }
/// <summary> Retracting from the left requires that we propogate the /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this); leftmem.Remove(linx); IGenericMap<Object, Object> rightmem = (IGenericMap<Object, Object>) mem.getBetaRightMemory(this); IEnumerator itr = rightmem.Keys.GetEnumerator(); if (itr != null) { while (itr.MoveNext()) { propogateRetract(linx.add((IFact) itr.Current), engine, mem); } } }
public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this); leftmem.Remove(linx); EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts)); TemporalHashedAlphaMem rightmem = (TemporalHashedAlphaMem) mem.getBetaRightMemory(this); // now we propogate the retract. To do that, we have // merge each item in the list with the Fact array // and call retract in the successor nodes IEnumerator itr = rightmem.iterator(eqinx); if (itr != null) { while (itr.MoveNext()) { propogateRetract(linx.add((IFact) itr.Current), engine, mem); } } }
/// <summary> assertLeft takes an array of facts. Since the Current join may be joining /// against one or more objects, we need to pass all previously matched /// facts. /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void assertLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this); IBetaMemory bmem = new BetaMemoryImpl(linx); leftmem.Put(linx, bmem); IGenericMap<Object, Object> rightmem = (IGenericMap<Object, Object>) mem.getBetaRightMemory(this); IEnumerator itr = rightmem.Keys.GetEnumerator(); if (itr != null) { while (itr.MoveNext()) { IFact vl = (IFact) itr.Current; // we have to evaluate the function if (vl != null && evaluate(linx.Facts, vl, engine)) { bmem.addMatch(vl); propogateAssert(linx.add(vl), engine, mem); } } } }
/// <summary> Retracting from the left requires that we propogate the /// /// </summary> /// <param name="">factInstance /// </param> /// <param name="">engine /// /// </param> public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem) { IGenericMap<Object, Object> leftmem = (IGenericMap<Object, Object>) mem.getBetaLeftMemory(this); leftmem.Remove(linx); NotEqHashIndex eqinx = new NotEqHashIndex(NodeUtils.getLeftBindValues(binds, linx.Facts)); HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory) mem.getBetaRightMemory(this); Object[] objs = rightmem.iterator(eqinx); for (int idx = 0; idx < objs.Length; idx++) { propogateRetract(linx.add((IFact) objs[idx]), engine, mem); } }