diff --git a/README.md b/README.md
index 200a3a3304ef66f78d38ad39d630e4c13bdc343e..d4ddaddd3299cbf74994203af7a156d096c6eea1 100644
--- a/README.md
+++ b/README.md
@@ -179,4 +179,12 @@
 - Able to show the learning process:
   - Trying different combination of solving order
   - Try to give the best order of solving multiple path
-  - ![path_learning.gif](journal_media/path_learning.gif)
\ No newline at end of file
+##### Auto-routing learning process:
+  - ![path_learning.gif](journal_media/path_learning.gif)
+
+- Comparison between episodes and choose best combo of paths
+- ![learning_episodes.gif](journal_media/learning_episodes.gif)
+
+##### Issues and TODO
+- Path export from optimization is messed up
+- Obstacles setting are incorrect
\ No newline at end of file
diff --git a/analyze_dxf.py b/analyze_dxf.py
index bb8aff8823e573b6df8e7c39f94be023eff42432..c16f9a0af2f5e681f391395b6bbf92debeee1767 100644
--- a/analyze_dxf.py
+++ b/analyze_dxf.py
@@ -15,15 +15,12 @@ import matplotlib.animation as animation
 from matplotlib import cm
 from array2gif import write_gif
 
-class dxf_editor:
+class auto_rounter:
     def __init__(self,path,dxf_file):
         self.dwg=ezdxf.readfile(path+dxf_file)
         self.msp=self.dwg.modelspace()
         self.dxf_name='silhouette_ele.dxf'
-        self.fig=plt.figure()
-
-        # self.fig.show()
-        # self.img_name='silouette_ele.png'
+        self.fail_flag=False #return True when path not found
         
         
         self.create_layer('Cut',5)
@@ -54,22 +51,15 @@ class dxf_editor:
         
         self.connections_list=np.rint(self.connections_list)[1:]
         
-        self.matrix_temp=copy.deepcopy(self.matrix)
-        self.img=plt.imshow(self.matrix_temp,interpolation='nearest',cmap=cm.Spectral)
-        
-
-        ani=animation.FuncAnimation(self.fig,self.find_multi_path,interval=10)
-
-        plt.show()
+        # self.matrix_temp=copy.deepcopy(self.matrix)
+        # self.img=plt.imshow(self.matrix_temp,interpolation='nearest',cmap=cm.Spectral)
+        # ani=animation.FuncAnimation(self.fig,self.find_multi_path,interval=10)
+        # plt.show()
 
+        self.find_multi_path(1)
         self.dwg.saveas(self.dxf_name)
-        # os.system("inkscape -f silhouette_ele.dxf -e silouette_ele.png")
-        
 
-        # self.img=cv2.imread(path+self.img_name)
-        # print(self.img)
-    def update_img(self,i):
-        self.img.set_array(i)
+
 
     def create_layer(self,layer_name,color):
         if not layer_name in self.dwg.layers:
@@ -193,6 +183,8 @@ class dxf_editor:
     
     def get_cost(self,path):
         if len(path)==0: #if no path found
+            print('one path not found')
+            self.fail_flag=True
             cost=1000
         else: cost=len(path)
 
@@ -200,37 +192,56 @@ class dxf_editor:
 
 
     def find_multi_path(self,i):
-        """pin_connection shape : NX2X2 """
-        E=1
-        print('test=========')
+        """connection list shape : NX2X2 """
+        E=7
+        print("==========Auto rounting start===========")
+        
         for episode in range(E):
+            print 'episode:',episode+1,'==========='
             self.matrix_temp=copy.deepcopy(self.matrix)
             self.Q=0
+            self.fail_flag=False
+
             random_ix=random.randint(0,len(self.connections_list)-1)
             init_s=self.connections_list[random_ix]
+            current_solving=np.array([init_s]).reshape(1,2,2)
             con_list_temp=np.delete(self.connections_list,random_ix,axis=0)
             
-            cur_path=self.find_a_path(self.matrix_temp,init_s[0],init_s[1])
-            self.draw_a_path(cur_path,self.matrix_temp)
-            self.img.set_array(self.matrix_temp)
+            self.cur_path=self.find_a_path(self.matrix_temp,init_s[0],init_s[1])
+            self.draw_a_path(self.cur_path,self.matrix_temp)
+            # self.img.set_array(self.matrix_temp)
             
-            cost=self.get_cost(cur_path)
+            cost=self.get_cost(self.cur_path)
             self.Q=self.Q+cost
             
             while len(con_list_temp)!=0:
                 random_ix=random.randint(0,len(con_list_temp)-1)
                 next_conn=con_list_temp[random_ix]
+                current_solving=np.append(current_solving,next_conn.reshape(1,2,2),axis=0)
                 con_list_temp=np.delete(con_list_temp,random_ix,axis=0)
-        
                 
-                curpath=self.find_a_path(self.matrix_temp,next_conn[0],next_conn[1])
-                self.draw_a_path(curpath,self.matrix_temp)
-                self.img.set_array(self.matrix_temp)
+                self.curpath=self.find_a_path(self.matrix_temp,next_conn[0],next_conn[1])
+                self.draw_a_path(self.curpath,self.matrix_temp)
+                # self.img.set_array(self.matrix_temp)
                
-                cost=self.get_cost(curpath)
+                cost=self.get_cost(self.curpath)
                 self.Q=self.Q+cost
