Esempio n. 1
0
        /// <summary> implementation will Remove the template from the HashMap
        /// and it will Remove the ObjectTypeNode from the network.
        /// </summary>
        public virtual void removeTemplate(ITemplate temp, Rete engine, IWorkingMemory mem)
        {
            deftemplates.Remove(temp.Name);
            if (temp.ClassName != null)
            {
                deftemplates.Remove(temp.ClassName);
            }
            ObjectTypeNode otn = mem.RuleCompiler.getObjectTypeNode(temp);

            mem.RuleCompiler.removeObjectTypeNode(otn);
        }
Esempio n. 2
0
        /// <summary> Retracting from the left is different than retractRight for couple
        /// of reasons.
        /// <ul>
        /// <li> NotJoin will only propogate the facts from the left</li>
        /// <li> NotJoin never needs to merge the left and right</li>
        /// </ul>
        /// </summary>
        /// <param name="">factInstance
        /// </param>
        /// <param name="">engine
        ///
        /// </param>
        public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem)
        {
            IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this);

            leftmem.Remove(linx);
            propogateRetract(linx, engine, mem);
        }
Esempio n. 3
0
        /// <summary>
        /// </summary>
        public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem)
        {
            IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this);

            if (leftmem.ContainsKey(linx))
            {
                // the memory Contains the key, so we retract and propogate
                leftmem.Remove(linx);
                propogateRetract(linx, engine, mem);
            }
        }
Esempio n. 4
0
        public override bool removeNode(BaseNode n)
        {
            bool rem = base.removeNode(n);

            successor2.Remove(n);
            if (n is AlphaNode)
            {
                entries.Remove(((AlphaNode)n).HashIndex);
            }
            return(rem);
        }
Esempio n. 5
0
        /// <summary> Remove a partial match from the memory
        /// </summary>
        public virtual int removePartialMatch(IHashIndex index, IFact fact)
        {
            IGenericMap <Object, Object> list = (IGenericMap <Object, Object>)memory[index];

            list.Remove(fact);
            if (list.Count == 0)
            {
                memory.Remove(index);
            }
            counter--;
            return(list.Count);
        }
Esempio n. 6
0
        /// <summary> Retracting from the left requires that we propogate the
        ///
        /// </summary>
        /// <param name="">factInstance
        /// </param>
        /// <param name="">engine
        ///
        /// </param>
        public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem)
        {
            IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this);

            leftmem.Remove(linx);
            NotEqHashIndex       eqinx    = new NotEqHashIndex(NodeUtils.getLeftBindValues(binds, linx.Facts));
            HashedNeqAlphaMemory rightmem = (HashedNeqAlphaMemory)mem.getBetaRightMemory(this);

            Object[] objs = rightmem.iterator(eqinx);
            for (int idx = 0; idx < objs.Length; idx++)
            {
                propogateRetract(linx.add((IFact)objs[idx]), engine, mem);
            }
        }
Esempio n. 7
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)
        {
            Index inx = new Index(new IFact[] { rfact });
            IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this);

            if (rightmem.ContainsKey(inx))
            {
                int count = rightmem.Count;
                rightmem.Remove(inx);
                if (count == 1 && rightmem.Count == 0)
                {
                    propogateRetract(inx, engine, mem);
                }
            }
        }
Esempio n. 8
0
        /// <summary> Retracting from the left requires that we propogate the
        ///
        /// </summary>
        /// <param name="">factInstance
        /// </param>
        /// <param name="">engine
        ///
        /// </param>
        public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem)
        {
            IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this);

            leftmem.Remove(linx);
            IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this);
            IEnumerator itr = rightmem.Keys.GetEnumerator();

            if (itr != null)
            {
                while (itr.MoveNext())
                {
                    propogateRetract(linx.add((IFact)itr.Current), engine, mem);
                }
            }
        }
Esempio n. 9
0
        /// <summary> Remove a partial match from the memory
        /// </summary>
        public virtual int removePartialMatch(NotEqHashIndex index, IFact fact)
        {
            IGenericMap <Object, Object> match = (IGenericMap <Object, Object>)memory.Get(index);

            if (match != null)
            {
                IGenericMap <Object, Object> submatch = (IGenericMap <Object, Object>)match.Get(index.SubIndex);
                submatch.Remove(fact);
                if (submatch.Count == 0)
                {
                    match.Remove(index.SubIndex);
                }
                counter--;
                return(submatch.Count);
            }
            return(-1);
        }
