Skip to content

Instantly share code, notes, and snippets.

@hjweide
Created August 1, 2020 02:29
Show Gist options
  • Save hjweide/1586715f5a2762e80a917bfc2c827dd1 to your computer and use it in GitHub Desktop.
Save hjweide/1586715f5a2762e80a917bfc2c827dd1 to your computer and use it in GitHub Desktop.
Benchmarking 2D-A* algorithms
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