Skip to content

Commit 750e8a1

Browse files
Update breadth_first_search.py (AtsushiSakai#374)
1 parent 6d29bcd commit 750e8a1

File tree

7 files changed

+85
-17
lines changed

7 files changed

+85
-17
lines changed

PathPlanning/BreadthFirstSearch/breadth_first_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ def __init__(self, ox, oy, reso, rr):
3333
self.motion = self.get_motion_model()
3434

3535
class Node:
36-
def __init__(self, x, y, cost, pind, parent):
36+
def __init__(self, x, y, cost, parent_index, parent):
3737
self.x = x # index of grid
3838
self.y = y # index of grid
3939
self.cost = cost
40-
self.pind = pind
40+
self.parent_index = parent_index
4141
self.parent = parent
4242

4343
def __str__(self):
4444
return str(self.x) + "," + str(self.y) + "," + str(
45-
self.cost) + "," + str(self.pind)
45+
self.cost) + "," + str(self.parent_index)
4646

4747
def planning(self, sx, sy, gx, gy):
4848
"""
@@ -92,7 +92,7 @@ def planning(self, sx, sy, gx, gy):
9292

9393
if current.x == ngoal.x and current.y == ngoal.y:
9494
print("Find goal")
95-
ngoal.pind = current.pind
95+
ngoal.parent_index = current.parent_index
9696
ngoal.cost = current.cost
9797
break
9898

PathPlanning/DepthFirstSearch/depth_first_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ def __init__(self, ox, oy, reso, rr):
3333
self.motion = self.get_motion_model()
3434

3535
class Node:
36-
def __init__(self, x, y, cost, pind, parent):
36+
def __init__(self, x, y, cost, parent_index, parent):
3737
self.x = x # index of grid
3838
self.y = y # index of grid
3939
self.cost = cost
40-
self.pind = pind
40+
self.parent_index = parent_index
4141
self.parent = parent
4242

4343
def __str__(self):
4444
return str(self.x) + "," + str(self.y) + "," + str(
45-
self.cost) + "," + str(self.pind)
45+
self.cost) + "," + str(self.parent_index)
4646

4747
def planning(self, sx, sy, gx, gy):
4848
"""
@@ -88,7 +88,7 @@ def planning(self, sx, sy, gx, gy):
8888

8989
if current.x == ngoal.x and current.y == ngoal.y:
9090
print("Find goal")
91-
ngoal.pind = current.pind
91+
ngoal.parent_index = current.parent_index
9292
ngoal.cost = current.cost
9393
break
9494

PathPlanning/Dijkstra/dijkstra.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ def __init__(self, ox, oy, resolution, robot_radius):
3838
self.motion = self.get_motion_model()
3939

4040
class Node:
41-
def __init__(self, x, y, cost, parent):
41+
def __init__(self, x, y, cost, parent_index):
4242
self.x = x # index of grid
4343
self.y = y # index of grid
4444
self.cost = cost
45-
self.parent = parent # index of previous Node
45+
self.parent_index = parent_index # index of previous Node
4646

4747
def __str__(self):
4848
return str(self.x) + "," + str(self.y) + "," + str(
49-
self.cost) + "," + str(self.parent)
49+
self.cost) + "," + str(self.parent_index)
5050

5151
def planning(self, sx, sy, gx, gy):
5252
"""
@@ -88,7 +88,7 @@ def planning(self, sx, sy, gx, gy):
8888

8989
if current.x == goal_node.x and current.y == goal_node.y:
9090
print("Find goal")
91-
goal_node.parent = current.parent
91+
goal_node.parent_index = current.parent_index
9292
goal_node.cost = current.cost
9393
break
9494

@@ -126,12 +126,12 @@ def calc_final_path(self, goal_node, closed_set):
126126
# generate final course
127127
rx, ry = [self.calc_position(goal_node.x, self.min_x)], [
128128
self.calc_position(goal_node.y, self.min_y)]
129-
parent = goal_node.parent
130-
while parent != -1:
131-
n = closed_set[parent]
129+
parent_index = goal_node.parent_index
130+
while parent_index != -1:
131+
n = closed_set[parent_index]
132132
rx.append(self.calc_position(n.x, self.min_x))
133133
ry.append(self.calc_position(n.y, self.min_y))
134-
parent = n.parent
134+
parent_index = n.parent_index
135135

136136
return rx, ry
137137

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ All animation gifs are stored here: [AtsushiSakai/PythonRoboticsGifs: Animation
124124
2. Install the required libraries. You can use environment.yml with conda command.
125125

126126
> conda env create -f environment.yml
127+
> using pip :-
128+
pip install -r requirements.txt
127129

128130

129131
3. Execute python script in each directory.

tests/test_breadth_first_search.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from unittest import TestCase
2+
import sys
3+
import os
4+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
5+
"/../PathPlanning/BreadthFirstSearch/")
6+
7+
8+
try:
9+
import breadth_first_search as m
10+
except ImportError:
11+
raise
12+
13+
14+
print(__file__)
15+
16+
17+
class Test(TestCase):
18+
19+
def test1(self):
20+
m.show_animation = False
21+
m.main()
22+
23+
24+
if __name__ == '__main__': # pragma: no cover
25+
test = Test()
26+
test.test1()

tests/test_depth_first_search.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from unittest import TestCase
2+
import sys
3+
import os
4+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
5+
"/../PathPlanning/DepthFirstSearch/")
6+
7+
8+
try:
9+
import depth_first_search as m
10+
except ImportError:
11+
raise
12+
13+
14+
print(__file__)
15+
16+
17+
class Test(TestCase):
18+
19+
def test1(self):
20+
m.show_animation = False
21+
m.main()
22+
23+
24+
if __name__ == '__main__': # pragma: no cover
25+
test = Test()
26+
test.test1()

tests/test_dijkstra.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
from unittest import TestCase
2+
import sys
3+
import os
4+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
5+
"/../PathPlanning/Dijkstra/")
6+
7+
8+
try:
9+
import dijkstra as m
10+
except ImportError:
11+
raise
212

3-
from PathPlanning.Dijkstra import dijkstra as m
413

514
print(__file__)
615

@@ -10,3 +19,8 @@ class Test(TestCase):
1019
def test1(self):
1120
m.show_animation = False
1221
m.main()
22+
23+
24+
if __name__ == '__main__': # pragma: no cover
25+
test = Test()
26+
test.test1()

0 commit comments

Comments
 (0)