arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1504.07828cs.DS
收藏

Python中的加权图算法

Weighted graph algorithms with Python

A. Kapanowski, Ł. Gałuszka

摘要:

给出了所选加权图算法的Python实现。最小图接口与实现该接口的几个类一起定义。图节点可以是任何可散列的Python对象。定向边是Edge类的实例。Graphs是Graph类的实例。它基于邻接表表示,但可以快速查找节点和邻居(dict-of-dict结构)。此类的其他实现也是可能的。在这项工作中,许多算法使用统一的方法来实现。有专门用于不同算法的单独的类和模块。实现了三种寻找最小生成树的算法:Boruvka算法、Prim算法(三种实现)和Kruskal算法。实现了三种求解单源最短路径问题的算法:dag最短路径算法、Bellman-Ford算法和Dijkstra算法(两种实现)。实现了两种求解全对最短路问题的算法:Floor-Warshall算法和Johnson算法。所有算法都通过Python单元测试框架unittest模块进行了测试。为了比较真实和理论的计算复杂性,进行了额外的计算机实验。源代码可从公共GitHub存储库获得。

英文摘要:

Python implementation of selected weighted graph algorithms is presented. The minimal graph interface is defined together with several classes implementing this interface. Graph nodes can be any hashable Python objects. Directed edges are instances of the Edge class. Graphs are instances of the Graph class. It is based on the adjacency-list representation, but with fast lookup of nodes and neighbors (dict-of-dict structure). Other implementations of this class are also possible. In this work, many algorithms are implemented using a unified approach. There are separate classes and modules devoted to different algorithms. Three algorithms for finding a minimum spanning tree are implemented: the Boruvka's algorithm, the Prim's algorithm (three implementations), and the Kruskal's algorithm. Three algorithms for solving the single-source shortest path problem are implemented: the dag shortest path algorithm, the Bellman-Ford algorithm, and the Dijkstra's algorithm (two implementations). Two algorithms for solving all-pairs shortest path problem are implemented: the Floyd-Warshall algorithm and the Johnson's algorithm. All algorithms were tested by means of the unittest module, the Python unit testing framework. Additional computer experiments were done in order to compare real and theoretical computational complexity. The source code is available from the public GitHub repository.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