Ejemplo 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)
        {
            NotEqHashIndex       inx      = new NotEqHashIndex(NodeUtils.getRightBindValues(binds, rfact));
            HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this);

            // first we Remove the fact from the right
            rightmem.removePartialMatch(inx, rfact);
            bool zm = rightmem.zeroMatch(inx);
            // 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))
                {
                    if (zm)
                    {
                        try
                        {
                            propogateAssert(linx, engine, mem);
                        }
                        catch (AssertException e)
                        {
                            throw new RetractException("NotJion - " + e.Message);
                        }
                    }
                }
            }
        }
Ejemplo 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)
        {
            NotEqHashIndex       inx      = new NotEqHashIndex(NodeUtils.getRightBindValues(binds, rfact));
            HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)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))
                {
                    // it matched, so we need to retract it from
                    // succeeding nodes
                    propogateRetract(linx.add(rfact), engine, mem);
                }
            }
        }