WIP: Space <> accès direct (par des "get") aux données parsées de XML

This commit is contained in:
Jean Sirmai 2021-12-13 19:09:12 +01:00
parent a009d0e402
commit d430332c3f
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 108 additions and 69 deletions

View File

@ -28,7 +28,7 @@
<!-- loop_on_max="true" anything moved beyond max reenters at the zero of space-->
<!-- loop_on_max="false" anything moved beyond max is lost-->
<dimension x="18"/>
<dimension x="20"/>
<!-- Site_multiplicity = number of sites in a space unit. -->
<!-- Each site points towards a neighbouring space unit. -->
@ -60,11 +60,12 @@
<arrow site="2" weight="7" x="1"/>
<arrow site="1" weight="1" x="6"/>
<arrow site="2" weight="1" x="7"/>
<arrow site="1" weight="1" x="14"/>
<arrow site="1" weight="4" x="14"/>
<arrow site="0" weight="8" x="14"/>
<arrow site="2" weight="1" x="15"/>
<arrow site="1" weight="1" x="17"/>
<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"/>
</space>

Binary file not shown.

View File

@ -1,8 +1,13 @@
import model
from anytree import Node, AnyNode, NodeMixin, RenderTree
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://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/
# TODO Contrôles de cohérence des données
# 1) node_id <> pas de doublon
# 2) pas de node sans un node_parent_id
@ -46,31 +51,58 @@ for i in l:
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')
affichage = ''
for i in l:
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)):
affichage = affichage + str(i.ch[c].id) + ', '
affichage += str(i.ch[c].id) + ', '
print(affichage)
##
A = Node("A")
A1 = Node("A1", parent=A)
A2 = Node("A2", parent=A)
A21 = Node("A21", parent=A2)
root = Node([0])
"""
https://python-gtk-3-tutorial.readthedocs.io/en/latest/treeview.html
A
A1
A2
A21
with open('input.txt', 'r') as f:
lines = f.readlines()[1:]
root = Node(lines[0].split(" ")[0])
for line in lines:
line = line.split(" ")
Node("".join(line[1:]).strip(), parent=find_by_attr(root, line[0]))
for pre, _, node in RenderTree(root):
print("%s%s" % (pre, node.name))
"""
##
##
@ -78,7 +110,11 @@ 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())
weight = int (model.testmodel.get_states().get_space(0).get_arrow(0).get_weight())
print()
print("space size = ", size, " nb de sites par cellule = ", nb_sites,
" nb total de flèches dans l'espace = ", nb_arrows)
print(' | ',end=' ')
# TODO Contrôles de cohérence des données
# condition et arrow
@ -89,42 +125,20 @@ weight = int (model.testmodel.get_states().get_space(0).get_arrow(0).get_weight(
# 1) parent <= condition.node_id max value (donc deux lectures)
# 2) pas de node sans un node_parent_id
space = []
cells = []
sites = []
weights = []
arrows = []
extremite = 1
for x in range (0, nb_arrows):
arrows.append(sp.get_arrow(x).get_coord("x"))
sites.append(sp.get_arrow(x).get_site())
weights.append(sp.get_arrow(x).get_weight())
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):
arr = sp.get_arrow(a).get_weight()
if arr > 0:
print(str(arr),end=' ')
else:
print('.',end=' ')
print(' | ',end=' ')
print('\n ',end=' ')
for i in range (0, (size + 1) * (nb_sites + 1) + extremite): space.append(0)
print()
print("space size = ", size, " nb de sites par cellule = ", nb_sites,
" nb total de flèches dans l'espace = ", nb_arrows)
print()
print (sites)
print (weights)
print (arrows)
print()
for i in range (0, size + 1): cells.append('')
for i in range (0, size + nb_sites - 1):
if i <= size + extremite: # ad hoc ! (j'en conviens...)
space[i * (nb_sites + 1)] = ''
for k in range (0, nb_arrows):
if arrows[k] == i:
cells[i] = i # cette cellule contient au moins une flèche
space[i * (nb_sites + 1) + sites[k] + 1] = weights[k]
# nombre de flèches dans ce site
print (cells)
print()
print (space)
"""
for k in range (0, size + 1):
if k < 9: print(k+1,end=' ')
else: print(k+1,end=' ')

View File

@ -66,30 +66,30 @@ class Identity:
def get_name(self):
return self.__name.text
def get_owner(self):
return self.__owner.text
def get_owner_id(self):
return self.__owner_id.text
def get_date(self):
return DT.datetime.fromtimestamp(int(self.__date.text))
def get_version(self):
return self.__version.text
def set_name(self, text):
self.__name.text = text
def get_owner(self):
return self.__owner.text
def set_owner(self, text):
self.__owner.text = text
def get_owner_id(self):
return self.__owner_id.text
def set_owner_id(self, text):
self.__owner_id.text = text
def get_date(self):
return DT.datetime.fromtimestamp(int(self.__date.text))
def set_date(self, date):
self.__date.text = str(int(date.timestamp()))
def get_version(self):
return self.__version.text
def set_version(self, text):
self.__version.text = text
@ -143,6 +143,9 @@ class Spaceparam:
def get_dimension(self):
return self.__dimension
def set_dimension(self, value):
self.__dimension = str(value) # TODO Assert
class Axis:
def __init__(self, node):
@ -151,9 +154,14 @@ class Axis:
def get_name(self):
return self.node.attrib["name"]
def set_name(self, value):
pass # TODO (The user can create a complete model from scratch.)
def get_size(self):
return int(self.node.attrib["size"])
def set_size(self, value):
pass # TODO (The user can create a complete model from scratch.)
class Dimension:
__axis = []
@ -164,6 +172,16 @@ class Dimension:
def get_x(self):
return int(self.node.get("x"))
def set_x(self, value):
self.node.attrib["x"] = value # TODO Assert
def get_y(self):
return int(self.node.get("y"))
def set_y(self, value):
pass
# TODO z, u, v, w,...
class Parameters:
@ -184,12 +202,12 @@ class Parameters:
def get_author(self):
return self.node.attrib["author"]
def get_date(self):
return self.node.attrib["date"]
def set_author(self, text):
self.node.attrib["author"] = text
def get_date(self):
return self.node.attrib["date"]
def set_date(self, text):
self.node.attrib["date"] = text
@ -209,6 +227,9 @@ class Object:
def get_arrow(self, i):
return self.__arrows[i]
def set_arrow(self, i, value):
self.__arrows[i] = value # TODO Assert
class Objects:
__objects = []
@ -222,6 +243,9 @@ class Objects:
def get_object(self, i):
return self.__objects[i]
def set_object(self, i, Object):
self.__objects[i] = Object # TODO Assert
## States
@ -412,7 +436,7 @@ class Model:
def get_transitions(self):
return Transitions(self.__transitions)
def saveas(self, name):
def save_as(self, name):
self.tree.write("../models/" + name + ".xml", encoding="utf-8")