예제 #1
0
 /// <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);
                 }
             }
         }
     }
 }
예제 #2
0
 /// <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);
                 }
             }
         }
     }
 }
예제 #3
0
 /// <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);
                 }
             }
         }
     }
 }
예제 #4
0
 /// <summary> Method is used to pass a fact to the successor nodes
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 ///
 /// </param>
 protected internal virtual void propogateAssert(IFact fact, Rete engine, IWorkingMemory mem)
 {
     for (int idx = 0; idx < successorNodes.Length; idx++)
     {
         Object nNode = successorNodes[idx];
         if (nNode is BaseAlpha)
         {
             BaseAlpha next = (BaseAlpha)nNode;
             next.assertFact(fact, engine, mem);
         }
         else if (nNode is BaseJoin)
         {
             BaseJoin next = (BaseJoin)nNode;
             next.assertRight(fact, engine, mem);
         }
         else if (nNode is TerminalNode)
         {
             TerminalNode next = (TerminalNode)nNode;
             Index        inx  = new Index(new IFact[] { fact });
             next.assertFacts(inx, engine, mem);
         }
     }
 }
예제 #5
0
 /// <summary> method for propogating the retract
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 ///
 /// </param>
 protected internal virtual void propogateRetract(IFact fact, Rete engine, IWorkingMemory mem)
 {
     for (int idx = 0; idx < successorNodes.Length; idx++)
     {
         Object nNode = successorNodes[idx];
         if (nNode is BaseAlpha)
         {
             BaseAlpha next = (BaseAlpha)nNode;
             next.retractFact(fact, engine, mem);
         }
         else if (nNode is BaseJoin)
         {
             BaseJoin next = (BaseJoin)nNode;
             // AlphaNodes always call retractRight in the
             // BetaNode
             next.retractRight(fact, engine, mem);
         }
         else if (nNode is TerminalNode)
         {
             Index inx = new Index(new IFact[] { fact });
             ((TerminalNode)nNode).retractFacts(inx, engine, mem);
         }
     }
 }