Fast search algorithms for grid-based pathfinding
Project description
cstar – A Fast C++ Pathfinding Wrapper for Python
cstar provides a simple Python interface to high-performance C++ implementations of A*, WA*, Focal Search, and MHA*. It supports fast 2D/3D grid pathfinding with diagonal movement.
Features
- Core A*, WA*, Focal Search, and MHA* implementations in C++ for speed
- Clean Python API with 2D and 3D wrappers
- Supports 8-direction (2D) and 26-direction (3D) movement
- Works with 2D and 3D NumPy arrays
- Benchmark script included in
/benchmarks
Installation
Basic:
uv sync
Dev:
uv sync --extra dev
Usage
import numpy as np
from cstar.pathfinding import (
run_astar_2D,
run_wastar_2D,
run_astar_3D,
run_wastar_3D,
run_mhastar_2D,
run_mhastar_3D,
)
grid = np.ones((10, 10), dtype=bool)
path, cost, expansions, expanded = run_astar_2D(grid, 0, 0, 9, 9)
h2d = np.zeros((10, 10), dtype=float)
path_h, cost_h, expansions_h, expanded_h = run_wastar_2D(
grid, 0, 0, 9, 9, w=1.2
)
path_mha, cost_mha, expansions_mha, expanded_mha = run_mhastar_2D(
grid, h2d, 0, 0, 9, 9, w1=1.0, w2=1.0
)
print(path)
print(cost)
print(expansions)
print(expanded)
grid3d = np.ones((10, 10, 5), dtype=bool)
path3d, cost3d, expansions3d, expanded3d = run_astar_3D(grid3d, 0, 0, 0, 9, 9, 4)
h3d = np.zeros((10, 10, 5), dtype=float)
path3d_h, cost3d_h, expansions3d_h, expanded3d_h = run_astar_3D_heuristic_grid(
grid3d, 0, 0, 0, 9, 9, 4, heuristic_grid=h3d, w=1.2
)
path3d_mha, cost3d_mha, expansions3d_mha, expanded3d_mha = run_mhastar_3D(
grid3d, h3d, 0, 0, 0, 9, 9, 4, w1=1.0, w2=1.0
)
API: pathfinding wrappers
Parameters
- 2D wrappers:
run_astar_2Drun_wastar_2Drun_focal_search_2Drun_mhastar_2D
- 3D wrappers:
run_astar_3Drun_wastar_3Drun_focal_search_3Drun_mhastar_3D
Common parameters
- grid: 2D/3D boolean NumPy array with True = walkable, False = obstacle (autoconverted to bool if necessary and possible)
- x_start, y_start (, z_start): start coordinates
- x_target, y_target (, z_target): target coordinates
Returns
- path: NumPy array [N, 2] or [N, 3] of path waypoints
- cost: float total path cost
- expansions: int number of nodes expanded during the search
- expanded: boolean grid matching input shape with expanded nodes marked True
Edge behavior:
- The default assumes non uniform step costs (octile distance based), 2D functions have an optional parameter for uniform step costs
- The model can always move diagonal if the diagonal cell is free, even if all other neighboring cells of the current node and diagonal node are blocked. This is mostly standard, can however be undesired for some real world applications.
Benchmarks
A benchmark script is available in the /benchmarks directory, showing performance comparisons with the python based pathfinding2D library and the C++ based pyastar library.
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 Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cstar_pathfinding-0.1.0.tar.gz.
File metadata
- Download URL: cstar_pathfinding-0.1.0.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
077ff1d50182cc9dd271a79ed7ee4da3cb7d183756106e80cc11d32211f11ebc
|
|
| MD5 |
64b09e2f0dbab2a332a8200a9277b726
|
|
| BLAKE2b-256 |
771fe4881512ce0abad8e02898c42d8c8f79ebe25768ce881715db72c3db85c9
|
File details
Details for the file cstar_pathfinding-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: cstar_pathfinding-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 423.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56ef4961affde68183fdb7f7e34309f0b5236e86478f1e75dcb3a35750d08106
|
|
| MD5 |
9bf5276339208d16a7e74d6a17e2e286
|
|
| BLAKE2b-256 |
ca78f8c37703fa2b3ef943d7d90799e00f62710de0dad3b2a249169353034c10
|
File details
Details for the file cstar_pathfinding-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: cstar_pathfinding-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 420.1 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08b5df32e2da93d20d4f8a3d9c9440de9d8ba4321f8d0daa884aed01da0fa1e3
|
|
| MD5 |
fc63aeb191814f88aa1e2a5d2509371e
|
|
| BLAKE2b-256 |
52c2c2a1e02c3829083163ca0c181de42c163091757b60173b917613f9bd4802
|
File details
Details for the file cstar_pathfinding-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: cstar_pathfinding-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 417.0 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d36a2c5587a7ee8eb110a30eb26ec6d126efdfb783019be7cbbe513544da514
|
|
| MD5 |
7b5a35211f565cebf01d1415d878113a
|
|
| BLAKE2b-256 |
a7b0d0bf2971b0f8943a9ad51a1ac531e8da8965cd5e21b3b60d6bc12911ac04
|
File details
Details for the file cstar_pathfinding-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: cstar_pathfinding-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 417.7 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfbad8f5e4bab1d163b07910b35b16b0f48b435aa4dd8cd7166f58288e8b8246
|
|
| MD5 |
3b5c85de9dc10c5728bcdee15c96c164
|
|
| BLAKE2b-256 |
e84c284a0073addabe5fcb1965e7a17d0f120dda8386379d54934721ba417fc4
|