Skip to main content

AStar Algorithm

Project description

pyastar - A* Algorithm in Python

You can find a documentation of pyastar at: https://www.egr.msu.edu/coinlab/pyastar/

build status python 3.6 license apache

Installation

The official release is always available at PyPi:

pip install -U pyastar

Usage

Graph

from pyastar.interface import astar_graph
from pyastar.util.graph import WeightedGraph


def create_sample_graph():
    G = WeightedGraph()

    G.add_node("s", "a", "b", "c", "d", "e", "g")
    G.add_edge("s", "a", 1.5)
    G.add_edge("a", "b", 2.0)
    G.add_edge("b", "c", 3.0)
    G.add_edge("c", "g", 4.0)
    G.add_edge("s", "d", 2.0)
    G.add_edge("d", "e", 3.0)
    G.add_edge("e", "g", 2.0)

    G.preprocess()

    return G


def heuristic_sample_graph(node):
    D = {
        "s": None,
        "a": 4.0,
        "b": 4.0,
        "c": 4.0,
        "d": 4.0,
        "e": 4.0,
        "g": 0.0
    }

    return D[node]


if __name__ == '__main__':
    G = create_sample_graph()
    ret = astar_graph(G, "s", "g", heuristic_sample_graph)
    print("Shortest Path:", ret)

Grid

from pyastar.interface import astar_graph
from pyastar.util.grid import Grid
from pyastar.util.heuristics import manhatten_dist_2d

grid = Grid(5, 5)
grid.add_obstacle((3, 0), (3, 1))
G = grid.to_graph()

start = (4, 0)
goal = (0, 4)

ret = astar_graph(G, start, goal, lambda x: manhatten_dist_2d(x, goal))
print("Shortest Path:", ret)

Contact

Feel free to contact me if you have any question:

Julian Blank (blankjul [at] egr.msu.edu)
Michigan State University
Computational Optimization and Innovation Laboratory (COIN)
East Lansing, MI 48824, USA

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

pyastar-0.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

pyastar-0.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file pyastar-0.1.tar.gz.

File metadata

  • Download URL: pyastar-0.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pyastar-0.1.tar.gz
Algorithm Hash digest
SHA256 be9b1d32aa22a1bed78bb2e6fd1a3a864ba572791039778d64c133da2f8819b9
MD5 b7837a14e577c914b80802c8458192bb
BLAKE2b-256 7010f5218087ffdb323e891c7978b578c72ba8a301311eeac35cb3ec6f8027a2

See more details on using hashes here.

File details

Details for the file pyastar-0.1-py3-none-any.whl.

File metadata

  • Download URL: pyastar-0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pyastar-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60ba67ce5b2a1514fbc6421d48c36b173ae739a57aeb6b5becd2779a41ee9485
MD5 0a6ab8535383308261de688b5c5f9139
BLAKE2b-256 6838fbc94e0f88cbb821ac98f506ffa2051f504f350080e63ada3c10c709d572

See more details on using hashes here.

Supported by

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