Esempio 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);
        }
Esempio 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);
        }
Esempio n. 3
0
        public override bool Equals(Object obj)
        {
            //Check for null and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            Test_At_Join_Node p = (Test_At_Join_Node)obj;

            return(p.Field_Of_Arg1 == this.Field_Of_Arg1 &&
                   p.Field_Of_Arg2 == this.Field_Of_Arg2 &&
                   p.Number_Of_Levels_Up == this.Number_Of_Levels_Up);
        }
Esempio n. 4
0
        private List <Test_At_Join_Node> GetJoinTestsFromCondition(Condition c, List <Condition> earlier_conds)
        {
            List <Test_At_Join_Node> result = new List <Test_At_Join_Node>();

            for (int j = 0; j < ReteInferenceEngine.WME_FIELD_NUM; j++)
            {
                if (c.Fields[j] is Variable)
                {
                    Term      v = c.Fields[j];
                    FieldType f = (FieldType)j;
                    for (int i = earlier_conds.Count - 1; i >= 0; i--)
                    {
                        for (int k = 0; k < ReteInferenceEngine.WME_FIELD_NUM; k++)
                        {
                            if (earlier_conds[i].Fields[k] is Variable && earlier_conds[i].Fields[k].Equals(v))
                            {
                                FieldType         f2        = (FieldType)k;
                                Test_At_Join_Node this_test = new Test_At_Join_Node();
                                this_test.Field_Of_Arg1 = f;
                                //this_test.Number_Of_Levels_Up = i;
                                //foamliu, 2008/08/20, change:
                                //from: condition-number-of-arg2
                                //  to: number-of-levels-up
                                //since the current condition index = earlier_conds.Count
                                //we have: Number_Of_Levels_Up = earlier_conds.Count - i
                                this_test.Number_Of_Levels_Up = earlier_conds.Count - i;
                                this_test.Field_Of_Arg2       = f2;
                                result.Add(this_test);
                            }
                        }
                    }
                }
            }

            return(result);
        }