Ejemplo n.º 1
0
        private ReteNode BuildOrShareNegativeNode(ReteNode parent, Alpha_Memory am, List <Test_At_Join_Node> tests)
        {
            // look for an existing node to share
            foreach (ReteNode child in parent.Children)
            {
                if (child.Type == ReteNodeType.Negative_Node)
                {
                    Negative_Node n_node = (Negative_Node)child;

                    if (n_node.Amem.Equals(am) && Test_At_Join_Node.IsListEquals(n_node.Tests, tests))
                    {
                        return(child);
                    }
                }
            }

            Negative_Node new_n_node = new Negative_Node();

            new_n_node.Type   = ReteNodeType.Negative_Node;
            new_n_node.Parent = parent;
            // insert new at the head of the list parent.children
            parent.Children.Insert(0, new_n_node);
            //new_n_node.Children.Clear();
            //new_n_node.Items.Clear();
            new_n_node.Tests = tests;
            new_n_node.Amem  = am;

            am.Successors.Insert(0, new_n_node);

            return(new_n_node);
        }
Ejemplo n.º 2
0
        private ReteNode BuildOrShareJoinNode(ReteNode parent, Alpha_Memory am, List <Test_At_Join_Node> tests)
        {
            // look for an existing node to share
            foreach (ReteNode child in parent.Children)
            {
                Join_Node j_node = child as Join_Node;

                if (null != j_node)
                {
                    if (j_node.Amem.Equals(am) && Test_At_Join_Node.IsListEquals(j_node.Tests, tests))
                    {
                        return(child);
                    }
                }
            }

            Join_Node new_j_node = new Join_Node();

            new_j_node.Parent = parent;
            // insert new at the head of the list parent.children
            parent.Children.Insert(0, new_j_node);

            // foamliu, 2008/11/29, new object, no need.
            //new_j_node.Children.Clear();
            new_j_node.Tests = tests;
            new_j_node.Amem  = am;
            am.Successors.Insert(0, new_j_node);

            return(new_j_node);
        }
Ejemplo n.º 3
0
        private Alpha_Memory BuildOrShareAlphaMemory(Condition c)
        {
            Constant_Test_Node current_node = this.m_top_node_of_alpha_network;

            for (int j = 0; j < ReteInferenceEngine.WME_FIELD_NUM; j++)
            {
                // for each constant tests in each field of c
                if (!(c.Fields[j] is Variable))
                {
                    Term      sym = c.Fields[j];
                    FieldType f   = (FieldType)j;
                    current_node = BuildOrShareConstantTestNode(current_node, f, sym);
                }
            }
            if (current_node.Output_Memory != null)
            {
                return(current_node.Output_Memory);
            }

            Alpha_Memory am = new Alpha_Memory();

            current_node.Output_Memory = am;
            am.Successors.Clear();
            am.Items.Clear();
            // initialize am with any current WMEs
            foreach (WME w in this.m_workingmemory)
            {
                if (c.PassAllConstantTests(w))
                {
                    AlphaMemoryActivation(am, w);
                }
            }

            return(am);
        }
Ejemplo n.º 4
0
        public void AlphaMemoryActivation(Alpha_Memory node, WME wme)
        {
            // insert w at the head of node.items
            node.Items.Insert(0, wme);

            // for tree-based removal
            wme.Alpha_Mems.Insert(0, node);

            // for each child in node.successors do right-activation (child, w)
            foreach (ReteNode child in node.Successors)
            {
                //Join_Node_Right_Activation((Join_Node)child, w);
                // foamliu, 2008/08/26, use a general method here
                // to support both join-node and negative-node.
                RightActivation(child, wme);
            }
        }
Ejemplo n.º 5
0
 private void DeleteAlphaMemory(Alpha_Memory alpha_Memory)
 {
     // foamliu, 2008/11/21.
     // TODO: send to GC.
 }