Skip to content
aetperfPublic

About

Directed graph algorithms in Cython

Resources

Contributing

Stars

5 stars

Watchers

1 watching

Forks

Repository files navigation

Tests Status codecov Documentation Status PyPI version Downloads Python 3.10 | 3.11 | 3.12 | 3.13 | 3.14 Ruff Cython lint: cython-lint ty License: MIT

Edsger

Graph algorithms in Cython

Edsger is a Python library of graph algorithms for directed graphs, written in Cython. A graph is given as a dataframe of edges, from pandas or Polars, and the results come back as NumPy arrays, pandas Series or Polars DataFrames.

Family Classes
Shortest paths Dijkstra, BellmanFord, AStar, BidirectionalDijkstra
Traversal and components BFS, DFS, ConnectedComponents
Spanning trees and centrality MinimumSpanningTree, Centrality (PageRank, HITS, Katz)
Transit assignment HyperpathGenerating (Spiess and Florian's optimal strategies)

Documentation: https://edsger.readthedocs.io/en/latest/

Installation

pip install edsger

Edsger requires Python 3.10 or later. Wheels are published for Linux (x86_64), Windows and macOS (arm64).

Example

import pandas as pd

from edsger import Dijkstra

edges = pd.DataFrame(
    {
        "tail": [0, 0, 1, 2, 2, 3],
        "head": [1, 2, 2, 3, 4, 4],
        "weight": [1.0, 4.0, 2.0, 1.5, 3.0, 1.0],
    }
)

dijkstra = Dijkstra(edges)
dijkstra.run(vertex_idx=0)
array([0. , 1. , 3. , 4.5, 5.5])

The result is the length of the shortest path from vertex 0 to each vertex of the graph. The graph is built once, and run can be called any number of times with different vertices. With path_tracking=True, the paths themselves can be retrieved.

dijkstra.run(vertex_idx=0, path_tracking=True)
dijkstra.get_path(vertex_idx=4)
array([4, 3, 2, 1, 0], dtype=uint32)

The other classes are described in the quick start.

Performance

Dijkstra's algorithm takes about one second on the USA road network of the 9th DIMACS implementation challenge, which has 23.9 million vertices and 57.7 million edges.

Run time of Dijkstra's algorithm on the USA road network, for Edsger, NetworKit, graph-tool and SciPy

Single-source shortest paths from one vertex of the USA road network, best of 5 runs. The Linux and Windows timings come from two different machines. The method and the versions are given in the benchmarks page.

Contributing

Bug reports and pull requests are welcome on GitHub. See the contributing page for the development setup.

License

Edsger is distributed under the MIT License, see the LICENSE file.

Contact

François Pacull, francois.pacull@architecture-performance.fr

About

Directed graph algorithms in Cython

Resources

Contributing

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages