Skip to main content

Fast_dijkstra

Fast directed Dijkstra written in C++ with parallelization build in

Function definition

Parameters
----------
indptr : List[int]
indices : List[int]
weights : Sequence[float]
sources : List[int]
cutoff: OPTIONAL  float (default = np.inf)
num_threads: OPTIONAL int (default = -1)
    -1: maximum allowed threads

Returns
-------
distances : numpy.ndarray
    Array of shape (num_sources, num_nodes) with shortest distances
predecessors : numpy.ndarray
    Array of shape (num_sources, num_nodes) with predecessor indices

usage

  • The graph is passed as a csr_matrix just like scipy. you can reuse scipy to create the graph from edges.
  • edges must be integers. starting at 0
  • Graph is directed
from scipy.sparse import csr_matrix
from fast_dijkstra import dijkstra, dijkstra_with_targets, dijkstra_on_multi_targets

edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3)]
weights = [1.0, 4.0, 2.0, 5.0, 1.0]
sources = [0, 1]

row = [e[0] for e in edges]
col = [e[1] for e in edges]

nodelist = sorted({e[0] for e in edges}.union({e[1] for e in edges}))
nlen = len(nodelist)

sparse = csr_matrix((weights, (row, col)), shape=(nlen, nlen))
indptr = sparse.indptr  # [0, 2, 4, 5, 5]
indices = sparse.indices  # [1, 2, 2, 3, 3]

# basic usage
distances, predecessor = dijkstra(indptr=indptr, indices=indices, weights=weights, sources=sources)

distances   # [
            #   [ 0.,  1.,  3.,  4.],
            #   [inf,  0.,  2.,  3.]
            # ]

predecessor # [
            #   [-9999,     0,     1,     2],
            #   [-9999, -9999,     1,     2]
            # ]


# with limits, and threads
distances, predecessor = dijkstra(
    indptr=indptr, indices=indices, weights=weights, sources=sources, cutoff=10, num_threads=2
)

# with targets (return smaller predecessor/distances)
distances, predecessor = dijkstra_with_targets(
    indptr=indptr, indices=indices, weights=weights, sources=sources, targets=[3]
)

# with limits, and threads
distances, predecessor = dijkstra_with_targets(
    indptr=indptr, indices=indices, weights=weights, sources=sources, targets=[3]
)

# with target per source.

targets = [(0, 3), (1, 2), (1, 3)]
row = [e[0] for e in targets]
col = [e[1] for e in targets]
target_mat = csr_matrix(([1, 1, 1], (row, col)), shape=(nlen, nlen))


distances, predecessor = dijkstra_on_multi_targets(
    indptr=indptr,
    indices=indices,
    weights=weights,
    sources=sources,
    target_indptr=target_mat.indptr,
    target_indices=target_mat.indices,
)

to deploy

  1. change the version number in pyproject.toml under [project]
[project]
name = "fast_dijkstra"
version = "1.0.2"
  • the poetry config is only used for local dev. to ignore.
  1. create a new tag starting with "v"
git tag -a 'v1.0.2' -m 'description'
git push origin v1.0.2

Github action will build wheels for windows and Linux.

  1. when Done, upload to Pypi
./upload v1.0.2

local development build

poetry run python setup.py bdist_wheel

or

poetry run python -m build --wheel

Metadata

Release files for fast-dijkstra 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for fast-dijkstra 4.0.0
File
fast_dijkstra-4.0.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
fast_dijkstra-4.0.0-cp312-cp312-win32.whl CPython 3.12 CPython 3.12 Windows x86-32 Details
fast_dijkstra-4.0.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.26+ x86-64 Details
fast_dijkstra-4.0.0-cp312-cp312-macosx_26_0_arm64.whl CPython 3.12 CPython 3.12 macOS 26.0+ ARM64 Details

Total release size: 1.8 MB

Release files / fast_dijkstra-4.0.0-cp312-cp312-win_amd64.whl

Download URL fast_dijkstra-4.0.0-cp312-cp312-win_amd64.whl
Size 385.1 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
1359fce2bb7a65da75cb0157629e432fbbbab63f1bb5047cc2ec135299bfd283
BLAKE2b-256 checksum
How to use checksums
ad0a4cd6270d4ea36a6eb6cfb4b92930259ff4dd834987e9b0707528938759fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / fast_dijkstra-4.0.0-cp312-cp312-win32.whl

Download URL fast_dijkstra-4.0.0-cp312-cp312-win32.whl
Size 365.5 kB
Tags CPython 3.12 Windows x86-32
SHA-256 checksum
How to use checksums
4801e7ce7dd1c5abec8321f38841cf679e0d8b223021511e1a3def3692a933da
BLAKE2b-256 checksum
How to use checksums
3b52778ff8c7a9e0010d2bfc5aa1fa46d7a53c5b85ccbedaa10ec03a78a9e828
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / fast_dijkstra-4.0.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl

Download URL fast_dijkstra-4.0.0-cp312-cp312-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
Size 702.0 kB
Tags CPython 3.12 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1184c9d2a62f9ec9933124c5af5d95f4f6a9edceb5c02f8332922b47708cf47f
BLAKE2b-256 checksum
How to use checksums
cb40e8fd37edf21c7b09fad1b0797e497082956b04c7f8d2c141dec66eeb126c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / fast_dijkstra-4.0.0-cp312-cp312-macosx_26_0_arm64.whl

Download URL fast_dijkstra-4.0.0-cp312-cp312-macosx_26_0_arm64.whl
Size 342.9 kB
Tags CPython 3.12 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
bd8f53c44cadb8ba4fef8f66a40acc1cfd25e31a9b40c6f46c17c74c9dd0ef7a
BLAKE2b-256 checksum
How to use checksums
1721aa40bfa568cb66ae8a25982e67e9cbea5f3f734c91dd6c1b4461bdda95b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Security for fast-dijkstra 4.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page