def links_in_simple_paths(self, sources, sinks):
"""
Count all links in a simple path between sources and sinks
Parameters
-----------
sources : list
List of source nodes
sinks : list
List of sink nodes
sinks : list
List of sink nodes
Returns
-------
link_count : dict
A dictonary with the number of times each link is involved in a path
"""
link_names = [name for (node1, node2, name) in list(self.edges(keys=True))]
link_count = pd.Series(data = 0, index=link_names)
for sink in sinks:
for source in sources:
if nx.has_path(self, source, sink):
paths = _all_simple_paths(self,source,target=sink)
for path in paths:
for i in range(len(path)-1):
links = list(self[path[i]][path[i+1]].keys())
for link in links:
link_count[link] = link_count[link]+1
return link_count
评论列表
文章目录