WIP: optimisation algo.
This commit is contained in:
parent
fe668f3720
commit
a78e3f7bb6
Binary file not shown.
|
@ -353,10 +353,10 @@ class Conditions:
|
|||
if(child.tag == "condition"):
|
||||
self.__conditions.append(Condition(child))
|
||||
|
||||
def get_condition(self, i):
|
||||
def get_one(self, i):
|
||||
return self.__conditions[i]
|
||||
|
||||
def get_conditions_array(self):
|
||||
def get_all(self):
|
||||
return self.__conditions
|
||||
|
||||
|
||||
|
@ -397,10 +397,10 @@ class Transitions:
|
|||
if(child.tag == "transition"):
|
||||
self.__transitions.append(Transition(child))
|
||||
|
||||
def get_transition(self, i):
|
||||
def get_one(self, i):
|
||||
return self.__transitions[i]
|
||||
|
||||
def get_transitions_array(self):
|
||||
def get_all(self):
|
||||
return self.__transitions
|
||||
|
||||
## Model
|
||||
|
|
|
@ -6,24 +6,6 @@ import model
|
|||
# 1) node_id <> pas de doublons
|
||||
# 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):
|
||||
def __init__(self, id, x, site, weight, parent_node_id):
|
||||
|
@ -36,8 +18,8 @@ class CondTreeNode(NodeMixin):
|
|||
self.weight = weight
|
||||
|
||||
def add_parent_node(self, parent_node):
|
||||
print('orphan node ', self.id, ' is adopted by node ', parent_node.id)
|
||||
self.parent = parent_node
|
||||
# print('orphan node ', self.id, ' is adopted by node ', parent_node.id)
|
||||
|
||||
|
||||
class TransTreeNode(NodeMixin):
|
||||
|
@ -52,28 +34,43 @@ class TransTreeNode(NodeMixin):
|
|||
self.parent = parent_node
|
||||
|
||||
|
||||
for i in conditions_set: # sorted(conditions_set, key=i.id):
|
||||
condition = CondTreeNode(i[0], i[2], i[3], i[4], i[1]) # TODO y,z,...
|
||||
conditions_list.append(condition)
|
||||
|
||||
conditions_set = set()
|
||||
transitions_set = set()
|
||||
root = 0
|
||||
|
||||
for i in conditions_list:
|
||||
if (i.parent is None):
|
||||
for j in conditions_list:
|
||||
if (i.parent_node_id == j.id):
|
||||
for i in range(0, len(model.testmodel.get_conditions().get_all())):
|
||||
condition = model.testmodel.get_conditions().get_one(i)
|
||||
conditions_set.add(CondTreeNode(
|
||||
condition.get_node_self_id(),
|
||||
condition.get_node_parent_id(),
|
||||
condition.get_coord("x"),
|
||||
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)
|
||||
else:
|
||||
root = j
|
||||
|
||||
for condition_node in LevelOrderIter(root):
|
||||
if condition_node.is_leaf:
|
||||
for i in transitions_set:
|
||||
transition_node = TransTreeNode(i[1], i[0])
|
||||
if (str(condition_node.id) == i[1]):
|
||||
for transition_node in transitions_set:
|
||||
if (str(condition_node.id) == transition_node.parent):
|
||||
transition_node.add_parent_leaf_node(condition_node)
|
||||
|
||||
|
||||
for pre, fill, node in RenderTree(root):
|
||||
treestr = u"%s%s" % (pre, node.id)
|
||||
if (type(node) == CondTreeNode):
|
||||
|
@ -84,4 +81,5 @@ for pre, fill, node in RenderTree(root):
|
|||
else:
|
||||
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])
|
||||
|
|
Loading…
Reference in New Issue