Commit b88a1197 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Fix bug in frontier places detection: nodes only in conditions but not in...

Fix bug in frontier places detection: nodes only in conditions but not in transition (input/output) were forgotten
parent 7d1c8035
......@@ -146,7 +146,7 @@ def load_solutions(file):
yield sol, sol_steps[sol]
def get_transitions(file):
def get_transitions(file, all_places=False):
"""Get all transitions in a file model (bcx format).
:param: Model in bcx format.
......@@ -198,10 +198,14 @@ def get_transitions(file):
assert len(transitions) != 0, "No transitions found in the model ! " \
"Please check the names of events (_h_xxx)"
if all_places:
# Return all nodes
return dict(transitions), parser.handler.node_dict.keys()
return dict(transitions)
def get_frontier_places(transitions):
def get_frontier_places(transitions, all_places):
"""Return frontier places of a model (deducted from its transitions).
:param arg1: Model's transitions.
......@@ -217,11 +221,11 @@ def get_frontier_places(transitions):
g = tuple(trans for event in transitions.values() for trans in event)
# Get input nodes & output nodes
input_places = {trans[0] for trans in g}
# input_places = {trans[0] for trans in g}
output_places = {trans[1] for trans in g}
# Get all places that are not in transitions in the "output" place
return input_places - output_places
return set(all_places) - output_places
def rec(tree, inhibitors_nodes):
......@@ -358,7 +362,7 @@ def parse_condition(condition, all_nodes, inhibitors_nodes):
)
)
assert len(valid_paths) > 0
assert len(valid_paths) > 0, "No valid path for: " + str(condition)
if len(valid_paths) > 1:
LOGGER.warning("Multiple valid paths for: {}:\n{}".format(condition,
valid_paths))
......@@ -435,6 +439,24 @@ def build_graph(solution, steps, transitions):
assert len(step_event) != 0 # Todo: useful ?
inhibitors_nodes = set() # Inactivated nodes in paths of conditions
input_places = {trans[0] for trans in step_event}
# Color nodes
# Since we explore all possible paths for each condition,
# some edges are rewrited multiple times.
# => included edges between origin <=> transition node
# These edges must be grey while, edges between a node that is
# only in a condition and a transition node must be green.
# => notion of activator vs inhibitor vs normal input/output node
def color_map(node):
# print("color for:", node)
if node in inhibitors_nodes: # Test first (see cond below)
return 'red'
if node in input_places: # some /all frontier places are in this set
return 'grey'
else:
return 'green'
for trans in step_event:
attributes = trans[2]
......@@ -498,7 +520,7 @@ def build_graph(solution, steps, transitions):
# ', '.join(path),
# i
# ), #node + '-' + event,
'color': 'red' if node in inhibitors_nodes else 'green',
'color': color_map(node),
}
)
)
......@@ -826,13 +848,20 @@ def graph_isomorph_test(model_file_1, model_file_2, output_dir='graphs/',
# Load transitions in the models
# Transitions structure format:
# {u'h00': [('Ax', 'n1', {u'label': u'h00[]'}),]
transitions_1 = get_transitions(model_file_1)
transitions_2 = get_transitions(model_file_2)
transitions_1, all_places_1 = get_transitions(model_file_1, all_places=True)
transitions_2, all_places_2 = get_transitions(model_file_2, all_places=True)
# Get all frontier places in the models
# (places that are never in output position in all transitions)
front_places_1 = " ".join(get_frontier_places(transitions_1))
front_places_2 = " ".join(get_frontier_places(transitions_2))
# EDIT: why we use all_places from the model instead of
# (input_places - output_places) to get frontier places ?
# Because some nodes are only in conditions and not in transitions.
# If we don't do that, these nodes are missing when we compute
# valid paths from conditions.
front_places_1 = " ".join(get_frontier_places(transitions_1, all_places_1))
front_places_2 = " ".join(get_frontier_places(transitions_2, all_places_2))
LOGGER.debug("Frontier places 1: " + str(front_places_1))
LOGGER.debug("Frontier places 2: " + str(front_places_2))
# Build graphs & get networkx object
# We give all events in the model as a list of steps
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment