Created
August 1, 2020 02:29
-
-
Save hjweide/1586715f5a2762e80a917bfc2c827dd1 to your computer and use it in GitHub Desktop.
Benchmarking 2D-A* algorithms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import imageio | |
import numpy as np | |
import pyastar | |
def maze_to_grid(img): | |
grid = img.astype(np.float32) | |
grid[grid == 0] = np.inf | |
grid[grid == 255] = 1 | |
return grid | |
def test_smooth_1000(benchmark): | |
filepath = "/home/hendrik/work/astar-gridmap-2d/data/maze_1000_smooth.pgm" | |
img = imageio.imread(filepath) | |
grid = maze_to_grid(img) | |
height, width = grid.shape[0:2] | |
start = (0, width // 2) | |
end = (height - 1, width // 2) | |
benchmark(pyastar.astar_path, grid, start, end, True) | |
def test_large(benchmark): | |
filepath = "/home/hendrik/work/astar-gridmap-2d/data/maze_large.pgm" | |
img = imageio.imread(filepath) | |
grid = maze_to_grid(img) | |
height, width = grid.shape[0:2] | |
start = (0, width // 2) | |
end = (height - 1, width // 2) | |
benchmark(pyastar.astar_path, grid, start, end, True) | |
def test_small(benchmark): | |
filepath = "/home/hendrik/work/astar-gridmap-2d/data/maze_250.pgm" | |
img = imageio.imread(filepath) | |
grid = maze_to_grid(img) | |
height, width = grid.shape[0:2] | |
start = (0, width // 2) | |
end = (height // 2, width // 2) | |
benchmark(pyastar.astar_path, grid, start, end, True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment