Esempio n. 1
0
        /// <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)
        {
            HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this);
            EqHashIndex           inx      = new EqHashIndex(NodeUtils.getRightValues(binds, rfact));
            // Remove the fact from the right
            int after = rightmem.removePartialMatch(inx, rfact);

            if (after == 0)
            {
                // 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))
                    {
                        try
                        {
                            propogateAssert(linx, engine, mem);
                        }
                        catch (AssertException e)
                        {
                            throw new RetractException("NotJion - " + e.Message);
                        }
                    }
                }
                inx = null;
            }
        }
Esempio n. 2
0
        /// <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);
                }
            }
        }