예제 #1
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;
                     Index inx = new Index(new IFact[] {(IFact) itr.Current});
                     next.assertLeft(inx, engine, mem);
                 }
             }
         }
     }
 }
예제 #2
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);
                 }
             }
         }
     }
 }
예제 #3
0
        /// <summary> the implementation just propogates the assert down the network
        /// </summary>
        public override void assertFact(IFact fact, Rete engine, IWorkingMemory mem)
        {
            IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this);

            alpha.addPartialMatch(fact);
            propogateAssert(fact, engine, mem);
        }
예제 #4
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);
                 }
             }
         }
     }
 }
예제 #5
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);
                 }
             }
         }
     }
 }
예제 #6
0
 /// <summary> Retract simply propogates it down the network
 /// </summary>
 public override void retractFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     IAlphaMemory alpha = (IAlphaMemory) mem.getAlphaMemory(this);
     if (alpha.removePartialMatch(fact) != null)
     {
         propogateRetract(fact, engine, mem);
     }
 }
예제 #7
0
        /// <summary> Retract simply propogates it down the network
        /// </summary>
        public override void retractFact(IFact fact, Rete engine, IWorkingMemory mem)
        {
            IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this);

            if (alpha.removePartialMatch(fact) != null)
            {
                propogateRetract(fact, engine, mem);
            }
        }
예제 #8
0
 /// <summary> the implementation will first check to see if the fact already matched.
 /// If it did, the fact stops and doesn't go any further. If it doesn't,
 /// it will attempt to evaluate it and Add the fact if it matches.
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 ///
 /// </param>
 public override void assertFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     if (evaluate(fact))
     {
         IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this);
         // we set the time of the last match
         alpha.addPartialMatch(fact);
         propogateAssert(fact, engine, mem);
     }
 }
예제 #9
0
 /// <summary> the implementation will first check to see if the fact already matched.
 /// If it did, the fact stops and doesn't go any further. If it doesn't,
 /// it will attempt to evaluate it and Add the fact if it matches.
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 ///
 /// </param>
 public override void assertFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     if (evaluate(fact))
     {
         IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this);
         alpha.addPartialMatch(fact);
         // if watch is on, we notify the engine. Rather than
         // create an event class here, we let Rete do that.
         propogateAssert(fact, engine, mem);
     }
 }
예제 #10
0
        /// <summary> Retract a fact from the node
        /// </summary>
        /// <param name="">factInstance
        /// </param>
        /// <param name="">engine
        ///
        /// </param>
        public override void retractFact(IFact fact, Rete engine, IWorkingMemory mem)
        {
            IAlphaMemory alpha = (IAlphaMemory)mem.getAlphaMemory(this);

            if (alpha.removePartialMatch(fact) != null)
            {
                // if watch is on, we notify the engine. Rather than
                // create an event class here, we let Rete do that.
                propogateRetract(fact, engine, mem);
            }
        }
예제 #11
0
 /// <summary> assert the fact and propogate. ObjectTypeNode does not call
 /// assertEvent, since it's not that important and doesn't really
 /// help debugging.
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 ///
 /// </param>
 public override void assertFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     // ObjectTypeNode doesn't bother checking the deftemplate.
     ((IAlphaMemory)mem.getAlphaMemory(this)).addPartialMatch(fact);
     // if the number of succesor nodes is less than (slot count * opCount)
     if (gauranteeUnique && fact.Deftemplate.AllSlots.Length > 0 && successorNodes.Length > (fact.Deftemplate.AllSlots.Length * operators.Length))
     {
         assertFactWithMap(fact, engine, mem);
     }
     else
     {
         assertAllSuccessors(fact, engine, mem);
     }
 }
예제 #12
0
 /// <summary> Retract the fact to the succeeding nodes. ObjectTypeNode does not call
 /// assertEvent, since it's not that important and doesn't really
 /// help debugging.
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 ///
 /// </param>
 public override void retractFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     if (fact.Deftemplate == deftemplate)
     {
         ((IAlphaMemory)mem.getAlphaMemory(this)).removePartialMatch(fact);
         for (int idx = 0; idx < successorNodes.Length; idx++)
         {
             Object node = successorNodes[idx];
             if (node is BaseAlpha)
             {
                 ((BaseAlpha)node).retractFact(fact, engine, mem);
             }
             else if (node is BaseJoin)
             {
                 ((BaseJoin)node).retractRight(fact, engine, mem);
             }
         }
         IEnumerator itr2 = successor2.GetEnumerator();
         while (itr2.MoveNext())
         {
             BaseNode node = (BaseNode)itr2.Current;
             if (node is BaseAlpha)
             {
                 ((BaseAlpha)node).retractFact(fact, engine, mem);
             }
             else if (node is BaseJoin)
             {
                 ((BaseJoin)node).retractRight(fact, engine, mem);
             }
             else if (node is TerminalNode)
             {
                 Index inx = new Index(new IFact[] { fact });
                 ((TerminalNode)node).retractFacts(inx, engine, mem);
             }
         }
     }
 }
