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

Ability to export graphs in specific folder

parent 9b71273c
......@@ -73,7 +73,13 @@ def parse_trajectories(args):
# Module import
import solution_repr
params = args_to_param(args)
solution_repr.main(params['chart_file'], params['sol_file'])
params['output'] = params['output'] if params['output'][-1] == '/' \
else params['output'] + '/'
solution_repr.main(
params['output'],
params['chart_file'],
params['sol_file']
)
def model_comp(args):
......@@ -88,9 +94,12 @@ def model_comp(args):
# Module import
import solution_repr
params = args_to_param(args)
params['output'] = params['output'] if params['output'][-1] == '/' \
else params['output'] + '/'
solution_repr.graph_isomorph_test(
params['model_file_1'],
params['model_file_2'],
params['output'],
params['make_graphs'],
)
......@@ -213,6 +222,8 @@ def main():
help=parse_trajectories.__doc__)
parser_trajectories.add_argument('chart_file')
parser_trajectories.add_argument('sol_file')
parser_trajectories.add_argument('--output', action=ReadableDir,
nargs='?', default='graphs/')
parser_trajectories.set_defaults(func=parse_trajectories)
......@@ -236,6 +247,8 @@ def main():
parser_model_comparison.add_argument('model_file_2')
# Export graphs for the 2 models; default: false
parser_model_comparison.add_argument('--make_graphs', action='store_true')
parser_model_comparison.add_argument('--output', action=ReadableDir,
nargs='?', default='graphs/')
parser_model_comparison.set_defaults(func=model_comp)
......
......@@ -45,8 +45,6 @@ import cadbiom.commons as cm
LOGGER = cm.logger()
GRAPHS_DIR = "./graphs/"
"""
Bx Ax
% h2 h00
......@@ -555,7 +553,7 @@ def build_graph(solution, steps, transitions):
return G, transition_nodes, all_nodes, edges_in_cond, edges
def draw_graph(solution, solution_index, G,
def draw_graph(output_dir, solution, solution_index, G,
transition_nodes, all_nodes,
edges_in_cond, edges):
"""Draw graph with colors and export it to graphml format.
......@@ -644,17 +642,19 @@ def draw_graph(solution, solution_index, G,
nx.write_graphml(
G,
"{}{}_{}_{}.graphml".format(
GRAPHS_DIR, date, solution_index, solution[:75]
output_dir, date, solution_index, solution[:75]
)
)
def process_solutions(sol_steps, transitions):
def process_solutions(output_dir, sol_steps, transitions):
"""Build a graph per solution"""
for sol_index, (sol, steps) in enumerate(sol_steps):
draw_graph(sol, sol_index, *build_graph(sol, steps, transitions))
draw_graph(output_dir, sol, sol_index,
*build_graph(sol, steps, transitions)
)
def test_main():
......@@ -787,16 +787,18 @@ def sol_digging(sol_steps, transitions):
fd.write('\n====================================================\n')
def main(model_file, solution_file):
def main(output_dir, model_file, solution_file):
"""Entry point for parse_trajectories"""
process_solutions(
output_dir,
load_solutions(solution_file),
get_transitions(model_file)
)
def graph_isomorph_test(model_file_1, model_file_2, make_graphs=False):
def graph_isomorph_test(model_file_1, model_file_2,
output_dir, make_graphs=False):
"""Entry point for model consistency checking.
This functions checks if the 2 given models have the same topology,
......@@ -834,8 +836,8 @@ def graph_isomorph_test(model_file_1, model_file_2, make_graphs=False):
# Draw graph
if make_graphs:
draw_graph(front_places_1, "first", *res_1)
draw_graph(front_places_2, "second", *res_2)
draw_graph(output_dir, front_places_1, "first", *res_1)
draw_graph(output_dir, front_places_2, "second", *res_2)
# Checking
LOGGER.info("Topology checking: " +
......
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