GitHunt
KY

kyletreleaven/roadgeometry

A python utility library for geometrical queries on continuous road network spaces. Includes a O(n log n) algorithm (fastest possible) for matching two sets of points placed in a roadmap, using a modified algorithm for minimum cost flows on networks with convex costs on edges.

roadgeometry

setiptah.roadgeometry is a currently pure-Python library for geometric queries on
metric graphs, a broad class of
one-dimensional continuous "roadmap" metric spaces.

The library
provides api for defining and querying road networks as metric graphs,
including support for parallel roads, mixtures of one-way and bidirectional roads,
shortest paths, and nearest-neighbor queries.

The main contribution of the library is an efficient $O(n \log n)$ bipartite matching algorithm,
achieving the fastest possible asymptotic runtime in terms of the number of query points.
The algorithm reduces bipartite matching to minimum-cost flow on graphs with convex edge costs,
all within the highly restrictive runtime budget
(see arXiv:1311.4609).
In contrast,
classical algorithms like the Hungarian method run in $O(n^3)$,
which can be too slow at scale for many applications.

See demonstration in this Jupyter notebook.


Highlights

  • ๐Ÿš€ Fastest-possible bipartite matching

    • Exact $O(n \log n)$ algorithm for bipartite matching weighted by roadmap distance.
    • Based on convex-cost minimum-cost flow on graphs.
    • Scales efficiently to large problem instances.
  • ๐Ÿ›ฃ Road-aware metric graphs

    • Networks defined in terms of roads, not just connected vertices:
      • Allows multiple distinct roads between the same endpoints.
      • Consistent support for mixtures of one-way and bidirectional roads.
    • Planar embeddings supported.
    • Visualization available with NetworkX.
  • ๐Ÿ“ Continuous shortest paths

    • Compute distances and shortest paths between arbitrary points along roads, not just vertices.
    • Dijkstra-like algorithm adapted to parallel roads and mixed directionality.
  • ๐Ÿ” Nearest-neighbor search

    • Efficient Dijkstra-like search for the closest network location to a query point.

Trying it out

Please feel free to check out the unit tests for usage examples.

This project uses nox for automation.
With nox installed, you can run the unit tests in either directory by:

# Run the unit test suite in either package directory.
nox -r -s test

Languages

Jupyter Notebook88.0%Python11.7%HTML0.2%CSS0.0%TeX0.0%

Contributors

Created June 23, 2013
Updated March 2, 2026