WIP : First glimpse at a conditions tree
This commit is contained in:
parent
71ddf7dd3d
commit
9261bc03cf
|
@ -28,13 +28,13 @@
|
|||
<!-- 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="29"/>
|
||||
<dimension x="18"/>
|
||||
|
||||
<!-- Site_multiplicity = number of sites in a space unit. -->
|
||||
<!-- Each site points towards a neighbouring space unit. -->
|
||||
<!-- Several arrows can be stacked in the same site. -->
|
||||
|
||||
<site_multiplicity>5</site_multiplicity>
|
||||
<site_multiplicity>3</site_multiplicity>
|
||||
|
||||
</space-param>
|
||||
|
||||
|
@ -60,12 +60,11 @@
|
|||
<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="15"/>
|
||||
<arrow site="0" weight="8" x="15"/>
|
||||
<arrow site="2" weight="1" x="16"/>
|
||||
<arrow site="1" weight="1" x="28"/>
|
||||
<arrow site="2" weight="1" x="29"/>
|
||||
<arrow site="4" weight="9" x="29"/>
|
||||
<arrow site="1" weight="1" 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="7" x="18"/>
|
||||
|
||||
</space>
|
||||
|
||||
|
|
Binary file not shown.
|
@ -1,4 +1,69 @@
|
|||
import model
|
||||
from anytree import Node, AnyNode, NodeMixin, RenderTree
|
||||
from anytree.exporter import DotExporter
|
||||
from ete3 import Tree
|
||||
|
||||
cset = {(0,0,'root')} # TODO 1) get_node_self_id <> 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)
|
||||
|
||||
|
||||
|
|
23
src/model.py
23
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
|
||||
|
|
Loading…
Reference in New Issue