From d430332c3fd1b374dc7f97b6dd91538f7fed31b1 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Mon, 13 Dec 2021 19:09:12 +0100 Subject: [PATCH] =?UTF-8?q?WIP:=20Space=20<>=20acc=C3=A8s=20direct=20(par?= =?UTF-8?q?=20des=20"get")=20aux=20donn=C3=A9es=20pars=C3=A9es=20de=20XML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/dimers random walk.xml | 9 ++- src/__pycache__/model.cpython-39.pyc | Bin 16858 -> 17885 bytes src/glimpse.py | 112 +++++++++++++++------------ src/model.py | 56 ++++++++++---- 4 files changed, 108 insertions(+), 69 deletions(-) diff --git a/models/dimers random walk.xml b/models/dimers random walk.xml index 62c20b5..1753767 100644 --- a/models/dimers random walk.xml +++ b/models/dimers random walk.xml @@ -28,7 +28,7 @@ - + @@ -60,11 +60,12 @@ - + - - + + + diff --git a/src/__pycache__/model.cpython-39.pyc b/src/__pycache__/model.cpython-39.pyc index 79fb21d4670374b5810e01c7a021356cafc79ee0..56fcbb6284a5e2aec2c0f71731ad3eca49fe8403 100644 GIT binary patch delta 2916 zcmb7G4Qx}_74~uLm*?1ib^=apC$Wj+IB`gv1j0{g6Os*Rpn5cXTO0_h~Yku z5J&`VT3W{1wK-*MKt=yjN=du1l>SgkTd7hj(59kpsuro8+DV->b(N-RowTuO=UhA4 zXfsW<^*&$Ud(OG%=ey^==`r}|C};_%v&clBb;*|#di{CrxE;q_O?cHAg4OtiGk_EJ z9=HwrG!MERMfmArAD(iR!ng26&1<(AdbTe!G^mT)Ng{}T$5x1=;RxZEnj8D;Y$V&H zIcBB$(y2}OYb}Jw92w7dXjj9`d&BGIg7Tg{Gorv4B;28M?5uVBS(E``>5C`iT;5dHfO~VQ7 z^7$KOPDqPCJO+9=R)c+=bz0cyA9?#|cwQN&<8hYAr_;%{V+KBM_u^$r=9q6iJb~}~ ze6i#=Gk(qKtuoU4^{2mXobtmf9QEfuzg0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)8jxItv~@D&E`GMFG<9RY{LTDFpcXvoRy3HqQaGZy*{S#Z@@nOus?l*$Qg1PchB zCs;_Zh#+ZnzUdnkTuRf!S(9B=qi|?Pmsl<;!`zN==(8rn!Hg-9waDCtpR7U9FpUOo zS(8{Y44YE4=%Kl(D(Uvin0g620KGAO^I;+@5fp5bfo#qeFzBr?j%(f(yR_iw({^0H z?BC>bI|RvzRw;|XMW7=nCRh#oGOU&c90Go_fPkwB(}YP4z|zaqQXQFS8ONbEZYguX zyK&jJ6U3cZjIrF`?(2~KfevR2X6(jvkQ<-IJUlYFA0u`svPy}O>)@VsI*i5Nu{5Ja zqODk|l{a{reH%QIrycquW7rw^($>j7fue*C_957a=Cm4y`H^RGAH6OfbNW zL^~UUzZ2cy$I&?KMtfnR6BgO+>~mCLXr6XwQ+%7{QU)m;{uf^P>{SBraU~n zvT2>KIS6-is^Qm^G@+F|y)cv?$8JDgYGnjQ5768?CG8};gNUg&=nusp-5<0hVhBbLvReeHlgql5ahVA) znE3*0ga?`FECOO@285R>bTw_Cj-T=7KtS>u;M~l5q@9nog#~>kNOM+4Z6o3qgwsli zPMoxz@A+jxt(N^kpBYX%m!k`9#Bi!QyvyfrX$?+=n9=?;tq%8P8r!UkVJ-i(=Vdtz` z;Q;xB>V(apZ4PvJ{Xsm|Ilyw=>>%Hq)?5qAgRQyqO`Oe3cZmEBQ?BU!ICLy3d) zMcVwmp|}HF(L(qvzfO2N6nDGX3a$bzz7mB6Rcw$8IZ-eb--@w+1;mgFSn|RN@xsT9r=nz1>`5Wc{$aq)MP`N;<_S|0>Zlfbh~~0v&Sc zG@qoiCI|72l@Gzz(xn3Rk93Bc?w1 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=' ') diff --git a/src/model.py b/src/model.py index 0c09a78..705fd70 100644 --- a/src/model.py +++ b/src/model.py @@ -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")