Commit 1d4fdaa2 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

Ability to dump tests results in json file; graph_isomorph_test() returns a...

Ability to dump tests results in json file; graph_isomorph_test() returns a check dict for easy integration in python scripts
parent ffc85832
......@@ -100,7 +100,8 @@ def model_comp(args):
......@@ -246,7 +247,8 @@ def main():
# Export graphs for the 2 models; default: false
parser_model_comparison.add_argument('--make_graphs', action='store_true')
parser_model_comparison.add_argument('--graphs', action='store_true')
parser_model_comparison.add_argument('--json', action='store_true')
parser_model_comparison.add_argument('--output', action=ReadableDir,
nargs='?', default='graphs/')
......@@ -31,6 +31,7 @@ import networkx as nx
import itertools as it
import re
import matplotlib.pyplot as plt
import json
from logging import DEBUG
# Library imports
......@@ -801,7 +802,7 @@ def main(output_dir, model_file, solution_file):
def graph_isomorph_test(model_file_1, model_file_2,
output_dir, make_graphs=False):
output_dir, make_graphs=False, make_json=False):
"""Entry point for model consistency checking.
This functions checks if the 2 given models have the same topology,
......@@ -814,6 +815,9 @@ def graph_isomorph_test(model_file_1, model_file_2,
:param arg2: File for the model 2.
:type arg1: <str>
:type arg2: <str>
:return: Dictionary with the results of tests.
keys: 'topology', 'nodes', 'edges'; values: booleans
:rtype: <dict <str>: <boolean>>
import networkx.algorithms.isomorphism as iso
......@@ -837,20 +841,32 @@ def graph_isomorph_test(model_file_1, model_file_2,
res_2 = build_graph(front_places_2, [transitions_2.keys()], transitions_2)
G2 = res_2[0]
# Checking
nm = iso.categorical_node_match('color', 'grey')
em = iso.categorical_edge_match('color', '')
check_state = \
'topology': nx.is_isomorphic(G1, G2),
'nodes': nx.is_isomorphic(G1, G2, node_match=nm),
'edges': nx.is_isomorphic(G1, G2, edge_match=em),
}"Topology checking: " + str(check_state['topology']))"Nodes checking: " + str(check_state['nodes']))"Edges checking: " + str(check_state['edges']))
# Draw graph
if make_graphs:
draw_graph(output_dir, front_places_1, "first", *res_1)
draw_graph(output_dir, front_places_2, "second", *res_2)
# Checking"Topology checking: " +
str(nx.is_isomorphic(G1, G2)))
nm = iso.categorical_node_match('color', 'grey')"Nodes checking: " +
str(nx.is_isomorphic(G1, G2, node_match=nm)))
em = iso.categorical_edge_match('color', '')"Edges checking: " +
str(nx.is_isomorphic(G1, G2, edge_match=em)))
# Export to json file
if make_json:
with open(output_dir + "comp_results.json", 'a') as fd:
fd.write(json.dumps(check_state) + '\n')
return check_state
if __name__ == "__main__":
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