diff --git a/Search-based Planning/.idea/workspace.xml b/Search-based Planning/.idea/workspace.xml
index 27cfbb5..4682921 100644
--- a/Search-based Planning/.idea/workspace.xml
+++ b/Search-based Planning/.idea/workspace.xml
@@ -19,7 +19,11 @@
-
+
+
+
+
+
@@ -51,7 +55,7 @@
-
+
@@ -159,8 +163,8 @@
-
+
@@ -198,22 +202,22 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
diff --git a/Search-based Planning/__pycache__/plotting.cpython-37.pyc b/Search-based Planning/__pycache__/plotting.cpython-37.pyc
index b091284..eb55214 100644
Binary files a/Search-based Planning/__pycache__/plotting.cpython-37.pyc and b/Search-based Planning/__pycache__/plotting.cpython-37.pyc differ
diff --git a/Search-based Planning/ara_star.py b/Search-based Planning/ara_star.py
index c5f9683..2b2928e 100644
--- a/Search-based Planning/ara_star.py
+++ b/Search-based Planning/ara_star.py
@@ -15,7 +15,7 @@ class AraStar:
self.u_set = self.Env.motions # feasible input set
self.obs = self.Env.obs # position of obstacles
- self.e = 3
+ self.e = 2.5
self.g = {self.xI: 0, self.xG: float("inf")}
self.fig_name = "ARA_Star Algorithm"
@@ -24,47 +24,57 @@ class AraStar:
self.INCONS = []
self.parent = {self.xI: self.xI}
- def searching(self):
- path = []
+ self.path = []
+ self.visited = []
+ def searching(self):
self.OPEN.put(self.xI, self.fvalue(self.xI))
self.ImprovePath()
-
- path.append(self.extract_path())
+ self.path.append(self.extract_path())
while self.update_e() > 1:
self.e -= 0.5
+ print(self.e)
OPEN_mid = [x for (p, x) in self.OPEN.enumerate()] + self.INCONS
self.OPEN = queue.QueuePrior()
+ self.OPEN.put(self.xI, self.fvalue(self.xI))
for x in OPEN_mid:
self.OPEN.put(x, self.fvalue(x))
+
self.INCONS = []
self.CLOSED = []
self.ImprovePath()
+ self.path.append(self.extract_path())
- path.append(self.extract_path())
-
- return path
+ return self.path, self.visited
def ImprovePath(self):
- while (not self.OPEN.empty() and self.fvalue(self.xG) >
+ visited_each = []
+ while (self.fvalue(self.xG) >
min([self.fvalue(x) for (p, x) in self.OPEN.enumerate()])):
s = self.OPEN.get()
- self.CLOSED.append(s)
+
+ if s not in self.CLOSED:
+ self.CLOSED.append(s)
for u_next in self.u_set:
s_next = tuple([s[i] + u_next[i] for i in range(len(s))])
+
if s_next not in self.obs:
new_cost = self.g[s] + self.get_cost(s, u_next)
if s_next not in self.g or new_cost < self.g[s_next]:
self.g[s_next] = new_cost
self.parent[s_next] = s
+ visited_each.append(s_next)
+
if s_next not in self.CLOSED:
self.OPEN.put(s_next, self.fvalue(s_next))
else:
self.INCONS.append(s_next)
+ self.visited.append(visited_each)
+
def update_e(self):
c_OPEN, c_INCONS = float("inf"), float("inf")
@@ -76,8 +86,8 @@ class AraStar:
if min(c_OPEN, c_INCONS) == float("inf"):
return 1
- else:
- return min(self.e, self.g[self.xG] / min(c_OPEN, c_INCONS))
+
+ return min(self.e, self.g[self.xG] / min(c_OPEN, c_INCONS))
def fvalue(self, x):
h = self.e * self.Heuristic(x)
@@ -143,23 +153,10 @@ def main():
arastar = AraStar(x_start, x_goal, "manhattan")
plot = plotting.Plotting(x_start, x_goal)
- path = arastar.searching()
+ fig_name = "ARA* algorithm"
+ path, visited = arastar.searching()
- plot.plot_grid("ARA*")
-
- print(arastar.e)
-
- for path_i in path:
- path_i.remove(x_start)
- path_i.remove(x_goal)
-
- path_x = [path_i[i][0] for i in range(len(path_i))]
- path_y = [path_i[i][1] for i in range(len(path_i))]
-
- plt.plot(path_x, path_y, linewidth='3', marker='o')
- plt.pause(1)
-
- plt.show()
+ plot.animation_ara_star(path, visited, fig_name)
if __name__ == '__main__':
diff --git a/Search-based Planning/plotting.py b/Search-based Planning/plotting.py
index 625529c..7bfd526 100644
--- a/Search-based Planning/plotting.py
+++ b/Search-based Planning/plotting.py
@@ -12,6 +12,7 @@ class Plotting:
self.plot_grid(name)
self.plot_visited(visited)
self.plot_path(path)
+ plt.show()
def plot_grid(self, name):
obs_x = [self.obs[i][0] for i in range(len(self.obs))]
@@ -23,31 +24,62 @@ class Plotting:
plt.title(name)
plt.axis("equal")
- def plot_visited(self, visited):
- visited.remove(self.xI)
+ def plot_visited(self, visited, cl='gray'):
+ if self.xI in visited:
+ visited.remove(self.xI)
+
+ if self.xG in visited:
+ visited.remove(self.xG)
+
count = 0
for x in visited:
count += 1
- plt.plot(x[0], x[1], linewidth='3', color='#808080', marker='o')
+ plt.plot(x[0], x[1], linewidth='3', color=cl, marker='o')
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
if count < len(visited) / 3:
length = 15
elif count < len(visited) * 2 / 3:
- length = 30
+ length = 25
else:
- length = 45
+ length = 35
- if count % length == 0: plt.pause(0.001)
+ if count % length == 0:
+ plt.pause(0.001)
+ plt.pause(0.01)
+
+ def plot_path(self, path, cl='r', flag=False):
+ if self.xI in path:
+ path.remove(self.xI)
+
+ if self.xG in path:
+ path.remove(self.xG)
- def plot_path(self, path):
- path.remove(self.xI)
- path.remove(self.xG)
path_x = [path[i][0] for i in range(len(path))]
path_y = [path[i][1] for i in range(len(path))]
- plt.plot(path_x, path_y, linewidth='3', color='r', marker='o')
+ if not flag:
+ plt.plot(path_x, path_y, linewidth='3', color='r', marker='o')
+ else:
+ plt.plot(path_x, path_y, linewidth='3', color=cl, marker='o')
+
plt.pause(0.01)
+
+ def animation_ara_star(self, path, visited, name):
+ self.plot_grid(name)
+ cl_v, cl_p = self.color_list()
+
+ for k in range(len(path)):
+ self.plot_visited(visited[k], cl_v[k])
+ self.plot_path(path[k], cl_p[k], True)
+ plt.pause(0.5)
+
plt.show()
+
+ @staticmethod
+ def color_list():
+ cl_v = ['silver', 'wheat', 'lightskyblue', 'plum', 'slategray']
+ cl_p = ['gray', 'orange', 'deepskyblue', 'red', 'm']
+ return cl_v, cl_p