graph.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:WNTR 作者: USEPA 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号