zhm-real 5 سال پیش
والد
کامیت
2538ae42fb
3فایلهای تغییر یافته به همراه37 افزوده شده و 21 حذف شده
  1. 1 1
      Search-based Planning/.idea/workspace.xml
  2. BIN
      Stochastic Shortest Path/gif/VI_E.gif
  3. 36 20
      Stochastic Shortest Path/value_iteration.py

+ 1 - 1
Search-based Planning/.idea/workspace.xml

@@ -2,8 +2,8 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="025aff36-a6aa-4945-ab7e-b2c625055f47" name="Default Changelist" comment="">
-      <change beforePath="$PROJECT_DIR$/../Model-free Control/tools.py" beforeDir="false" afterPath="$PROJECT_DIR$/../Model-free Control/tools.py" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../Stochastic Shortest Path/value_iteration.py" beforeDir="false" afterPath="$PROJECT_DIR$/../Stochastic Shortest Path/value_iteration.py" afterDir="false" />
     </list>
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
     <option name="SHOW_DIALOG" value="false" />

BIN
Stochastic Shortest Path/gif/VI_E.gif


+ 36 - 20
Stochastic Shortest Path/value_iteration.py

@@ -92,32 +92,48 @@ class Value_iteration:
         :return: simulation path
         """
 
-        plt.figure(1)                                               # path animation
-        tools.show_map(xI, xG, self.obs, self.lose, self.name1)     # show background
-
-        x, path = xI, []
-        while True:
-            u = policy[x]
-            x_next = (x[0] + u[0], x[1] + u[1])
-            if x_next in self.obs:
-                print("Collision!")                                 # collision: simulation failed
-            else:
-                x = x_next
-                if x_next in xG: break
-                else:
-                    tools.plot_dots(x)                              # each state in optimal path
-                    path.append(x)
-        plt.pause(1)
-
-        plt.figure(2)                                               # difference between two successive iteration
-        plt.plot(diff, color='#808080', marker='o')
+        # plt.figure(1)                                               # path animation
+        # tools.show_map(xI, xG, self.obs, self.lose, self.name1)     # show background
+        #
+        # x, path = xI, []
+        # while True:
+        #     u = policy[x]
+        #     x_next = (x[0] + u[0], x[1] + u[1])
+        #     if x_next in self.obs:
+        #         print("Collision!")                                 # collision: simulation failed
+        #     else:
+        #         x = x_next
+        #         if x_next in xG: break
+        #         else:
+        #             tools.plot_dots(x)                              # each state in optimal path
+        #             path.append(x)
+        # plt.pause(1)
+
+        # plt.figure(2)                                               # difference between two successive iteration
+        # plt.plot(diff, color='#808080', marker='o')
+        fig, ax = plt.subplots()
+
+        ax.set_xlim(-5, 60)
+        ax.set_ylim(-1, 9)
         plt.title(self.name2, fontdict=None)
         plt.xlabel('iterations')
         plt.ylabel('difference of successive iterations')
         plt.grid('on')
+
+        count = 0
+
+        for x in diff:
+            plt.plot(count, x, color='#808080', marker='o')  # plot dots for animation
+            plt.gcf().canvas.mpl_connect('key_release_event',
+                                         lambda event: [exit(0) if event.key == 'escape' else None])
+            plt.pause(0.07)
+            count += 1
+
+        plt.plot(diff, color='#808080')
+        plt.pause(0.01)
         plt.show()
 
-        return path
+        return
 
 
     def message(self, count):