WIP: Struggling to slide through pipeline (I)

This commit is contained in:
Jean Sirmai 2021-12-14 19:45:09 +01:00
parent d430332c3f
commit 5b1e27d670
Signed by: jean
GPG Key ID: FB3115C340E057E3
5 changed files with 70 additions and 43 deletions

View File

@ -55,31 +55,32 @@
<states id="texte" date="1630000000" author="Here, states are spaces.">
<space id="initial" date="1630000000" author="Une souris verte,">
<arrow site="0" weight="8" x="0"/>
<arrow site="0" weight="6" x="0"/>
<arrow site="1" weight="1" x="0"/>
<arrow site="2" weight="7" x="1"/>
<arrow site="1" weight="1" x="6"/>
<arrow site="1" weight="3" x="6"/>
<arrow site="2" weight="1" x="7"/>
<arrow site="1" weight="4" x="14"/>
<arrow site="0" weight="8" x="14"/>
<arrow site="2" weight="5" x="15"/>
<arrow site="1" weight="2" x="17"/>
<arrow site="2" weight="7" x="18"/>
<arrow site="2" weight="4" x="20"/>
<arrow site="2" weight="9" x="20"/>
<arrow site="0" weight="4" x="20"/>
</space>
</states>
<!-- Model transitions definition (rules) -->
<!-- In this version : <xs:sequence minOccurs="0" maxOccurs="unbounded">-->
<!-- In this version : <xs:sequence minOccurs="1" maxOccurs="unbounded">-->
<!-- Transitions should be edited by hand and written in a 'human-readable' format -->
<conditions id="random walk of dimers" date="1630000000" author="Zazard le lézard !">
<condition site="1" weight="1" node_id="1" parent="0" x="0"/>
<condition site="2" weight="1" node_id="2" parent="1" x="1"/>
<!-- as soon as conditions 1 and 2 are satisfied, a dimer is identified at atation (0,1). -->
<!-- as soon as conditions 1 and 2 are satisfied, a dimer is identified at location (0,1). -->
<condition site="1" weight="0" node_id="3" parent="2" x="2"/>
<!-- as soon as condition 3 is satisfied,

View File

@ -170,7 +170,7 @@
<xs:element name="conditions">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element minOccurs="0" ref="quote"/>
<xs:element ref="condition"/>
</xs:sequence>
@ -180,7 +180,7 @@
<xs:element name="transitions">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element ref="transition"/>
</xs:sequence>
</xs:complexType>

Binary file not shown.

View File

