-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDepthFirstPlanner.py
55 lines (40 loc) · 1.8 KB
/
DepthFirstPlanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from RRTTree import RRTTree
class DepthFirstPlanner(object):
def __init__(self, planning_env, visualize):
self.planning_env = planning_env
self.visualize = visualize
self.nodes = dict()
def Plan(self, start_config, goal_config):
plan = []
# TODO: Here you will implement the depth first planner
# The return path should be a numpy array
# of dimension k x n where k is the number of waypoints
# and n is the dimension of the robots configuration space
plan.append(start_config)
if dfs_rec(start_config) == None: return [] # TODO: or return None
else:
print "Tree size: " + str(len(self.tree.vertices))
currVertex = eid
while (currVertex != tree.GetRootId()):
currVertex = tree.edges[currVertex]
plan.insert(0, tree.vertices[currVertex])
plan.append(goal_config)
return plan
def dfs_rec(parent):
# base case, no children
if(self.planning_env.GetSuccessors(parent) == None):
return None
elif(parent == goal_config):
return
else:
Children = self.planning_env.GetSuccessors(parent)
for child in children:
# avoid revisit and check collision
if child not in recordMarked and (not self.s.Collides(child)):
recordMarked.append(child)
dfs_rec(child)
sid = self.recordMarked.index(parent)
eid = self.tree.AddVertex(child)
self.tree.AddEdge(self, sid, eid)
# visualize the updated tree
self.planning_env.PlotEdge(self, parent, child)