17
17
show_animation = True
18
18
19
19
20
- class BFSPlanner :
20
+ class BreadthFirstSearchPlanner :
21
21
22
22
def __init__ (self , ox , oy , reso , rr ):
23
23
"""
@@ -48,7 +48,7 @@ def __str__(self):
48
48
49
49
def planning (self , sx , sy , gx , gy ):
50
50
"""
51
- Breadth First search
51
+ Breadth First search based planning
52
52
53
53
input:
54
54
sx: start x position [m]
@@ -101,12 +101,10 @@ def planning(self, sx, sy, gx, gy):
101
101
del open_set [c_id ]
102
102
103
103
# expand_grid search grid based on motion model
104
- successors = [self .Node (current .x + self .motion [i ][0 ],
104
+ for i , _ in enumerate (self .motion ):
105
+ node = self .Node (current .x + self .motion [i ][0 ],
105
106
current .y + self .motion [i ][1 ],
106
- current .cost + self .motion [i ][2 ], c_id + 1 , current ) for i , _ in enumerate (self .motion )]
107
-
108
- random .shuffle (successors )
109
- for node in successors :
107
+ current .cost + self .motion [i ][2 ], c_id + 1 , current )
110
108
n_id = self .calc_grid_index (node )
111
109
112
110
# If the node is not safe, do nothing
@@ -132,12 +130,6 @@ def calc_final_path(self, ngoal, closedset):
132
130
133
131
return rx , ry
134
132
135
- @staticmethod
136
- def calc_heuristic (n1 , n2 ):
137
- w = 1.0 # weight of heuristic
138
- d = w * math .hypot (n1 .x - n2 .x , n1 .y - n2 .y )
139
- return d
140
-
141
133
def calc_grid_position (self , index , minp ):
142
134
"""
143
135
calc grid position
@@ -257,7 +249,7 @@ def main():
257
249
plt .grid (True )
258
250
plt .axis ("equal" )
259
251
260
- bfs = BFSPlanner (ox , oy , grid_size , robot_radius )
252
+ bfs = BreadthFirstSearchPlanner (ox , oy , grid_size , robot_radius )
261
253
rx , ry = bfs .planning (sx , sy , gx , gy )
262
254
263
255
if show_animation : # pragma: no cover
0 commit comments