@ -1,9 +1,9 @@
import model
from anytree import Node, AnyNode, NodeMixin, RenderTree, find_by_attr
from anytree.exporter import DotExporter
from ete3 import Tree
# from anytree import Node, AnyNode, NodeMixin, RenderTree, find_by_attr
# from anytree.exporter import DotExporter from ete3 import Tree
# https://stackoverflow.com/questions/51902250/read-data-from-a-file-and-create-a-tree-using-anytree-in-python
# https://stackoverflow.com/questions/51902250/
# read-data-from-a-file-and-create-a-tree-using-anytree-in-python
# https://www.delftstack.com/howto/python/trees-in-python/
# https://python-gtk-3-tutorial.readthedocs.io/en/latest/treeview.html
# https://anytree.readthedocs.io/en/latest/
@ -14,48 +14,50 @@ from ete3 import Tree
conditions_set = set()
for i in range (0, len(model.testmodel.get_conditions().get_conditions_array())):
# TODO cnd.get_coord("y"),...
for i in range(0, len(model.testmodel.get_conditions().get_conditions_array())):
cnd = model.testmodel.get_conditions().get_condition(i)
conditions_set.add((cnd.get_node_self_id(),
cnd.get_node_parent_id(),
cnd.get_coord("x"),
# TODO cnd.get_coord("y"),...
cnd.get_site(),
cnd.get_weight()))
class TreeNode(object):
# TODO self.y = y,...
def __init__(self, id, parent, x, site, weight):
self.id = id
self.parent = parent
self.ch = []
self.x = x
# TODO self.y = y,...
self.site = site
self.weight = weight
def id(self): return id
def id(self):
return id
def add_child(self,ch_id):
def add_child(self, ch_id):
self.ch.append(ch_id)
self.ch = sorted(self.ch, key=id)
l = []
lll = []
for i in conditions_set: # sorted(conditions_set, key=id):
cndt = TreeNode(i[0], i[1], i[2], i[3], i[4]) # TODO y,z,...
l.append(cndt)
lll.append(cndt)
for i in l:
for j in l:
for i in lll:
for j in lll:
if (i.id == j.parent):
i.add_child(j)
print('\n',"Liste des conditions (node_id, parent_id, nb d'enfants, +/- liste des enfants)",'\n')
print('\n', "Liste des conditions (node_id, parent_id, nb d'enfants, +/- liste des enfants)", '\n')
affichage = ''
for i in l:
for i in lll:
affichage = str(i.id) + ' ' + str(i.parent) + ' n=' + str(len(i.ch)) + ' '
if len(i.ch) > 0:
for c in range (0, len(i.ch)):
@ -63,10 +65,8 @@ for i in l:
print(affichage)
##
"""
A = Node("A")
A1 = Node("A1", parent=A)
A2 = Node("A2", parent=A)
@ -74,7 +74,7 @@ A21 = Node("A21", parent=A2)
root = Node([0])
"""
https://python-gtk-3-tutorial.readthedocs.io/en/latest/treeview.html
@ -95,8 +95,6 @@ with open('input.txt', 'r') as f:
for pre, _, node in RenderTree(root):
print("%s%s" % (pre, node.name))
"""
##
@ -105,13 +103,19 @@ with open('input.txt', 'r') as f:
##
print("\n*** Conditions tree ***")
print(type(model.testmodel.get_conditions()))
print("\n")
print(model.testmodel.get_conditions().get_condition(0).get_coord('x'))
print("\n")
print()
sp = model.testmodel.get_states().get_space(0)
size = model.testmodel.get_parameters().spaceparam.get_dimension().get_x()
nb_sites = int (model.testmodel.get_parameters().spaceparam.get_site_multiplicity())
nb_arrows = int (model.testmodel.get_states().get_space(0).get_nb_arrows())
nb_sites = int(model.testmodel.get_parameters().spaceparam.get_site_multiplicity())
nb_arrows = int(model.testmodel.get_states().get_space(0).get_nb_arrows())
print()
print("space size = ", size, " nb de sites par cellule = ", nb_sites,
" nb total de flèches dans l'espace = ", nb_arrows)
print(' | ',end=' ')
@ -126,19 +130,20 @@ print(' | ',end=' ')
# 2) pas de node sans un node_parent_id
for n in range (0, size + 1):
for s in range (0, nb_sites):
for n in range(0, size + 1):
for s in range(0, nb_sites):
arr = 0
for a in range (0, nb_arrows):
if (sp.get_arrow(a).get_coord("x") == n and sp.get_arrow(a).get_site() == s):
for a in range(0, nb_arrows):
if (sp.get_arrow(a).get_coord("x") == n
and sp.get_arrow(a).get_site() == s):
arr = sp.get_arrow(a).get_weight()
if arr > 0:
print(str(arr),end=' ')
else:
print('.',end=' ')
print(' | ',end=' ')
print('\n ',end=' ')
print('\n ' + ' ' * nb_sites * 2,end='')
for k in range (0, size + 1):
if k < 9: print(k+1,end=' ')
else: print(k+1,end=' ')
for k in range(0, size + 1):
if k < 9: print(k+1,end=' '+ ' ' * nb_sites * 2)
else: print(k+1,end=' '+ ' ' * nb_sites * 2)

View File

@ -279,8 +279,27 @@ class States:
def get_space(self, i):
return self.__space[i]
## Conditions
## Conditions Tree
class TreeNode(object):
def __init__(self, id, parent, x, site, weight):
self.id = id
self.parent = parent
self.ch = []
self.x = x
# TODO self.y = y,...
self.site = site
self.weight = weight
def id(self): return id
def add_child(self,ch_id):
self.ch.append(ch_id)
self.ch = sorted(self.ch, key=id)
## Conditions
class Condition:
def __init__(self, node):
@ -387,7 +406,6 @@ class Arrow:
def set_weight(self, weight):
self.node.attrib["weight"] = str(weight)
class Model:
def __init__(self, modelpath, schemapath):
@ -430,6 +448,9 @@ class Model:
def get_states(self):
return States(self.__states)
def get_tree(self):
return self.tree
def get_conditions(self):
return Conditions(self.__conditions)
@ -440,8 +461,8 @@ class Model:
self.tree.write("../models/" + name + ".xml", encoding="utf-8")
modelPath = "../models/dimers random walk.xml"
schemaPath = "../schemas/models_0.2.1.xmls"
modelPath = "../models/dimers random walk.automat.xml"
schemaPath = "../schemas/models_0.2.1.automat.xmls"
testmodel = Model(modelPath, schemaPath)