From e364b97cbf58d17f16d0a0c5deff17b0dedea922 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Fri, 7 Jan 2022 21:16:30 +0100 Subject: [PATCH] WIP: Adding Transitions to the Conditions Tree: success ! --- src/rules_tree.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/rules_tree.py b/src/rules_tree.py index 404169a..2c53d17 100644 --- a/src/rules_tree.py +++ b/src/rules_tree.py @@ -45,13 +45,11 @@ class TransTreeNode(NodeMixin): super(TransTreeNode, self).__init__() self.parent_node_id = parent_node_id self.parent = None + self.id = None def add_parent_leaf_node(self, parent_node, transition_node_id): - print('orphan transition node', transition_node_id, - 'is to be adopted by leaf node', parent_node.id, - type(self), - type(parent_node)) - # self.parent = parent_node + # print('orphan transition is adopted by leaf node', parent_node.id) + self.parent = parent_node for i in conditions_set: # sorted(conditions_set, key=i.id): @@ -68,17 +66,22 @@ for i in conditions_list: else: root = j -for i in transitions_set: - transition_node = TransTreeNode(i[1]) - for condition_node in LevelOrderIter(root): - if condition_node.is_leaf: - if (str(condition_node.id) == transition_node.parent_node_id): - transition_node.add_parent_leaf_node(condition_node, i[1]) +for condition_node in LevelOrderIter(root): + if condition_node.is_leaf: + for i in transitions_set: + transition_node = TransTreeNode(i[1]) + if (str(condition_node.id) == i[1]): + transition_node.add_parent_leaf_node(condition_node, transition_node) for pre, fill, node in RenderTree(root): treestr = u"%s%s" % (pre, node.id) - print(treestr.ljust(16), node.weight, ' arrow(s) at [site', node.site, - 'in cell', node.x, end=']\n') + if (type(node) == CondTreeNode): + print(treestr.ljust(16), node.weight, ' arrow(s) at [site', node.site, + 'in cell', node.x, end='') + if (not node.depth == 2): + print(end=']\n') + else: + print(end='] *** \n') # print([node.id for node in LevelOrderIter(root) if node.is_leaf])