Pathfinding algorithms in 3D (based on python-pathfinding)
Project description
Pathfinding3D
Pathfinding algorithms for python3 froked from python-pathfinding by @brean.
Currently there are 7 path-finders bundled in this library, namely:
- A*
- Dijkstra
- Best-First
- Bi-directional A*
- Breadth First Search (BFS)
- Iterative Deeping A* (IDA*)
- Minimum Spanning Tree (MSP)
Dijkstra, A* and Bi-directional A* take the weight of the fields on the map into account.
Installation
The package is available on pypi, so you can install it with pip:
pip install pathfinding3d
Usage examples
For usage examples with detailed descriptions take a look at the examples folder, also take a look at the test/ folder for more examples.
Rerun the algorithm
While running the pathfinding algorithm it might set values on the nodes. Depending on your path finding algorithm things like calculated distances or visited flags might be stored on them. So if you want to run the algorithm in a loop you need to clean the grid first (see Grid.cleanup
). Please note that because cleanup looks at all nodes of the grid it might be an operation that can take a bit of time!
Implementation details
All pathfinding algorithms in this library are inheriting the Finder class. It has some common functionality that can be overwritten by the implementation of a path finding algorithm.
The normal process works like this:
- You call
find_path
on one of your finder implementations. init_find
instantiates theopen_list
and resets all values and counters.- The main loop starts on the
open_list
. This list gets filled with all nodes that will be processed next (e.g. all current neighbors that are walkable). For this you need to implementcheck_neighbors
in your own finder implementation. - For example in A*s implementation of
check_neighbors
you first want to get the next node closest from the current starting point from the open list. thenext_node
method in Finder does this by giving you the node with a minimumf
-value from the open list, it closes it and removes it from theopen_list
. - if this node is not the end node we go on and get its neighbors by calling
find_neighbors
. This just callsgrid.neighbors
for most algorithms. - If none of the neighbors are the end node we want to process the neighbors to calculate their distances in
process_node
process_node
calculates the costf
from the start to the current node using thecalc_cost
method and the cost after calculatingh
fromapply_heuristic
.- finally
process_node
updates the open list sofind_path
can runcheck_neighbors
on it in the next node in the next iteration of the main loop.
flow:
find_path
init_find # (re)set global values and open list
check_neighbors # for every node in open list
next_node # closest node to start in open list
find_neighbors # get neighbors
process_node # calculate new cost for neighboring node
Testing
You can run the tests locally using pytest. Take a look at the test
-folder
Contributing
Please use the issue tracker to submit bug reports and feature requests. Please use merge requests as described here to add/adapt functionality.
License
python-pathfinding is distributed under the MIT license.
Authors / Contributers
Authors and contributers are listed on github.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pathfinding3d-0.4.0.tar.gz
.
File metadata
- Download URL: pathfinding3d-0.4.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd3d2340175dfdf69e3812d917a15b2d68ce8340ca7fd6780a676d137527d19b |
|
MD5 | c2ebf6dd0ef2acd3d5d36b6ce7f31290 |
|
BLAKE2b-256 | 594a138631a7dd8300413fb5645d01c069c74c32c770d7d77d1a4f0b7060afb8 |
File details
Details for the file pathfinding3d-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: pathfinding3d-0.4.0-py3-none-any.whl
- Upload date:
- Size: 24.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1075ea3a50721ba65c5743d87bfb11d2851334012269e0c194c2994ee44e90df |
|
MD5 | 25796849689e1aaff7a952955109dcb2 |
|
BLAKE2b-256 | 31f7a1f9e43926a1e324ca1aaacb3eb6dbdc59ce200dc2dd67097056a78c5117 |