/// <summary> Remove a successor node /// </summary> /// <param name="">node /// </param> /// <param name="">engine /// </param> /// <param name="">mem /// @throws AssertException /// /// </param> public virtual void removeSuccessorNode(BaseNode node, Rete engine, IWorkingMemory mem) { if (removeNode(node)) { // we retract the memories first, before removing the node IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this); if (alpha.size() > 0) { IEnumerator itr = alpha.GetEnumerator(); while (itr.MoveNext()) { if (node is BaseAlpha) { BaseAlpha next = (BaseAlpha)node; next.retractFact((IFact)itr.Current, engine, mem); } else if (node is BaseJoin) { BaseJoin next = (BaseJoin)node; next.retractRight((IFact)itr.Current, engine, mem); } } } } }
/// <summary> Set the Current node in the sequence of 1-input nodes. /// The Current node can be an AlphaNode or a LIANode. /// </summary> /// <param name="">node /// /// </param> public override void addSuccessorNode(BaseNode node, Rete engine, IWorkingMemory mem) { if (addNode(node)) { // if there are matches, we propogate the facts to // the new successor only IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this); if (alpha.size() > 0) { IEnumerator itr = alpha.GetEnumerator(); while (itr.MoveNext()) { if (node is BaseAlpha) { BaseAlpha next = (BaseAlpha)node; next.assertFact((IFact)itr.Current, engine, mem); } else if (node is BaseJoin) { BaseJoin next = (BaseJoin)node; next.assertRight((IFact)itr.Current, engine, mem); } else if (node is TerminalNode) { TerminalNode next = (TerminalNode)node; Index inx = new Index(new IFact[] { (IFact)itr.Current }); next.assertFacts(inx, engine, mem); } } } } }
/// <summary> Add a successor node /// </summary> public override void addSuccessorNode(BaseNode node, Rete engine, IWorkingMemory mem) { if (!containsNode(successorNodes, node) && !successor2.Contains(node)) { if (node is BaseJoin || node is TerminalNode) { successor2.Add(node); } else { // we test to see if the operator is ==, nil, not nil // if the node isn't BaseJoin, it should be BaseAlpha BaseAlpha ba = (BaseAlpha)node; if (ba.Operator == Constants.LESS || ba.Operator == Constants.GREATER || ba.Operator == Constants.LESSEQUAL || ba.Operator == Constants.GREATEREQUAL || ba.Operator == Constants.NOTEQUAL || ba.Operator == Constants.NOTNILL) { successor2.Add(node); } else { addNode(node); } } if (gauranteeUnique && node is AlphaNode) { // now we use CompositeIndex instead of HashString AlphaNode anode = (AlphaNode)node; entries.Put(anode.HashIndex, node); // we increment the node count for the slot deftemplate.getSlot(anode.slot.Id).incrementNodeCount(); } // if there are matches, we propogate the facts to // the new successor only IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this); if (alpha.size() > 0) { IEnumerator itr = alpha.GetEnumerator(); while (itr.MoveNext()) { IFact f = (IFact)itr.Current; if (node is BaseAlpha) { BaseAlpha next = (BaseAlpha)node; next.assertFact(f, engine, mem); } else if (node is BaseJoin) { BaseJoin next = (BaseJoin)node; next.assertRight(f, engine, mem); } else if (node is TerminalNode) { TerminalNode t = (TerminalNode)node; Index inx = new Index(new IFact[] { f }); t.assertFacts(inx, engine, mem); } } } } }
public virtual void printWorkingMemory(bool detailed, bool inputNodes) { engine.writeMessage("AlphaNode count " + alphaMemories.Count + Constants.LINEBREAK); IEnumerator itr = alphaMemories.Keys.GetEnumerator(); int memTotal = 0; while (itr.MoveNext()) { BaseNode key = (BaseNode)itr.Current; if (!(key is ObjectTypeNode) && !(key is LIANode)) { IAlphaMemory am = (IAlphaMemory)alphaMemories.Get(key); if (detailed) { engine.writeMessage(key.toPPString() + " count=" + am.size() + Constants.LINEBREAK); } memTotal += am.size(); } else { if (inputNodes) { IAlphaMemory am = (IAlphaMemory)alphaMemories.Get(key); engine.writeMessage(key.toPPString() + " count=" + am.size() + Constants.LINEBREAK); } } } engine.writeMessage("total AlphaMemories = " + memTotal + Constants.LINEBREAK); // now write out the left beta memory engine.writeMessage("BetaNode Count " + betaLeftMemories.Count + Constants.LINEBREAK); int betaTotal = 0; itr = betaLeftMemories.Keys.GetEnumerator(); while (itr.MoveNext()) { BaseNode key = (BaseNode)itr.Current; if (key is BaseJoin) { printBetaNodes((BaseJoin)key, detailed, betaTotal); } } engine.writeMessage("total BetaMemories = " + betaTotal + Constants.LINEBREAK); }
/// <summary> /// Printout the memory for the given rule. /// </summary> /// <param name="rule">The rule.</param> public virtual void printWorkingMemory(Rule.IRule rule) { engine.writeMessage("Memories for " + rule.Name); ICondition[] conds = rule.Conditions; int memTotal = 0; for (int idx = 0; idx < conds.Length; idx++) { ICondition c = conds[idx]; IList l = c.Nodes; IEnumerator itr = l.GetEnumerator(); while (itr.MoveNext()) { BaseNode key = (BaseNode)itr.Current; IAlphaMemory am = (IAlphaMemory)alphaMemories.Get(key); engine.writeMessage(key.toPPString() + " count=" + am.size() + Constants.LINEBREAK); memTotal += am.size(); } } }