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); }
public ReteInferenceEngine() { this.m_top_node_of_alpha_network = new Constant_Test_Node(); this.m_top_node_of_alpha_network.Field_To_Test = FieldType.No_Test; this.m_dummy_top_node = new Dummy_Top_Node(); // just so there will be one thing to iterate over in the join-node-right-activation procedure. this.m_workingmemory = new List <WME>(); // foamliu, 2008/11/21, remove "P_Nodes", access p-nodes from productions. // //this.m_p_nodes = new List<P_Node>(); }
private Constant_Test_Node BuildOrShareConstantTestNode(Constant_Test_Node parent, FieldType field, Term term) { // look for an existing node we can share foreach (Constant_Test_Node child in parent.Children) { if (child.Field_To_Test == field && child.Thing_The_Field_Must_Equal.Equals(term)) { return(child); } } // couldn't find a node to share, so build a new one Constant_Test_Node _new = new Constant_Test_Node(); parent.Children.Add(_new); _new.Field_To_Test = field; _new.Thing_The_Field_Must_Equal = term; _new.Output_Memory = null; _new.Children.Clear(); return(_new); }
// assumes all tests are tests for equality with some constant symbol. public void ConstantTestNodeActivation(Constant_Test_Node node, WME w) { if (node.Field_To_Test != FieldType.No_Test) { Term v = w.Fields[(int)node.Field_To_Test]; if (!v.Equals(node.Thing_The_Field_Must_Equal)) { // failed the test, so don't propagate any further return; } } if (node.Output_Memory != null) { AlphaMemoryActivation(node.Output_Memory, w); } foreach (Constant_Test_Node c in node.Children) { ConstantTestNodeActivation(c, w); } }