-            
+
+            if episode==0:
+                self.Q_buff=copy.deepcopy(self.Q)
+            if self.Q<=self.Q_buff:
+                self.Q_buff=copy.deepcopy(self.Q)
+                self.final_solving=current_solving
+                self.final_path=self.cur_path
+                self.final_fail=self.fail_flag
+                
+            print 'Current cost:',self.Q,'Best cost',self.Q_buff
             episode+=1 
+        if not self.final_fail:
+            self.draw_a_path(self.final_path,self.matrix,True)
+            # self.draw_a_path(self.final_path[1],self.matrix,True)
+        else:
+            print 'Cannot solve more than one path'
 
         # plt.imshow(self.matrix_temp)
         # plt.show()
@@ -240,7 +251,7 @@ class dxf_editor:
 # def main():
 path='/home/jingyan/Documents/summer_intern_lemur/roco_electrical/'
 dxf_file='graph-silhouette.dxf'
-edit=dxf_editor(path,dxf_file)
+router=auto_rounter(path,dxf_file)
 # animation.FuncAnimation(edit.fig,plt.imshow(edit.matrix_temp))
 # plt.show()
 
diff --git a/journal_media/learning_episodes.gif b/journal_media/learning_episodes.gif
new file mode 100644
index 0000000000000000000000000000000000000000..be083a6bae5092ed643cfebe377ef1819701e2fa
Binary files /dev/null and b/journal_media/learning_episodes.gif differ
diff --git a/silhouette_ele.dxf b/silhouette_ele.dxf
index 7f8de82277e955d658c5d23a3fa1d9672a54a2a9..38e1a9d0dd0acebcb8f2ea5aa81818f2b2301e93 100644
--- a/silhouette_ele.dxf
+++ b/silhouette_ele.dxf
@@ -53,11 +53,11 @@ $HANDLING
   9
 $TDUPDATE
  40
-2458673.53419
+2458673.68162
   9
 $HANDSEED
   5
-30B
+322
   9
 $DWGCODEPAGE
   3
@@ -10513,6 +10513,420 @@ ISO_BLK
  67
 0
   0
+LINE
+  5
+30B
+  8
+Circuit
+ 10
+97.0
+ 20
+186.0
+ 11
+98.0
+ 21
+186.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+30C
+  8
+Circuit
+ 10
+98.0
+ 20
+186.0
+ 11
+99.0
+ 21
+186.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+30D
+  8
+Circuit
+ 10
+99.0
+ 20
+186.0
+ 11
+100.0
+ 21
+186.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+30E
+  8
+Circuit
+ 10
+100.0
+ 20
+186.0
+ 11
+101.0
+ 21
+186.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+30F
+  8
+Circuit
+ 10
+101.0
+ 20
+186.0
+ 11
+102.0
+ 21
+187.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+310
+  8
+Circuit
+ 10
+102.0
+ 20
+187.0
+ 11
+103.0
+ 21
+188.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+311
+  8
+Circuit
+ 10
+103.0
+ 20
+188.0
+ 11
+104.0
+ 21
+188.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+312
+  8
+Circuit
+ 10
+104.0
+ 20
+188.0
+ 11
+105.0
+ 21
+188.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+313
+  8
+Circuit
+ 10
+105.0
+ 20
+188.0
+ 11
+106.0
+ 21
+188.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+314
+  8
+Circuit
+ 10
+106.0
+ 20
+188.0
+ 11
+107.0
+ 21
+189.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+315
+  8
+Circuit
+ 10
+107.0
+ 20
+189.0
+ 11
+108.0
+ 21
+189.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+316
+  8
+Circuit
+ 10
+108.0
+ 20
+189.0
+ 11
+109.0
+ 21
+189.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+317
+  8
+Circuit
+ 10
+109.0
+ 20
+189.0
+ 11
+110.0
+ 21
+190.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+318
+  8
+Circuit
+ 10
+110.0
+ 20
+190.0
+ 11
+111.0
+ 21
+191.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+319
+  8
+Circuit
+ 10
+111.0
+ 20
+191.0
+ 11
+112.0
+ 21
+192.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+31A
+  8
+Circuit
+ 10
+112.0
+ 20
+192.0
+ 11
+113.0
+ 21
+192.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+31B
+  8
+Circuit
+ 10
+113.0
+ 20
+192.0
+ 11
+114.0
+ 21
+193.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+31C
+  8
+Circuit
+ 10
+114.0
+ 20
+193.0
+ 11
+115.0
+ 21
+193.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+31D
+  8
+Circuit
+ 10
+115.0
+ 20
+193.0
+ 11
+116.0
+ 21
+193.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+31E
+  8
+Circuit
+ 10
+116.0
+ 20
+193.0
+ 11
+117.0
+ 21
+194.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+31F
+  8
+Circuit
+ 10
+117.0
+ 20
+194.0
+ 11
+118.0
+ 21
+195.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+320
+  8
+Circuit
+ 10
+118.0
+ 20
+195.0
+ 11
+119.0
+ 21
+195.0
+  6
+DASHDOT
+ 67
+0
+  0
+LINE
+  5
+321
+  8
+Circuit
+ 10
+119.0
+ 20
+195.0
+ 11
+120.0
+ 21
+196.0
+  6
+DASHDOT
+ 67
+0
+  0
 VIEWPORT
   5
 27