WIP: optimisation algo.

This commit is contained in:
Jean Sirmai 2022-01-08 16:31:12 +01:00
parent fe668f3720
commit a78e3f7bb6
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 36 additions and 38 deletions

Binary file not shown.

View File

@ -353,10 +353,10 @@ class Conditions:
if(child.tag == "condition"): if(child.tag == "condition"):
self.__conditions.append(Condition(child)) self.__conditions.append(Condition(child))
def get_condition(self, i): def get_one(self, i):
return self.__conditions[i] return self.__conditions[i]
def get_conditions_array(self): def get_all(self):
return self.__conditions return self.__conditions
@ -397,10 +397,10 @@ class Transitions:
if(child.tag == "transition"): if(child.tag == "transition"):
self.__transitions.append(Transition(child)) self.__transitions.append(Transition(child))
def get_transition(self, i): def get_one(self, i):
return self.__transitions[i] return self.__transitions[i]
def get_transitions_array(self): def get_all(self):
return self.__transitions return self.__transitions
## Model ## Model

View File

@ -6,24 +6,6 @@ import model
# 1) node_id <> pas de doublons # 1) node_id <> pas de doublons
# 2) tout node doit avoir un node_parent_id # 2) tout node doit avoir un node_parent_id
conditions_set = set()
conditions_list = []
transitions_set = set()
for i in range(0, len(model.testmodel.get_conditions().get_conditions_array())):
condition = model.testmodel.get_conditions().get_condition(i)
conditions_set.add((condition.get_node_self_id(),
condition.get_node_parent_id(),
condition.get_coord("x"), # TODO y,z,...
condition.get_site(),
condition.get_weight()))
for i in range(0,
len(model.testmodel.get_transitions().get_transitions_array())):
transition = model.testmodel.get_transitions().get_transition(i)
transitions_set.add((transition.get_id(), transition.get_parent()))
class CondTreeNode(NodeMixin): class CondTreeNode(NodeMixin):
def __init__(self, id, x, site, weight, parent_node_id): def __init__(self, id, x, site, weight, parent_node_id):
@ -36,8 +18,8 @@ class CondTreeNode(NodeMixin):
self.weight = weight self.weight = weight
def add_parent_node(self, parent_node): def add_parent_node(self, parent_node):
print('orphan node ', self.id, ' is adopted by node ', parent_node.id)
self.parent = parent_node self.parent = parent_node
# print('orphan node ', self.id, ' is adopted by node ', parent_node.id)
class TransTreeNode(NodeMixin): class TransTreeNode(NodeMixin):
@ -52,28 +34,43 @@ class TransTreeNode(NodeMixin):
self.parent = parent_node self.parent = parent_node
for i in conditions_set: # sorted(conditions_set, key=i.id): conditions_set = set()
condition = CondTreeNode(i[0], i[2], i[3], i[4], i[1]) # TODO y,z,... transitions_set = set()
conditions_list.append(condition)
root = 0 root = 0
for i in conditions_list: for i in range(0, len(model.testmodel.get_conditions().get_all())):
if (i.parent is None): condition = model.testmodel.get_conditions().get_one(i)
for j in conditions_list: conditions_set.add(CondTreeNode(
if (i.parent_node_id == j.id): condition.get_node_self_id(),
i.add_parent_node(j) condition.get_node_parent_id(),
else: condition.get_coord("x"),
root = j condition.get_site(),
condition.get_weight()))
for i in range(0, len(model.testmodel.get_transitions().get_all())):
transition = model.testmodel.get_transitions().get_one(i)
transitions_set.add(TransTreeNode(
transition.get_id(),
transition.get_parent()))
# 0 1 2 3 4
# <condition site="1" weight="0" node_id="3" parent="2" x="2"/>
for i in conditions_set:
if (i.parent_node_id == 0):
root = i
for i in conditions_set:
for j in conditions_set:
if ((i != j) & (i.parent_node_id == j.id)):
i.add_parent_node(j)
for condition_node in LevelOrderIter(root): for condition_node in LevelOrderIter(root):
if condition_node.is_leaf: if condition_node.is_leaf:
for i in transitions_set: for transition_node in transitions_set:
transition_node = TransTreeNode(i[1], i[0]) if (str(condition_node.id) == transition_node.parent):
if (str(condition_node.id) == i[1]):
transition_node.add_parent_leaf_node(condition_node) transition_node.add_parent_leaf_node(condition_node)
for pre, fill, node in RenderTree(root): for pre, fill, node in RenderTree(root):
treestr = u"%s%s" % (pre, node.id) treestr = u"%s%s" % (pre, node.id)
if (type(node) == CondTreeNode): if (type(node) == CondTreeNode):
@ -84,4 +81,5 @@ for pre, fill, node in RenderTree(root):
else: else:
print('] > ', node.children[0].id, end='\n') print('] > ', node.children[0].id, end='\n')
print('\nNext step: single rule extraction from tree. 😃️')
# print([node.id for node in LevelOrderIter(root) if node.is_leaf]) # print([node.id for node in LevelOrderIter(root) if node.is_leaf])