Commit 3197f27b authored by VIGNET Pierre's avatar VIGNET Pierre

Improve infos option: advanced centralies on demand only => quicker

parent 3d78d953
......@@ -123,6 +123,7 @@ def model_infos(args):
params['output'],
params['graph'],
params['json'],
params['advanced'],
)
......@@ -283,6 +284,7 @@ def main():
# Export graphs for the 2 models; default: false
parser_model_infos.add_argument('--graph', action='store_true')
parser_model_infos.add_argument('--json', action='store_true')
parser_model_infos.add_argument('--advanced', action='store_true')
parser_model_infos.add_argument('--output', action=ReadableDir,
nargs='?', default='graphs/')
parser_model_infos.set_defaults(func=model_infos)
......
......@@ -451,7 +451,7 @@ def parse_event(event):
return expr.name, ''
raise AssertionError("You should never have been there ! "
"Your expression type is not yer supported...")
"Your expression type is not yet supported...")
# def filterSigExpression(listOfExpr):
# return [filterSigExpression(expr) for expr in listOfExpr]
......@@ -990,7 +990,7 @@ def graph_isomorph_test(model_file_1, model_file_2, output_dir='graphs/',
def graph_infos(model_file, output_dir='graphs/',
make_graph=True, make_json=True):
make_graph=True, make_json=True, advanced_measures=False):
"""Entry point for model stats.
:param arg1: File for the model.
......@@ -1018,35 +1018,44 @@ def graph_infos(model_file, output_dir='graphs/',
# 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))
LOGGER.debug("Frontier places 1: " + str(front_places_1))
front_places = get_frontier_places(transitions_1, all_places_1)
front_places_str = " ".join(front_places)
LOGGER.debug("Frontier places 1: " + front_places_str)
# Build graphs & get networkx object
# We give all events in the model as a list of steps
# So we simulate a cadbiom solution (with all events in the model).
res_1 = build_graph(front_places_1, [transitions_1.keys()], transitions_1)
res_1 = build_graph(front_places_str, [transitions_1.keys()], transitions_1)
G = res_1[0]
infos = {
'model': model_file,
'nodes': len(G.nodes()),
'edges': len(G.edges()),
'degree': nx.degree_centrality(G),
'in_degree': nx.in_degree_centrality(G),
'out_degree': nx.out_degree_centrality(G),
'betweenness': nx.betweenness_centrality(G),
'closeness': nx.closeness_centrality(G),
'transitions:': len(transitions_1),
'places': len(all_places_1),
'frontier places': len(front_places),
}
if advanced_measures:
infos.update({
'degree': nx.degree_centrality(G),
'in_degree': nx.in_degree_centrality(G),
'out_degree': nx.out_degree_centrality(G),
'betweenness': nx.betweenness_centrality(G),
'closeness': nx.closeness_centrality(G),
})
# Draw graph
if make_graph:
draw_graph(output_dir, front_places_1, 'stat', *res_1)
draw_graph(output_dir, front_places_str, 'stat', *res_1)
# Export to json file
if make_json:
with open(output_dir + "infos_results.json", 'w') as fd:
fd.write(json.dumps(infos, sort_keys=True, indent=4) + '\n')
LOGGER.info(str(infos))
return infos
......
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