WIP: plus simple, plus propre. ( ;- ))

This commit is contained in:
Jean Sirmai 2022-01-08 19:41:35 +01:00
parent a78e3f7bb6
commit 29c8d0c127
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 20 additions and 25 deletions

Binary file not shown.

View File

@ -331,16 +331,16 @@ class Condition:
def set_weight(self, weight): def set_weight(self, weight):
self.node.attrib["weight"] = str(weight) self.node.attrib["weight"] = str(weight)
def get_node_self_id(self): def get_self_id(self):
return int(self.node.get("node_id")) return int(self.node.get("node_id"))
def set_node_self_id(self, node_id): def set_self_id(self, node_id):
self.node.attrib["node_id"] = str(node_id) self.node.attrib["node_id"] = str(node_id)
def get_node_parent_id(self): def get_parent_id(self):
return int(self.node.get("parent")) return int(self.node.get("parent"))
def set_node_parent_id(self, parent): def set_parent_id(self, parent):
self.node.attrib["parent"] = str(parent) self.node.attrib["parent"] = str(parent)

View File

@ -8,24 +8,24 @@ import model
class CondTreeNode(NodeMixin): class CondTreeNode(NodeMixin):
def __init__(self, id, x, site, weight, parent_node_id): def __init__(self, id, parent_id, x, site, weight):
super(CondTreeNode, self).__init__() super(CondTreeNode, self).__init__()
self.id = id self.id = id
self.parent_node_id = parent_node_id self.parent_id = parent_id
self.parent = None self.parent = None
self.x = x # TODO self.y = y,z... self.x = x # TODO self.y = y,z...
self.site = site self.site = site
self.weight = weight self.weight = weight
def add_parent_node(self, parent_node): def add_parent_node(self, parent_node):
print('orphan node ', self.id, ' is adopted by node ', parent_node.id) # print('orphan node ', self.id, ' is adopted by node ', parent_node.id)
self.parent = parent_node self.parent = parent_node
class TransTreeNode(NodeMixin): class TransTreeNode(NodeMixin):
def __init__(self, parent_node_id, id): def __init__(self, id, parent_id):
super(TransTreeNode, self).__init__() super(TransTreeNode, self).__init__()
self.parent_node_id = parent_node_id self.parent_id = parent_id
self.parent = None self.parent = None
self.id = id self.id = id
@ -36,16 +36,18 @@ class TransTreeNode(NodeMixin):
conditions_set = set() conditions_set = set()
transitions_set = set() transitions_set = set()
root = 0 root = None
for i in range(0, len(model.testmodel.get_conditions().get_all())): for i in range(0, len(model.testmodel.get_conditions().get_all())):
condition = model.testmodel.get_conditions().get_one(i) condition = model.testmodel.get_conditions().get_one(i)
conditions_set.add(CondTreeNode( tmp = CondTreeNode(condition.get_self_id(),
condition.get_node_self_id(), condition.get_parent_id(),
condition.get_node_parent_id(),
condition.get_coord("x"), condition.get_coord("x"),
condition.get_site(), condition.get_site(),
condition.get_weight())) condition.get_weight())
conditions_set.add(tmp)
if (tmp.parent_id == 0):
root = tmp
for i in range(0, len(model.testmodel.get_transitions().get_all())): for i in range(0, len(model.testmodel.get_transitions().get_all())):
transition = model.testmodel.get_transitions().get_one(i) transition = model.testmodel.get_transitions().get_one(i)
@ -53,22 +55,15 @@ for i in range(0, len(model.testmodel.get_transitions().get_all())):
transition.get_id(), transition.get_id(),
transition.get_parent())) transition.get_parent()))
# 0 1 2 3 4
# <condition site="1" weight="0" node_id="3" parent="2" x="2"/>
for i in conditions_set:
if (i.parent_node_id == 0):
root = i
for i in conditions_set: for i in conditions_set:
for j in conditions_set: for j in conditions_set:
if ((i != j) & (i.parent_node_id == j.id)): if ((i != j) & (i.parent_id == j.id)):
i.add_parent_node(j) i.add_parent_node(j)
for condition_node in LevelOrderIter(root): for condition_node in LevelOrderIter(root):
if condition_node.is_leaf: if condition_node.is_leaf:
for transition_node in transitions_set: for transition_node in transitions_set:
if (str(condition_node.id) == transition_node.parent): if (str(condition_node.id) == transition_node.parent_id):
transition_node.add_parent_leaf_node(condition_node) transition_node.add_parent_leaf_node(condition_node)
for pre, fill, node in RenderTree(root): for pre, fill, node in RenderTree(root):
@ -76,7 +71,7 @@ for pre, fill, node in RenderTree(root):
if (type(node) == CondTreeNode): if (type(node) == CondTreeNode):
print(treestr.ljust(16), node.weight, ' arrow(s) at [site', node.site, print(treestr.ljust(16), node.weight, ' arrow(s) at [site', node.site,
'in cell', node.x, end='') 'in cell', node.x, end='')
if (not node.depth == 2): if (not node.depth == 2): # tree.depth()
print(end=']\n') print(end=']\n')
else: else:
print('] > ', node.children[0].id, end='\n') print('] > ', node.children[0].id, end='\n')