WIP: premières explorations.

This commit is contained in:
Jean Sirmai 2022-01-09 12:01:01 +01:00
parent 5751a6cd72
commit 75c63e8e24
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 78 additions and 12 deletions

View File

@ -92,17 +92,22 @@
the neighbouring space unhit to East of the dimer is empty
and the dimer identified by conditions (1,2) can be moved to East. -->
<condition site="2" weight="0" node_id="4" parent="2" x="-1"/>
<condition site="2" weight="0" node_id="4" parent="2" x="1"/>
<!-- as soon as condition 4 is satisfied,
the neighbouring space unit to West of the dimer is empty
and the dimer identified by conditions (1,2) can be moved to West. -->
<condition site="2" weight="1" node_id="5" parent="3" x="1"/>
<condition site="2" weight="0" node_id="6" parent="4" x="1"/>
<condition site="2" weight="2" node_id="7" parent="3" x="1"/>
<condition site="0" weight="3" node_id="8" parent="6" x="1"/>
<condition site="0" weight="4" node_id="9" parent="6" x="1"/>
</conditions>
<transitions>
<transition id="move_a_dimer_to_east" date="1630000000" author="Pas moi..."
parent="3" probability="1">
parent="7" probability="1">
<arrow site="1" weight="0" x="0"/>
<arrow site="2" weight="0" x="1"/>
@ -112,7 +117,27 @@
</transition>
<transition id="move_a_dimer_to_west" date="1630000000" author="Ni moi !"
parent="4" probability="1">
parent="8" probability="1">
<arrow site="1" weight="0" x="0"/>
<arrow site="2" weight="0" x="1"/>
<arrow site="2" weight="1" x="0"/>
<arrow site="1" weight="1" x="1"/>
</transition>
<transition id="do_anything_you_want" date="1630000000" author="Ni moi !"
parent="9" probability="1">
<arrow site="1" weight="0" x="0"/>
<arrow site="2" weight="0" x="1"/>
<arrow site="2" weight="1" x="0"/>
<arrow site="1" weight="1" x="1"/>
</transition>
<transition id="do_nothing" date="1630000000" author="Ni moi !"
parent="5" probability="1">
<arrow site="1" weight="0" x="0"/>
<arrow site="2" weight="0" x="1"/>

Binary file not shown.

View File

@ -1,5 +1,5 @@
# https://anytree.readthedocs.io/en/latest/_modules/anytree/node/nodemixin.html
from anytree import NodeMixin, RenderTree, LevelOrderIter
from anytree import NodeMixin, LevelOrderIter # , RenderTree
import model
# TODO Contrôles de cohérence des données
@ -46,7 +46,7 @@ for i in range(0, len(model.testmodel.get_conditions().get_all())):
condition.get_site(),
condition.get_weight())
conditions_set.add(tmp)
if (tmp.parent_id == 0):
if tmp.parent_id == 0:
root = tmp
for i in range(0, len(model.testmodel.get_transitions().get_all())):
@ -57,26 +57,33 @@ for i in range(0, len(model.testmodel.get_transitions().get_all())):
for i in conditions_set:
for j in conditions_set:
if ((i != j) & (i.parent_id == j.id)):
if (i != j) & (i.parent_id == j.id):
i.is_adopted_by(j)
for condition_node in LevelOrderIter(root):
if condition_node.is_leaf:
for transition_node in transitions_set:
if (str(condition_node.id) == transition_node.parent_id):
if str(condition_node.id) == transition_node.parent_id:
transition_node.is_adopted_by(condition_node)
"""
## print tree
for pre, fill, node in RenderTree(root):
treestr = u"%s%s" % (pre, node.id)
if (type(node) == CondTreeNode):
print(treestr.ljust(16), node.weight, ' arrow(s) at [site', node.site,
if type(node) == CondTreeNode:
print(treestr.ljust(19), node.weight, ' arrow(s) at [site', node.site,
'in cell', node.x, end='')
if (not node.depth == 2): # tree.depth()
if not node.depth == 2: # tree.depth()
print(end=']\n')
else:
print('] > ', node.children[0].id, end='\n')
print('] --> ', node.children[0].id, end='\n')
"""
## get the tree
def get_tree():
return root
print('\nNext step: single rule extraction from tree. 😃️')
# print([node.id for node in LevelOrderIter(root) if node.is_leaf])

34
src/show_tree.py Normal file
View File

@ -0,0 +1,34 @@
# from ete2 import Tree
from anytree import RenderTree
import rules_tree
tree = rules_tree.get_tree()
print('type: ', type(tree))
print(tree.depth, ' < depth')
print(tree.is_leaf, ' < is_leaf')
print(tree.is_root, ' < is_root')
print(tree.height, ' < height')
print(tree.parent, ' < parent')
print(tree.ancestors, ' < ancestors')
print(tree.anchestors, ' < anchestors')
print(tree.siblings, ' < siblings')
print(len(tree.leaves), ' < len(tree.leaves)')
print(len(tree.path), ' < len(tree.path)')
print('path: ', tree.path)
print('children: ', tree.children)
print('descendants[0]: ', tree.descendants[0])
print('\n to fix: (leaves)', end='\n\n')
for pre, fill, node in RenderTree(tree):
treestr = u"%s%s" % (pre, node.id)
if type(node) == rules_tree.CondTreeNode:
print(treestr.ljust(19), node.weight, ' arrow(s) at [site', node.site,
'in cell', node.x, end='')
if not node.depth == 2: # tree.depth()
print(end=']\n')
else:
print('] --> ', node.children[0].id, end='\n')
print('\nNext step: single rule extraction from tree. 😃️')