Commit 0d47bbf3 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Rename traj_2_graph to solutions_2_graph; Update doc; ability to take a...

Rename traj_2_graph to solutions_2_graph; Update doc; ability to take a directory instead of just 1 file
parent 52a432cd
......@@ -57,19 +57,17 @@ def launch_sort(args):
solution_sort.sort_solutions(params['path'])
def traj_2_graph(args):
def solutions_2_graph(args):
"""Parse a complete solution file and make a representation of trajectories.
"""
# Module import
import solution_repr
params = args_to_param(args)
params['output'] = params['output'] if params['output'][-1] == '/' \
else params['output'] + '/'
solution_repr.parse_trajectories_main(
solution_repr.solutions_2_graph(
params['output'],
params['chart_file'],
params['sol_file']
params['path']
)
def solutions_2_json(args):
......@@ -272,18 +270,18 @@ def main():
# Model file (xml : cadbiom language)
# Solution file (cam_complete)
parser_trajectories = subparsers.add_parser(
'traj_2_graph',
help=traj_2_graph.__doc__,
'solutions_2_graph',
help=solutions_2_graph.__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser_trajectories.add_argument('chart_file',
help="bcx model file.")
parser_trajectories.add_argument('sol_file',
parser_trajectories.add_argument('path',
help="Complete solution file or directory with MAC solutions files "
"(*cam_complete.txt files) generated with the 'compute_macs' command.")
parser_trajectories.add_argument('--output', action=ReadableDir,
nargs='?', default='graphs/',
help="Output directory for GraphML files.")
parser_trajectories.set_defaults(func=traj_2_graph)
parser_trajectories.set_defaults(func=solutions_2_graph)
# subparser: Decompilation of trajectories of MACs in a complete file/dir.
......
......@@ -199,10 +199,45 @@ def draw_graph(output_dir, solution, solution_index, G,
def process_solutions(output_dir, sol_steps, transitions):
"""Build a graph per solution"""
"""Build a graph based on the given solution
Each solution is composed of a set of frontier places and steps,
themselves composed of events.
We construct a graph based on the transitions that occur in the composition
of the events of the given solution.
:param output_dir: Output path.
:param sol_steps: A generator of tuples of "frontier places" and a list of
events in each step.
:Example:
.. code-block:: python
("Bx Ax", [['h2', 'h00'], ['h3'], ['h0', 'h1'], ['hlast']])
:param transitions: A dictionnary of events as keys, and transitions as values.
Since many transitions can define an event, values are lists.
Each transition is a tuple with: origin node, final node, attributes
like label and condition.
:Example:
.. code-block:: python
{'h00': [('Ax', 'n1', {'label': 'h00[]'}),]
:type output_dir: <str>
:type sol_steps: <tuple <str>, <list>>
:type transitions: <dict <list <tuple <str>, <str>, <dict <str>: <str>>>>
"""
for sol_index, (sol, steps) in enumerate(sol_steps):
# build_graph() returns :
# G, transition_nodes, all_nodes, edges_in_cond, edges
# sol_index is used to order files according to the order of appearance
# in the file
draw_graph(output_dir, sol, sol_index,
*build_graph(sol, steps, transitions)
)
......@@ -282,14 +317,49 @@ def test_main():
def parse_trajectories_main(output_dir, model_file, solution_file):
"""Entry point for parse_trajectories"""
def solutions_2_graph(output_dir, model_file, solution_path):
"""Entry point for solutions_2_graph
process_solutions(
output_dir,
load_solutions(solution_file),
get_transitions_from_model_file(model_file)
)
This functions tests if the given path is a directory or a file.
:param output_dir: Output path.
:param model_file: Filepath of the model.
:param solution_path:
:type output_dir: <str>
:type model_file: <str>
:type solution_path: <str>
"""
# Check valid input file/directory
assert os.path.isfile(solution_path) or os.path.isdir(solution_path)
# Get transitions from the model
model_transitions = get_transitions_from_model_file(model_file)
if os.path.isfile(solution_path):
# The given path is a solution file
process_solutions(
output_dir,
load_solutions(solution_path),
model_transitions
)
elif os.path.isdir(solution_path):
# The given path is a directory
solution_path = solution_path if solution_path[-1] == '/' \
else solution_path + '/'
# Decompilation of all files in the directory
for file_number, solution_path in \
enumerate(glob.glob(solution_path + '*cam_complete.txt'), 1):
process_solutions(
output_dir,
load_solutions(solution_path),
model_transitions
)
LOGGER.info("Files processed: " + str(file_number))
def graph_isomorph_test(model_file_1, model_file_2, output_dir='graphs/',
......
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