Skip to main content

Pathfinding

This package provides a pure Python implementation for Dijkstra and A-Star as well as a faster Cython implementation.

Using the pure Python Djikstra

from pypathfinder.Dijkstra import Node, bestpath
def example_nodesystem():
    # https://de.wikipedia.org/wiki/Dijkstra-Algorithmus#Beispiel_mit_bekanntem_Zielknoten
    frankfurt = Node("Frankfurt")
    mannheim = Node("Mannheim")
    kassel = Node("Kassel")
    wuerzburg = Node("Würzburg")
    frankfurt.connect({mannheim: 85, wuerzburg: 217, kassel: 173}, True)
    # True value results in connecting all the given Nodes to frankfurt and back with the same cost
    karlsruhe = Node("Karlsruhe")
    mannheim.connect({karlsruhe:80}, True)

    erfurt = Node("Erfurt")
    nuernberg = Node("Nürnberg")
    wuerzburg.connect({erfurt: 186, nuernberg: 103}, True)

    stuttgart = Node("Stuttgart")
    nuernberg.connect({stuttgart: 183}, True)

    augsburg = Node("Augsburg")
    karlsruhe.connect({augsburg: 250}, True)

    muenchen = Node("München")
    muenchen.connect({augsburg: 84, nuernberg: 167, kassel: 502}, True)
    return frankfurt, muenchen

frankfurt, muenchen = example_nodesystem()
path = bestpath(frankfurt, muenchen)
# path includes start and endpoint
# all Nodes have a cost value now

Using the Cython Djikstra

from pypathfinder.fast import CNode, djikstra_bestpath
def example_nodesystem():
    # https://de.wikipedia.org/wiki/Dijkstra-Algorithmus#Beispiel_mit_bekanntem_Zielknoten
    frankfurt = CNode("Frankfurt")
    mannheim = CNode("Mannheim")
    kassel = CNode("Kassel")
    wuerzburg = CNode("Würzburg")
    frankfurt.connect({mannheim: 85, wuerzburg: 217, kassel: 173}, True)

    karlsruhe = CNode("Karlsruhe")
    mannheim.connect({karlsruhe:80}, True)

    erfurt = CNode("Erfurt")
    nuernberg = CNode("Nürnberg")
    wuerzburg.connect({erfurt: 186, nuernberg: 103}, True)

    stuttgart = CNode("Stuttgart")
    nuernberg.connect({stuttgart: 183}, True)

    augsburg = CNode("Augsburg")
    karlsruhe.connect({augsburg: 250}, True)

    muenchen = CNode("München")
    muenchen.connect({augsburg: 84, nuernberg: 167, kassel: 502}, True)
    return frankfurt, muenchen

frankfurt, muenchen = example_nodesystem()
path = bestpath(frankfurt, muenchen)
# path includes start and endpoint
# all Nodes have a cost value now

Using INode (example for the pure Python version)

...

from pypathfinder.Dijkstra import INode, ibestpath, copy_graph
from pypathfinder.utils import PathError

point1 = INode(1)
point2 = INode(2, lambda x: x % 2 == 1)
point3 = INode(3, lambda x: x % 2 == 0)
point4 = INode(4)

point1.connect({point2: 15, point3: 5}, True)
point4.connect({point2: 15, point3: 10}, True)
try:
    path = bestpath(point1, point4) # time 0 at startingposition
except PathError:
    print("Error, no path")
else:
    print(path)

point1, point4, graph = copy_graph(point1, point4)
graph.get(point2).connect({graph.get(point3): 2}, True)
try:
    path = bestpath(point1, point4)
except PathError:
    print("Error, no path")
else:
    print(path)

Metadata

Release files for pypathfinder 1.2

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

Source distribution (sdist)

Source distribution for pypathfinder 1.2
File Size Uploaded Provenance Actions
pypathfinder-1.2.tar.gz 196.5 kB Without provenance Details for pypathfinder-1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pypathfinder 1.2
File Interpreter ABI Platform Actions
pypathfinder-1.2-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for pypathfinder-1.2-cp37-cp37m-win_amd64.whl

Total release size: 514.9 kB

Release files / pypathfinder-1.2.tar.gz

Download URL pypathfinder-1.2.tar.gz
Size 196.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0c00b9879585cc22422a201209618711c296d88aea3d88c4d13ee1632b5962aa
BLAKE2b-256 checksum
How to use checksums
30d63dae6d0bc50a9128349182105556d7bf3db5544ecfe3b5e58f23771efb9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.9

Release files / pypathfinder-1.2-cp37-cp37m-win_amd64.whl

Download URL pypathfinder-1.2-cp37-cp37m-win_amd64.whl
Size 318.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
b45f8175870d97595b75069e2f92c9ca401940130b34e278c8244ca5dadf22fc
BLAKE2b-256 checksum
How to use checksums
b905156bf73a7f30514d35afea2f6bf24579c289c3104dd1e78e25c4a6b9357b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.9

Security for pypathfinder 1.2

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2 This release

2 release files No provenance

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