Update breadth_first_search.py (#374)

This commit is contained in:
yashvarshney003
2020-08-15 08:24:36 +05:30
committed by GitHub
parent 6d29bcd97d
commit 750e8a185e
7 changed files with 85 additions and 17 deletions

View File

@@ -33,16 +33,16 @@ class BreadthFirstSearchPlanner:
self.motion = self.get_motion_model()
class Node:
def __init__(self, x, y, cost, pind, parent):
def __init__(self, x, y, cost, parent_index, parent):
self.x = x # index of grid
self.y = y # index of grid
self.cost = cost
self.pind = pind
self.parent_index = parent_index
self.parent = parent
def __str__(self):
return str(self.x) + "," + str(self.y) + "," + str(
self.cost) + "," + str(self.pind)
self.cost) + "," + str(self.parent_index)
def planning(self, sx, sy, gx, gy):
"""
@@ -92,7 +92,7 @@ class BreadthFirstSearchPlanner:
if current.x == ngoal.x and current.y == ngoal.y:
print("Find goal")
ngoal.pind = current.pind
ngoal.parent_index = current.parent_index
ngoal.cost = current.cost
break

View File

@@ -33,16 +33,16 @@ class DepthFirstSearchPlanner:
self.motion = self.get_motion_model()
class Node:
def __init__(self, x, y, cost, pind, parent):
def __init__(self, x, y, cost, parent_index, parent):
self.x = x # index of grid
self.y = y # index of grid
self.cost = cost
self.pind = pind
self.parent_index = parent_index
self.parent = parent
def __str__(self):
return str(self.x) + "," + str(self.y) + "," + str(
self.cost) + "," + str(self.pind)
self.cost) + "," + str(self.parent_index)
def planning(self, sx, sy, gx, gy):
"""
@@ -88,7 +88,7 @@ class DepthFirstSearchPlanner:
if current.x == ngoal.x and current.y == ngoal.y:
print("Find goal")
ngoal.pind = current.pind
ngoal.parent_index = current.parent_index
ngoal.cost = current.cost
break

View File

@@ -38,15 +38,15 @@ class Dijkstra:
self.motion = self.get_motion_model()
class Node:
def __init__(self, x, y, cost, parent):
def __init__(self, x, y, cost, parent_index):
self.x = x # index of grid
self.y = y # index of grid
self.cost = cost
self.parent = parent # index of previous Node
self.parent_index = parent_index # index of previous Node
def __str__(self):
return str(self.x) + "," + str(self.y) + "," + str(
self.cost) + "," + str(self.parent)
self.cost) + "," + str(self.parent_index)
def planning(self, sx, sy, gx, gy):
"""
@@ -88,7 +88,7 @@ class Dijkstra:
if current.x == goal_node.x and current.y == goal_node.y:
print("Find goal")
goal_node.parent = current.parent
goal_node.parent_index = current.parent_index
goal_node.cost = current.cost
break
@@ -126,12 +126,12 @@ class Dijkstra:
# generate final course
rx, ry = [self.calc_position(goal_node.x, self.min_x)], [
self.calc_position(goal_node.y, self.min_y)]
parent = goal_node.parent
while parent != -1:
n = closed_set[parent]
parent_index = goal_node.parent_index
while parent_index != -1:
n = closed_set[parent_index]
rx.append(self.calc_position(n.x, self.min_x))
ry.append(self.calc_position(n.y, self.min_y))
parent = n.parent
parent_index = n.parent_index
return rx, ry

View File

@@ -124,6 +124,8 @@ All animation gifs are stored here: [AtsushiSakai/PythonRoboticsGifs: Animation
2. Install the required libraries. You can use environment.yml with conda command.
> conda env create -f environment.yml
> using pip :-
pip install -r requirements.txt
3. Execute python script in each directory.

View File

@@ -0,0 +1,26 @@
from unittest import TestCase
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
"/../PathPlanning/BreadthFirstSearch/")
try:
import breadth_first_search as m
except ImportError:
raise
print(__file__)
class Test(TestCase):
def test1(self):
m.show_animation = False
m.main()
if __name__ == '__main__': # pragma: no cover
test = Test()
test.test1()

View File

@@ -0,0 +1,26 @@
from unittest import TestCase
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
"/../PathPlanning/DepthFirstSearch/")
try:
import depth_first_search as m
except ImportError:
raise
print(__file__)
class Test(TestCase):
def test1(self):
m.show_animation = False
m.main()
if __name__ == '__main__': # pragma: no cover
test = Test()
test.test1()

View File

@@ -1,6 +1,15 @@
from unittest import TestCase
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
"/../PathPlanning/Dijkstra/")
try:
import dijkstra as m
except ImportError:
raise
from PathPlanning.Dijkstra import dijkstra as m
print(__file__)
@@ -10,3 +19,8 @@ class Test(TestCase):
def test1(self):
m.show_animation = False
m.main()
if __name__ == '__main__': # pragma: no cover
test = Test()
test.test1()