Esempio n. 10
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)
        {
            IGenericMap <Object, Object> rightmem = (IGenericMap <Object, Object>)mem.getBetaRightMemory(this);

            rightmem.Remove(rfact);
            IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this);
            IEnumerator itr = leftmem.Values.GetEnumerator();

            while (itr.MoveNext())
            {
                IBetaMemory bmem = (IBetaMemory)itr.Current;
                if (evaluate(bmem.LeftFacts, rfact, engine))
                {
                    bmem.removeMatch(rfact);
                    propogateRetract(bmem.Index, engine, mem);
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Retracting from the left requires that we propogate the
        /// </summary>
        /// <param name="linx">The linx.</param>
        /// <param name="engine">The engine.</param>
        /// <param name="mem">The mem.</param>
        public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem)
        {
            IGenericMap <Object, Object> leftmem = mem.getBetaLeftMemory(this);

            leftmem.Remove(linx);
            IGenericMap <IFact, IFact> rightmem = (IGenericMap <IFact, IFact>)mem.getBetaRightMemory(this);

            foreach (IFact itr in rightmem.Values)
            {
                propogateRetract(linx.add(itr), engine, mem);
            }

            //IEnumerator itr = rightmem.Values.GetEnumerator();
            //while (itr.MoveNext())
            //{
            //    propogateRetract(linx.add((IFact) itr.Current), engine, mem);
            //}
        }
Esempio n. 12
0
        public virtual void retractFact(IFact fact)
        {
            Deffact f = (Deffact)fact;

            deffactMap.Remove(f.equalityIndex());
            if (profileRetract_Renamed_Field)
            {
                retractFactWProfile(f);
            }
            else
            {
                if (watchFact_Renamed_Field)
                {
                    engine.writeMessage("<== " + fact.toFactString() + Constants.LINEBREAK, "t");
                }
                root.retractObject(f, engine, this);
            }
        }
Esempio n. 13
0
        /// <summary> Retracting from the left requires that we propogate the
        ///
        /// </summary>
        /// <param name="">factInstance
        /// </param>
        /// <param name="">engine
        ///
        /// </param>
        public override void retractLeft(Index linx, Rete engine, IWorkingMemory mem)
        {
            IGenericMap <Object, Object> leftmem = (IGenericMap <Object, Object>)mem.getBetaLeftMemory(this);

            leftmem.Remove(linx);
            EqHashIndex           eqinx    = new EqHashIndex(NodeUtils.getLeftValues(binds, linx.Facts));
            HashedAlphaMemoryImpl rightmem = (HashedAlphaMemoryImpl)mem.getBetaRightMemory(this);

            // now we propogate the retract. To do that, we have
            // merge each item in the list with the Fact array
            // and call retract in the successor nodes
            IEnumerator itr = rightmem.iterator(eqinx);

            if (itr != null)
            {
                while (itr.MoveNext())
                {
                    propogateRetract(linx.add((IFact)itr.Current), engine, mem);
                }
            }
        }
Esempio n. 14
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="rfact"></param>
        /// <param name="engine"></param>
        /// <param name="mem"></param>
        public override void retractRight(IFact rfact, Rete engine, IWorkingMemory mem)
        {
            IGenericMap <IFact, IFact> rightmem = (IGenericMap <IFact, IFact>)mem.getBetaRightMemory(this);

            rightmem.Remove(rfact);
            IGenericMap <Object, Object> leftmem = mem.getBetaLeftMemory(this);

            foreach (Index bmem in leftmem.Values)
            {
                propogateRetract(bmem.add(rfact), engine, mem);
            }


            //IEnumerator itr = leftmem.Values.GetEnumerator();
            //while (itr.MoveNext())
            //{
            //    Index bmem = (Index) itr.Current;
            //    // now we propogate
            //    propogateRetract(bmem.add(rfact), engine, mem);
            //}
        }
Esempio n. 15
0
        /// <summary> Remove a rule from this module
        /// </summary>
        public virtual void removeRule(Rule.IRule rl, Rete engine, IWorkingMemory mem)
        {
            rules.Remove(rl.Name);
            // we should iterate over the nodes of the rule and Remove
            // them if they are not shared
            ICondition[] cnds = rl.Conditions;
            // first Remove the alpha nodes
            for (int idx = 0; idx < cnds.Length; idx++)
            {
                ICondition cnd = cnds[idx];
                if (cnd is ObjectCondition)
                {
                    ObjectCondition oc    = (ObjectCondition)cnd;
                    String          templ = oc.TemplateName;
                    Deftemplate     temp  = (Deftemplate)deftemplates.Get(templ);
                    ObjectTypeNode  otn   = mem.RuleCompiler.getObjectTypeNode(temp);
                    removeAlphaNodes(oc.Nodes, otn);
                }
            }
            // now Remove the betaNodes, since the engine currently
            // doesn't share the betaNodes, we can just Remove it
            IList bjl = rl.Joins;

            for (int idx = 0; idx < bjl.Count; idx++)
            {
                BaseJoin   bjoin = (BaseJoin)bjl[idx];
                ICondition cnd   = cnds[idx + 1];
                if (cnd is ObjectCondition)
                {
                    ObjectCondition oc    = (ObjectCondition)cnd;
                    String          templ = oc.TemplateName;
                    Deftemplate     temp  = (Deftemplate)deftemplates.Get(templ);
                    ObjectTypeNode  otn   = mem.RuleCompiler.getObjectTypeNode(temp);
                    otn.removeNode(bjoin);
                }
            }
        }
Esempio n. 16
0
 public virtual void removeMatch(IFact rightfact)
 {
     matches.Remove(rightfact);
 }
Esempio n. 17
0
 public virtual void removeAlphaMemory(Object key)
 {
     alphaMemories.Remove(key);
 }
Esempio n. 18
0
 /// <summary> Method will Remove the ObjectTypeNode and call Clear on it.
 /// </summary>
 public virtual void removeObjectTypeNode(ObjectTypeNode node)
 {
     inputnodes.Remove(node.Deftemplate);
     node.clear(memory);
     node.clearSuccessors();
 }
Esempio n. 19
0
        /// <summary>
        /// Remove the LinkedActivation from TerminalNode2. This is necessary
        /// when the activation is fired and the actions executed.
        /// </summary>
        /// <param name="mem">The mem.</param>
        /// <param name="activation">The activation.</param>
        public virtual void removeActivation(IWorkingMemory mem, LinkedActivation activation)
        {
            IGenericMap <Object, Object> tmem = (IGenericMap <Object, Object>)mem.getTerminalMemory(this);

            tmem.Remove(activation.Index);
        }
Esempio n. 20
0
 /// <summary> The current implementation just removes the ObjectTypeNode
 /// and doesn't prevent the removal. The method should be called
 /// with care, since removing the ObjectTypeNode can have serious
 /// negative effects. This would generally occur when an undeftemplate
 /// occurs.
 /// </summary>
 public virtual void removeObjectTypeNode(ObjectTypeNode node)
 {
     inputNodes.Remove(node.Deftemplate);
 }