graph.py 文件源码

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

项目:omnic 作者: michaelpb 项目源码 文件源码
def get_shortest_paths(self):
        '''
        Return a dictionary containing lists of all possible paths within the
        graph, keyed by tuple of start and end
        '''
        shortest_paths = {}
        for start in self.edges:
            paths_from_start = self.get_all_paths_from(start)
            for weight, path in paths_from_start:
                end = path[-1]
                if start == end:
                    continue  # Skip over self paths
                shortest, _ = shortest_paths.get(
                    (start, end), (math.inf, None))
                if weight < shortest:
                    shortest_paths[(start, end)] = (weight, path)

        # Overlay preferred paths
        shortest_paths.update(self.preferred_paths)
        return shortest_paths
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号