info_manager.py 文件源码

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

项目:SoftwareProject 作者: a-a-hofmann 项目源码 文件源码
def all_paths(self, G, src=None, dst=None, src_dpid=None, dst_dpid=None):
        """
        For a given source src and destination dst, compute all shortest paths.
        Args:
            G: graph.
            src: source obj. Defaults to None.
            dst: destination obj. Defaults to None.
            src_dpid: source dpid. Defaults to None.
            dst_dpid: dst dpid. Defaults to None.
        Returns:
            List of all paths between src and dst. If only src_dpid and dst_dpid
            were given it returns a list of paths defined as a list of nodes and not path objects.
        """
        if src_dpid and dst_dpid and not src and not dst:
            path_list = []
            for path in nx.all_shortest_paths(G, src_dpid, dst_dpid):
                path_list.append(path)
            return path_list

        src_dpid = src.dpid
        dst_dpid = dst.dpid
        # print "Fetching all paths between {}-{}".format(src, dst)
        if self.path_table.has_path(src_dpid, dst_dpid):
            "Using cached path"
            return [p for p in self.path_table.get_path(src_dpid, dst_dpid)]
        else:
            "Compute and cache new path"
            print "Inserting new path in cache!"
            for path in nx.all_shortest_paths(G, src_dpid, dst_dpid):
                pathObj = Path.of(src, dst, path)
                print pathObj
                self.path_table.put_path(pathObj, src_dpid, dst_dpid)

            return self.path_table.get_path(src_dpid, dst_dpid)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号