From 9261bc03cfb0f24cdb188a9a44de372c7a176ce8 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sat, 11 Dec 2021 09:54:52 +0100 Subject: [PATCH] WIP : First glimpse at a conditions tree --- models/dimers random walk.xml | 15 +++--- src/__pycache__/model.cpython-39.pyc | Bin 16531 -> 16854 bytes src/glimpse.py | 67 +++++++++++++++++++++++++++ src/model.py | 23 ++++++--- 4 files changed, 90 insertions(+), 15 deletions(-) diff --git a/models/dimers random walk.xml b/models/dimers random walk.xml index 89bb2eb..62c20b5 100644 --- a/models/dimers random walk.xml +++ b/models/dimers random walk.xml @@ -28,13 +28,13 @@ - + - 5 + 3 @@ -60,12 +60,11 @@ - - - - - - + + + + + diff --git a/src/__pycache__/model.cpython-39.pyc b/src/__pycache__/model.cpython-39.pyc index d04e8cba041364abccf9da8e87ec8da020537f4f..6002d349f3a5b48d86d14321aaa2e5118e9b9b02 100644 GIT binary patch delta 1623 zcmZ`(O;A%;6!wJh$oTpmOfcnvffGH+Hop^RtBqarc7!AhKWhIFVaS6 z6@MyAaL1a@IA9aoI-MDbl6I6r)Q@rX1^;xa z(E?@)Qe~-NV|iy0A~^4CHbRVv5PvxLN?(#Q&sklCyIh-Pu@tCZiJZsz@t*`J$~STz z=Q%I@?z#`s1UY}ooi)7UUbLQ|<=0&NU}6^1r*Kix@b|l+) z1hZ**%y-Oi?t{ks>Q(r9gQMG8ik6A8cq+@&T2lsLUnZ@Rp-Ak~(!^#du^wwFV#&N^ zdEEC6``s%36SlQY67+ErCrO+pahAk65*J8ZBypL<99<>k(A(AwIU?M&*MoCyGX@uO zf(v1f6EFEZRqP6R2on1hYQUj4&G(k&sFiBh#hsLl&?`4!zoXj3uHvFu3)H>?F%)Gi znhTTxH7x^#H~dXCA`L;r?-ZtaEr_$V*{$B;@QCLF}3;DAJv$G#Dp#Ej2zHn`J#f@=sH>Lo#x zDE<}flW9-PDLW;si9In)c6?%{F*U4-Oe6SP$8Nbax@=ll6T?PvXJ??{|4B$aZKQPf zQ8g-8EGA3E+doUt8}hQV2#~=uoBviKWv$Y2y6X;1qGwA1F5uHG6EKSpLLXwJyGx=s zl-;G~DKb$j{l#efP*%_5SFt0sOCqYUd!oy?Le)^<2z#K25Z=gp?Fs(~ wH}OR{11TKrDZ1&AX9AiYP)3g)%aIT$#0^GQ!xE@%O)1r?qFPl=4bb!YFQ*BpV*mgE delta 1477 zcmZ`(Uu;ul6yGWBU32exm3GbUwvGh0w$#B!*KRF;wt;mnwZhoyS zto+;fGo4Pi9%O6~BQFRT4Ty;$Jjk1gKJ5WDO-y|7l>|bfZ^m=JOJOc}lkb=F-E+R* zIp;g)e7~Fq90xt+a;X*c`D?#TeI2-^-}FK0_7A>EI~>N>R`1gelTK(1LpT#Oye5f1 z(#k0WPMh84RD@X!yoz;ePAX}(Gx1*7hj-T`l@Z?8>_9r79?rIuEikdJ!~JoYF7(9HG}AR}xo0%1 zo=;P@z}c#XVtqBPT<>3}GWSSInA!a5C8w(Y>)bNH-dMyvv)uh`Ih!HNs_FSO?A$Ww z3F)GRSy~x3Fvwd!!O}Rx8HRHVA2NKz@Cn1G3`GXy5 zrO=MQhxaHK`S2i8pE`y}+>D8~h$eqp4Jun{jx=pdyQG!oxcz@?o2o0Rd6CNIWT`1Q zHWBRvZyR_lVpIw_X>*(ayo`4!tFed=265bD;QFWv+c6#u;`VSA*l@O{zEWIb0&5hn zM7^*RzmImqW&ArDteGcOH^;#(%IP^3nvi*pny+&PIe{~ev!mAT(lc5If29bGv pas de doublon + # TODO 2) un node_parent_id existe toujours + +for i in range (0, len(model.testmodel.get_conditions().get_condition_array())): + cnd = model.testmodel.get_conditions().get_condition(i) + cset.add((cnd.get_node_self_id(), cnd.get_node_parent_id(), cnd.get_weight())) # TODO coord + + +class TreeNode(object): + + def __init__(self, id, parent, weight, coord): + self.id = id + self.parent = parent + self.children = None + self.weight = weight + self.coord = coord + self.ch = [] + + def id(self): return id + + def add_child(self,ch_id): + self.ch.append(ch_id) + self.ch = sorted(self.ch, key=id) + + +l = [] + +tnn = TreeNode(0, 0, 0, 0) + +for i in cset: # sorted(cset, key=id): + cndt = TreeNode(i[0], i[1], i[2], 0) + l.append(cndt) + +for i in l: + for j in l: + if (i.id == j.parent): + i.add_child(j) + else: + i.add_child(tnn) + +for i in l: + print(i.id,' ',i.parent,' [',i.ch[0].id,' ',i.ch[1].id,' ',i.ch[2].id,' ',i.ch[3].id,' ',i.ch[4].id,']') + + + + + + + + +## + + + + + + + + + + sp = model.testmodel.get_states().get_space(0) @@ -50,3 +115,5 @@ for i in range (0, size + nb_sites - 1): print (cells) print() print (space) + + diff --git a/src/model.py b/src/model.py index 411b5d1..3328bc7 100644 --- a/src/model.py +++ b/src/model.py @@ -280,16 +280,16 @@ class Condition: def set_weight(self, weight): self.node.attrib["weight"] = str(weight) - def get_node_id(self): + def get_node_self_id(self): return int(self.node.get("node_id")) - def set_node_id(self, node_id): + def set_node_self_id(self, node_id): self.node.attrib["node_id"] = str(node_id) - def get_parent(self): + def get_node_parent_id(self): return int(self.node.get("parent")) - def set_parent(self, parent): + def set_node_parent_id(self, parent): self.node.attrib["parent"] = str(parent) @@ -302,6 +302,11 @@ class Conditions: if(child.tag == "condition"): self.__conditions.append(Condition(child)) + def get_condition(self, i): + return self.__conditions[i] + + def get_condition_array(self): + return self.__conditions class Transition: __arrows = [] @@ -323,12 +328,12 @@ class Transitions: self.node = node for child in node: if(child.tag == "transition"): - self.__transition.append(Transition(child)) + self.__transitions.append(Transition(child)) def get_transition(self, i): return self.__transitions[i] - def get_transition_array(self, i): + def get_transition_array(self): return self.__transitions ## Model @@ -385,7 +390,7 @@ class Model: self.__states = child if(child.tag == "conditions"): self.__conditions = child - if(child.tag == "transition"): + if(child.tag == "transitions"): self.__transitions = child def get_identity(self): @@ -415,4 +420,8 @@ schemaPath = "../schemas/models_0.2.1.xmls" testmodel = Model(modelPath, schemaPath) +# print(testmodel.get_conditions().get_condition(0).get_weight()) + + + # TODO weight_max