Running Test Cases

Note that animation rendering might take a couple of seconds

BFS

In [1]:
%reload_ext autoreload
%autoreload 2

from pathfinding import demo, grid, utils, finder
from pathfinding.grid import core, viz
In [5]:
cases = demo.get_case_files()
In [6]:
start, end, polygons = cases[0]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.bfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
In [21]:
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[21]:


Once Loop Reflect
In [22]:
start, end, polygons = cases[1]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.bfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
In [23]:
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[23]:


Once Loop Reflect
In [24]:
start, end, polygons = cases[3]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.bfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
In [25]:
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[25]:


Once Loop Reflect
In [26]:
start, end, polygons = cases[4]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.bfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
In [27]:
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[27]:


Once Loop Reflect

DFS

In [29]:
start, end, polygons = cases[0]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.dfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[29]:


Once Loop Reflect
In [30]:
start, end, polygons = cases[1]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.dfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[30]:


Once Loop Reflect
In [31]:
start, end, polygons = cases[2]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.dfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[31]:


Once Loop Reflect
In [32]:
start, end, polygons = cases[3]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.dfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[32]:


Once Loop Reflect
In [33]:
start, end, polygons = cases[4]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.dfs(maze, core.find_walkable_neighbors, start, end, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[33]:


Once Loop Reflect

A*

In [34]:
def cost(p0, p1): return 1
def md(p0, p1):
    return abs(p1[0] - p0[0]) + abs(p1[1] - p0[1])

start, end, polygons = cases[0]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.astar(maze, core.find_walkable_neighbors, start, end, cost=cost, heuristic=md, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[34]:


Once Loop Reflect
In [35]:
start, end, polygons = cases[1]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.astar(maze, core.find_walkable_neighbors, start, end, cost=cost, heuristic=md, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[35]:


Once Loop Reflect
In [36]:
start, end, polygons = cases[2]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.astar(maze, core.find_walkable_neighbors, start, end, cost=cost, heuristic=md, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[36]:


Once Loop Reflect
In [37]:
start, end, polygons = cases[3]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.astar(maze, core.find_walkable_neighbors, start, end, cost=cost, heuristic=md, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[37]:


Once Loop Reflect
In [38]:
start, end, polygons = cases[4]
maze = grid.generate(200, 100, polygons)

path, expansion = finder.astar(maze, core.find_walkable_neighbors, start, end, cost=cost, heuristic=md, with_expansion=True)
utils.render_image(viz.generate_image(maze, start, end, path))
utils.render_anim(viz.generate_anim(maze, start, end, path, expansion))
Out[38]:


Once Loop Reflect

Let's now jump to timing and conclusions


This is a post in the CS 180 Pathfinding series.
Other posts in this series:

Arian Valdez @Secretmapper

React.JS and Node.JS Software engineering consultant. Developer/Designer Hybrid. Author of Alt Tracker, Combustion, Riyu, etc.