Skip to main content

Graph search algorithms with a small object-oriented Python API.

Project description

waypy-routing

waypy-routing is a small Python package for finding paths in directed graphs. It includes classic unweighted and weighted search algorithms behind a simple object-oriented API.

Features

  • Breadth-first search
  • Depth-first search
  • Limited-depth search
  • Iterative deepening search
  • Bidirectional search
  • Uniform-cost search
  • Greedy best-first search
  • A* search
  • Compatibility aliases for the original Portuguese API

Installation

pip install waypy-routing

Quick Start

from waypy import Agent

agent = Agent.from_adjacency({
    "A": ["B", "C"],
    "B": ["D"],
    "C": ["D"],
    "D": [],
})

path = agent.find_path("A", "D", method="breadth_first")
print(path)
# ["A", "B", "D"]

Weighted Graphs

from waypy import Agent

agent = Agent.from_weighted_adjacency({
    "A": [("B", 1), ("C", 5)],
    "B": [("C", 1)],
    "C": [],
})

result = agent.find_weighted_path("A", "C", method="uniform_cost")
print(result.path)
# ["A", "B", "C"]
print(result.cost)
# 2.0

Available Methods

Unweighted methods:

  • breadth_first
  • depth_first
  • limited_depth
  • iterative_deepening
  • bidirectional

Weighted methods:

  • uniform_cost
  • greedy
  • a_star

Legacy aliases such as AMPLITUDE, PROFUNDIDADE, BIDIRECIONAL, CUSTO_UNIFORME, and A_ESTRELA are still accepted.

Legacy API

The original class name remains available:

from waypy import Agente

agent = Agente()
agent.nodes = ["A", "B", "C"]
agent.graphs = [["B"], ["C"], []]
agent.starting_points = ["A"]

path = agent.encontrar_ajuda_humanitaria("C", "AMPLITUDE")
print(path)
# ["A", "B", "C"]

New projects should prefer Agent, find_path, and find_weighted_path.

Development

Install the package locally with test dependencies:

python -m pip install -e ".[test]"

Run the test suite:

python -m pytest

Build distribution artifacts:

python -m pip install build twine
python -m build
python -m twine check dist/*

Publish to PyPI:

python -m twine upload dist/*

License

waypy-routing is distributed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

waypy_routing-0.2.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

waypy_routing-0.2.0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file waypy_routing-0.2.0.tar.gz.

File metadata

  • Download URL: waypy_routing-0.2.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for waypy_routing-0.2.0.tar.gz
Algorithm Hash digest
SHA256 80f487794455b6550c138a4c61e55224f20cde3264dd2495e5e1b40fcac66ab2
MD5 e1675be9a6987eaeb12447e07d8bf687
BLAKE2b-256 73f3e050b16893b7ce80dfd9765b836c82e15455f145f983231d4a64b1dd31d2

See more details on using hashes here.

File details

Details for the file waypy_routing-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: waypy_routing-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for waypy_routing-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46526a65d6dd207f19df8723ed76a3ddb9732b504517d41b071eb7402f6b784d
MD5 0e0e6d36a71e11c9056cba0fe5d0e441
BLAKE2b-256 874fa80c6bbd11f548bfd2bdf708de85e03e3ae40fef678b76619e837c2ae1e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page