コード例 #1
0
        /// <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
            HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this);
            EqHashIndex           inx      = new EqHashIndex(NodeUtils.getRightValues(binds, rfact));

            rightmem.addPartialMatch(inx, rfact);
            int after = rightmem.count(inx);
            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))
                {
                    if (after == 1)
                    {
                        // we have to retract
                        try
                        {
                            propogateRetract(linx, engine, mem);
                        }
                        catch (RetractException e)
                        {
                            throw new AssertException("NotJion - " + e.Message);
                        }
                    }
                }
            }
        }
コード例 #2
0
 /// <summary> NotJoin has to have a special addSuccessorNode since it needs
 /// to just propogate the left facts if it has zero matches.
 /// </summary>
 public override 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;
                 EqHashIndex           inx      = new EqHashIndex(NodeUtils.getLeftValues(binds, bmem.LeftFacts));
                 HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this);
                 // we don't bother adding the right fact to the left, since
                 // the right side is already Hashed
                 if (rightmem.count(inx) == 0)
                 {
                     node.assertFacts(bmem.Index, engine, mem);
                 }
             }
         }
     }
 }
コード例 #3
0
        /// <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);

            if (rightmem.count(inx) > 0)
            {
                propogateAssert(linx, engine, mem);
            }
        }
コード例 #4
0
        /// <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);

            // we don't bother adding the right fact to the left, since
            // the right side is already Hashed
            if (rightmem.count(inx) == 0)
            {
                propogateAssert(linx, engine, mem);
            }
        }
コード例 #5
0
        protected internal virtual void printBetaNodes(BaseJoin bjoin, bool detailed, int betaTotal)
        {
            if (bjoin is HashedEqBNode || bjoin is HashedEqNJoin)
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)getBetaRightMemory(bjoin);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is HashedNotEqNJoin || bjoin is HashedNotEqBNode)
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)getBetaRightMemory(bjoin);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(bjoin.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is ExistJoin)
            {
                ExistJoin henj = (ExistJoin)bjoin;
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(henj);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index indx = (Index)bm.Get(bitr.Current);
                    if (detailed)
                    {
                        engine.writeMessage(bjoin.toPPString(), Constants.DEFAULT_OUTPUT);
                        HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)getBetaRightMemory(henj);

                        EqHashIndex eqinx = new EqHashIndex(NodeUtils.getLeftValues(henj.binds, indx.Facts));
                        // Add to the total count
                        betaTotal += rightmem.count(eqinx);
                        engine.writeMessage(" count=" + betaTotal + " - " + indx.toPPString() + ": ", Constants.DEFAULT_OUTPUT);
                        IEnumerator ritr = rightmem.iterator(eqinx);
                        if (ritr != null)
                        {
                            StringBuilder buf = new StringBuilder();
                            while (ritr.MoveNext())
                            {
                                buf.Append(((IFact)ritr.Current).FactId + ",");
                            }
                            engine.writeMessage(buf.ToString(), Constants.DEFAULT_OUTPUT);
                        }
                        engine.writeMessage(Constants.LINEBREAK, Constants.DEFAULT_OUTPUT);
                    }
                }
            }
            else if (bjoin is NotJoin)
            {
                NotJoin nj = (NotJoin)bjoin;
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)getBetaLeftMemory(bjoin);
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index       indx = (Index)bitr.Current;
                    IBetaMemory bmem = (IBetaMemory)bm.Get(indx);
                    engine.writeMessage(bmem.toPPString());
                }
            }
            else if (bjoin is TemporalEqNode)
            {
                TemporalEqNode ten = (TemporalEqNode)bjoin;
            }
            else
            {
                IGenericMap <Object, Object> bm = (IGenericMap <Object, Object>)betaLeftMemories.Get(bjoin);
                // we iterate over the keys in the HashMap
                IEnumerator bitr = bm.Keys.GetEnumerator();
                while (bitr.MoveNext())
                {
                    Index  indx     = (Index)bm.Get(bitr.Current);
                    Object rightmem = betaRightMemories.Get(bjoin);
                    if (detailed)
                    {
                        if (rightmem is HashedAlphaMemoryImpl)
                        {
                            HashedAlphaMemoryImpl hami = (HashedAlphaMemoryImpl)rightmem;
                            engine.writeMessage(bjoin.toPPString() + " count=" + hami.size() + " - " + indx.toPPString() + Constants.LINEBREAK);
                        }
                        else
                        {
                            IGenericMap <Object, Object> rmap = (IGenericMap <Object, Object>)rightmem;
                            engine.writeMessage(bjoin.toPPString() + " count=" + rmap.Count + " - " + indx.toPPString() + Constants.LINEBREAK);
                        }
                    }
                    if (rightmem is HashedAlphaMemoryImpl)
                    {
                        betaTotal += ((HashedAlphaMemoryImpl)rightmem).size();
                    }
                    else
                    {
                        betaTotal += ((IGenericMap <IFact, IFact>)rightmem).Count;
                    }
                }
            }
        }