Skip to content

Commit 79055bf

Browse files
committed
adding examples
1 parent ba47ae4 commit 79055bf

File tree

6 files changed

+97
-0
lines changed

6 files changed

+97
-0
lines changed

examples/astar_ex.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import algorithms.a_star_path_finding as pf
2+
import astar_utils as autils
3+
reload(autils)
4+
5+
a = pf.AStar()
6+
walls = ((0, 5), (1, 0), (1, 1), (1, 5), (2, 3),
7+
(3, 1), (3, 2), (3, 5), (4, 1), (4, 4), (5, 1))
8+
start = (0,0)
9+
end= (5,5)
10+
a.init_grid(6, 6, walls, start, end)
11+
path = a.solve()
12+
13+
fig=figure(1)
14+
clf()
15+
autils.plotAstar(a,path)
16+
show()

examples/astar_fdeco.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# Size of space
3+
N = 200
4+
NodeWidth = 2
5+
NodeCenter = (100,100)
6+
NodeOrient = 0
7+
def make_square(center,width,orient):
8+
walls = []
9+
for ii in range(width):
10+
for jj in range(width):
11+
xx = center[0]-width/2+ii
12+
yy = center[1]-width/2+jj
13+
print (xx,yy)
14+
walls.append((xx,yy))
15+
16+
make_square(NodeCenter,NodeWidth,NodeOrient)
17+
#a.init_grid(N,N, tuple(walls), start, end)

examples/astar_rand.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import algorithms.a_star_path_finding as pf
2+
import astar_utils as autils
3+
reload(autils)
4+
5+
cnt=0
6+
pmax=0
7+
for jj in range(1000):
8+
a = pf.AStar()
9+
N = 100
10+
walls = []
11+
start = (0,0)
12+
end= (N-1,N-1)
13+
for ii in range(int((N**2)*.75)):
14+
w = (randint(0,N),randint(0,N))
15+
if (w==start) or (w==end):
16+
pass
17+
else:
18+
walls.append(w)
19+
20+
a.init_grid(N,N, tuple(walls), start, end)
21+
path = a.solve()
22+
23+
if not(path is None):
24+
cnt+=1
25+
if len(path) > pmax:
26+
pmax=len(path)
27+
fig=figure(jj)
28+
clf()
29+
autils.plotAstar(a,path)
30+
31+
show()
32+
print cnt

examples/astar_utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pylab import *
2+
def plotAstar(astar,path):
3+
ax=subplot(111,aspect='equal')
4+
xmax=0.0
5+
ymax=0.0
6+
for c in astar.cells:
7+
bg="white"
8+
if not c.reachable:
9+
bg="black"
10+
elif c==astar.start:
11+
bg="green"
12+
elif c==astar.end:
13+
bg="red"
14+
ax.add_patch(Rectangle((c.x-0.5,c.y-0.5),1.0,1.0,edgecolor="black",facecolor=bg))
15+
xmax=max(xmax,c.x+0.5)
16+
ymax=max(ymax,c.y+0.5)
17+
ax.set_xlim(-0.5,xmax)
18+
ax.set_ylim(-0.5,ymax)
19+
20+
xx = []
21+
yy = []
22+
if not (path is None):
23+
for p in path:
24+
xx.append(p[0])
25+
yy.append(p[1])
26+
plot(xx,yy,'g',linewidth=5)
27+
28+
# Webloes
29+
# Jared Pechan 264-3217

make_venv.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
virtualenv astarvenv

start_venv.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
source astarvenv/bin/activate

0 commit comments

Comments
 (0)