Commit da7df0b3 authored by Runar Borge's avatar Runar Borge
Browse files

Fix #18 and #5, exception when partitioning net

Usage of nx.average_shortest_path_length dont allow a partitioned
net, and have to be executed once for each subgraph on the graph
parent dbce3ce5
......@@ -82,11 +82,20 @@ class MetricShell(Cmd):
effects = self.simulation.get_effects()
multinodes = [x for x in list(effects.keys()) if len(list(effects[x].keys())) >= 5]
multimulti = [x for x in list(effects.keys()) if len(list(effects[x].keys())) >= 20]
difflen = nx.average_shortest_path_length(self.simulation.graph)\
- nx.average_shortest_path_length(self.model.G)
components = list(self.model.G.subgraph(c) for c in nx.connected_components(
# Get all connected subgraphs of the current graph
components = list(self.simulation.graph.subgraph(c) for c in nx.connected_components(
self.simulation.graph.to_undirected()))
basecomponents = list(self.model.graph.subgraph(c) for c in nx.connected_components(
self.model.graph.to_undirected()))
# Average SPF is only able to be computed on connected nodes, if one node is disconnected
# it will fail computation. This code executes Averate calculation once pr. subgraph
# to circumvent this limitation
difflen = sum([nx.average_shortest_path_length(x) for x in components]) \
- sum([nx.average_shortest_path_length(x) for x in basecomponents])
cnodes = 0
if len(components) > 1:
cnodes = sum([len(g.nodes()) for g in components[1:]])
......
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