def _get_shortest__path_between_subgraphs_helper(graph, a, b):
"""Calculate the shortest path that occurs between two disconnected subgraphs A and B going through nodes in
the source graph
:param nx.MultiGraph graph: A graph
:param nx.MultiGraph a: A subgraph of :code:`graph`, disjoint from :code:`b`
:param nx.MultiGraph b: A subgraph of :code:`graph`, disjoint from :code:`a`
:return: A list of the shortest paths between the two subgraphs
:rtype: list
"""
shortest_paths = []
for na, nb in itt.product(a, b):
a_b_shortest_path = nx.shortest_path(graph, na, nb)
shortest_paths.append(a_b_shortest_path)
b_a_shortest_path = nx.shortest_path(graph, nb, na)
shortest_paths.append(b_a_shortest_path)
min_len = min(map(len, shortest_paths))
return [p for p in shortest_paths if len(p) == min_len]
评论列表
文章目录