WIP: Adding Transitions to the Conditions Tree: first approach.
This commit is contained in:
parent
4cec4b1855
commit
46db1e5ad6
|
@ -109,17 +109,17 @@
|
||||||
<arrow site="1" weight="1" x="1"/>
|
<arrow site="1" weight="1" x="1"/>
|
||||||
<arrow site="2" weight="1" x="2"/>
|
<arrow site="2" weight="1" x="2"/>
|
||||||
|
|
||||||
</transition>
|
</transition>
|
||||||
|
|
||||||
<transition id="move_a_dimer_to_west" date="1630000000" author="Ni moi !"
|
<transition id="move_a_dimer_to_west" date="1630000000" author="Ni moi !"
|
||||||
parent="4" probability="1">
|
parent="4" probability="1">
|
||||||
|
|
||||||
<arrow site="1" weight="0" x="0"/>
|
<arrow site="1" weight="0" x="0"/>
|
||||||
<arrow site="2" weight="0" x="1"/>
|
<arrow site="2" weight="0" x="1"/>
|
||||||
<arrow site="2" weight="1" x="0"/>
|
<arrow site="2" weight="1" x="0"/>
|
||||||
<arrow site="1" weight="1" x="1"/>
|
<arrow site="1" weight="1" x="1"/>
|
||||||
|
|
||||||
</transition>
|
</transition>
|
||||||
|
|
||||||
</transitions>
|
</transitions>
|
||||||
|
|
||||||
|
|
Binary file not shown.
17
src/model.py
17
src/model.py
|
@ -369,6 +369,21 @@ class Transition:
|
||||||
if(child.tag == "arrow"):
|
if(child.tag == "arrow"):
|
||||||
self.__arrows.append(Arrow(child))
|
self.__arrows.append(Arrow(child))
|
||||||
|
|
||||||
|
def get_id(self):
|
||||||
|
return self.node.attrib["id"]
|
||||||
|
|
||||||
|
def get_date(self):
|
||||||
|
return self.node.attrib["date"]
|
||||||
|
|
||||||
|
def get_author(self):
|
||||||
|
return self.node.attrib["author"]
|
||||||
|
|
||||||
|
def get_parent(self):
|
||||||
|
return self.node.attrib["parent"]
|
||||||
|
|
||||||
|
def get_probability(self):
|
||||||
|
return self.node.attrib["probability"]
|
||||||
|
|
||||||
def get_arrow(self, i):
|
def get_arrow(self, i):
|
||||||
return self.__arrows[i]
|
return self.__arrows[i]
|
||||||
|
|
||||||
|
@ -385,7 +400,7 @@ class Transitions:
|
||||||
def get_transition(self, i):
|
def get_transition(self, i):
|
||||||
return self.__transitions[i]
|
return self.__transitions[i]
|
||||||
|
|
||||||
def get_transitiosn_array(self):
|
def get_transitions_array(self):
|
||||||
return self.__transitions
|
return self.__transitions
|
||||||
|
|
||||||
## Model
|
## Model
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# https://anytree.readthedocs.io/en/latest/_modules/anytree/node/nodemixin.html
|
# https://anytree.readthedocs.io/en/latest/_modules/anytree/node/nodemixin.html
|
||||||
from anytree import NodeMixin, RenderTree
|
from anytree import NodeMixin, RenderTree, LevelOrderIter
|
||||||
import model
|
import model
|
||||||
|
|
||||||
# TODO Contrôles de cohérence des données
|
# TODO Contrôles de cohérence des données
|
||||||
|
@ -8,6 +8,7 @@ import model
|
||||||
|
|
||||||
conditions_set = set()
|
conditions_set = set()
|
||||||
conditions_list = []
|
conditions_list = []
|
||||||
|
transitions_set = set()
|
||||||
|
|
||||||
for i in range(0, len(model.testmodel.get_conditions().get_conditions_array())):
|
for i in range(0, len(model.testmodel.get_conditions().get_conditions_array())):
|
||||||
condition = model.testmodel.get_conditions().get_condition(i)
|
condition = model.testmodel.get_conditions().get_condition(i)
|
||||||
|
@ -18,6 +19,12 @@ for i in range(0, len(model.testmodel.get_conditions().get_conditions_array())):
|
||||||
condition.get_weight()))
|
condition.get_weight()))
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(0,
|
||||||
|
len(model.testmodel.get_transitions().get_transitions_array())):
|
||||||
|
transition = model.testmodel.get_transitions().get_transition(i)
|
||||||
|
transitions_set.add((transition.get_id(), transition.get_parent()))
|
||||||
|
|
||||||
|
|
||||||
class CondTreeNode(NodeMixin):
|
class CondTreeNode(NodeMixin):
|
||||||
def __init__(self, id, x, site, weight, parent_node_id):
|
def __init__(self, id, x, site, weight, parent_node_id):
|
||||||
super(CondTreeNode, self).__init__()
|
super(CondTreeNode, self).__init__()
|
||||||
|
@ -30,20 +37,48 @@ class CondTreeNode(NodeMixin):
|
||||||
|
|
||||||
def add_parent_node(self, parent_node):
|
def add_parent_node(self, parent_node):
|
||||||
self.parent = parent_node
|
self.parent = 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)
|
||||||
|
|
||||||
|
|
||||||
|
class TransTreeNode(NodeMixin):
|
||||||
|
def __init__(self, parent_node_id):
|
||||||
|
super(TransTreeNode, self).__init__()
|
||||||
|
self.parent_node_id = parent_node_id
|
||||||
|
self.parent = 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
|
||||||
|
|
||||||
|
|
||||||
for i in conditions_set: # sorted(conditions_set, key=i.id):
|
for i in conditions_set: # sorted(conditions_set, key=i.id):
|
||||||
condition = CondTreeNode(i[0], i[2], i[3], i[4], i[1]) # TODO y,z,...
|
condition = CondTreeNode(i[0], i[2], i[3], i[4], i[1]) # TODO y,z,...
|
||||||
conditions_list.append(condition)
|
conditions_list.append(condition)
|
||||||
|
|
||||||
|
root = 0
|
||||||
|
|
||||||
for i in conditions_list:
|
for i in conditions_list:
|
||||||
if (i.parent is None):
|
if (i.parent is None):
|
||||||
for j in conditions_list:
|
for j in conditions_list:
|
||||||
if (i.parent_node_id == j.id):
|
if (i.parent_node_id == j.id):
|
||||||
i.add_parent_node(j)
|
i.add_parent_node(j)
|
||||||
|
else:
|
||||||
|
root = j
|
||||||
|
|
||||||
for pre, fill, node in RenderTree(conditions_list[3]):
|
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 pre, fill, node in RenderTree(root):
|
||||||
treestr = u"%s%s" % (pre, node.id)
|
treestr = u"%s%s" % (pre, node.id)
|
||||||
print(treestr.ljust(16), ' n =', node.weight,
|
print(treestr.ljust(16), node.weight, ' arrow(s) at [site', node.site,
|
||||||
' at (site', node.site, 'in cell', node.x, ')')
|
'in cell', node.x, end=']\n')
|
||||||
|
|
||||||
|
# print([node.id for node in LevelOrderIter(root) if node.is_leaf])
|
||||||
|
|
Loading…
Reference in New Issue