예제 #13
0
 /// <summary> Retract the fact to the succeeding nodes. ObjectTypeNode does not call
 /// assertEvent, since it's not that important and doesn't really
 /// help debugging.
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 public override void retractFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     if (fact.Deftemplate == deftemplate)
     {
         ((IAlphaMemory) mem.getAlphaMemory(this)).removePartialMatch(fact);
         for (int idx = 0; idx < successorNodes.Length; idx++)
         {
             Object node = successorNodes[idx];
             if (node is BaseAlpha)
             {
                 ((BaseAlpha) node).retractFact(fact, engine, mem);
             }
             else if (node is BaseJoin)
             {
                 ((BaseJoin) node).retractRight(fact, engine, mem);
             }
         }
         IEnumerator itr2 = successor2.GetEnumerator();
         while (itr2.MoveNext())
         {
             BaseNode node = (BaseNode) itr2.Current;
             if (node is BaseAlpha)
             {
                 ((BaseAlpha) node).retractFact(fact, engine, mem);
             }
             else if (node is BaseJoin)
             {
                 ((BaseJoin) node).retractRight(fact, engine, mem);
             }
             else if (node is TerminalNode)
             {
                 Index inx = new Index(new IFact[] {fact});
                 ((TerminalNode) node).retractFacts(inx, engine, mem);
             }
         }
     }
 }
예제 #14
0
 /// <summary> assert the fact and propogate. ObjectTypeNode does not call
 /// assertEvent, since it's not that important and doesn't really
 /// help debugging.
 /// </summary>
 /// <param name="">fact
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 public override void assertFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     // ObjectTypeNode doesn't bother checking the deftemplate.
     ((IAlphaMemory) mem.getAlphaMemory(this)).addPartialMatch(fact);
     // if the number of succesor nodes is less than (slot count * opCount)
     if (gauranteeUnique && fact.Deftemplate.AllSlots.Length > 0 && successorNodes.Length > (fact.Deftemplate.AllSlots.Length*operators.Length))
     {
         assertFactWithMap(fact, engine, mem);
     }
     else
     {
         assertAllSuccessors(fact, engine, mem);
     }
 }
예제 #15
0
 /// <summary> Clear the memory. for now the method does not
 /// Remove all the successor nodes. need to think it over a bit.
 /// </summary>
 public override void clear(IWorkingMemory mem)
 {
     IAlphaMemory am = (IAlphaMemory) mem.getAlphaMemory(this);
     am.clear();
 }
예제 #16
0
 /// <summary> the implementation just propogates the assert down the network
 /// </summary>
 public override void assertFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     IAlphaMemory alpha = (IAlphaMemory) mem.getAlphaMemory(this);
     alpha.addPartialMatch(fact);
     propogateAssert(fact, engine, mem);
 }
예제 #17
0
 /// <summary> the implementation will first check to see if the fact already matched.
 /// If it did, the fact stops and doesn't go any further. If it doesn't,
 /// it will attempt to evaluate it and Add the fact if it matches.
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 public override void assertFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     if (evaluate(fact))
     {
         IAlphaMemory alpha = (IAlphaMemory) mem.getAlphaMemory(this);
         // we set the time of the last match
         alpha.addPartialMatch(fact);
         // if watch is on, we notify the engine. Rather than
         // create an event class here, we let Rete do that.
         propogateAssert(fact, engine, mem);
     }
 }
예제 #18
0
 /// <summary> Get the list of facts that have matched the node
 /// </summary>
 /// <returns>
 /// 
 /// </returns>
 public virtual IAlphaMemory getMemory(IWorkingMemory mem)
 {
     return (IAlphaMemory) mem.getAlphaMemory(this);
 }
예제 #19
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);
                 }
             }
         }
     }
 }
예제 #20
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);
                 }
             }
         }
     }
 }
예제 #21
0
 /// <summary> the implementation will first check to see if the fact already matched.
 /// If it did, the fact stops and doesn't go any further. If it doesn't,
 /// it will attempt to evaluate it and Add the fact if it matches.
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 public override void assertFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     if (evaluate(fact))
     {
         IAlphaMemory alpha = (IAlphaMemory) mem.getAlphaMemory(this);
         // we set the time of the last match
         alpha.addPartialMatch(fact);
         propogateAssert(fact, engine, mem);
     }
 }
예제 #22
0
 /// <summary> Retract a fact from the node
 /// </summary>
 /// <param name="">factInstance
 /// </param>
 /// <param name="">engine
 /// 
 /// </param>
 public override void retractFact(IFact fact, Rete engine, IWorkingMemory mem)
 {
     IAlphaMemory alpha = (IAlphaMemory) mem.getAlphaMemory(this);
     if (alpha.removePartialMatch(fact) != null)
     {
         // if watch is on, we notify the engine. Rather than
         // create an event class here, we let Rete do that.
         propogateRetract(fact, engine, mem);
     }
 }
예제 #23
0
 /// <summary> Get the list of facts that have matched the node
 /// </summary>
 /// <returns>
 ///
 /// </returns>
 public virtual IAlphaMemory getMemory(IWorkingMemory mem)
 {
     return((IAlphaMemory)mem.getAlphaMemory(this));
 }
예제 #24
0
        /// <summary> Clear the memory. for now the method does not
        /// Remove all the successor nodes. need to think it over a bit.
        /// </summary>
        public override void clear(IWorkingMemory mem)
        {
            IAlphaMemory am = (IAlphaMemory)mem.getAlphaMemory(this);

            am.clear();
        }