Skip to content
Snippets Groups Projects
Commit ff517ce3 authored by Jingyan Ling's avatar Jingyan Ling
Browse files

update 0708 journal, script

parent 5a46cc97
Branches
No related merge requests found
...@@ -148,7 +148,7 @@ ...@@ -148,7 +148,7 @@
- break single circuit trace to parallel traces - break single circuit trace to parallel traces
- solve the accuracy problem - solve the accuracy problem
### 07/04/2019 (Fri) ### 07/05/2019 (Fri)
- Write out algorithm for multi-node path finding - Write out algorithm for multi-node path finding
- pseudo code: - pseudo code:
...@@ -169,4 +169,14 @@ ...@@ -169,4 +169,14 @@
- Input: NX2X2 array specifies desired pin connections - Input: NX2X2 array specifies desired pin connections
- Research on KiCAD import needs and python API - Research on KiCAD import needs and python API
\ No newline at end of file
### 07/082019 (Mon)
- Debug multi-node path finding:
- some obstacles are ignored
- too close to each other
- 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
...@@ -12,6 +12,8 @@ from pathfinding.finder.a_star import AStarFinder ...@@ -12,6 +12,8 @@ from pathfinding.finder.a_star import AStarFinder
import copy import copy
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import matplotlib.animation as animation import matplotlib.animation as animation
from matplotlib import cm
from array2gif import write_gif
class dxf_editor: class dxf_editor:
def __init__(self,path,dxf_file): def __init__(self,path,dxf_file):
...@@ -39,17 +41,11 @@ class dxf_editor: ...@@ -39,17 +41,11 @@ class dxf_editor:
self.matrix_shape=(270,210) self.matrix_shape=(270,210)
self.read_dxf_as_matrix() self.read_dxf_as_matrix()
# start_point_arr=np.rint(self.center_arr[1])
# end_point_arr=(120,172)
# start_point=[start_point_arr[0],start_point_arr[1]]
# end_point=[end_point_arr[0],end_point_arr[1]]
# self.path=self.find_a_path(self.matrix,start_point,end_point)
# self.draw_a_path(self.path,self.matrix,True)
self.connections_list=np.array([[0,0],[0,0]]).reshape(1,2,2) self.connections_list=np.array([[0,0],[0,0]]).reshape(1,2,2)
connection_amount=5 connection_amount=4
for i in range(connection_amount): for i in range(connection_amount):
s=random.randint(0,len(self.center_arr)-1) s=random.randint(0,len(self.center_arr)-1)
e=random.randint(0,len(self.center_arr)-1) e=random.randint(0,len(self.center_arr)-1)
...@@ -57,7 +53,14 @@ class dxf_editor: ...@@ -57,7 +53,14 @@ class dxf_editor:
self.connections_list=np.append(self.connections_list,connections,axis=0) self.connections_list=np.append(self.connections_list,connections,axis=0)
self.connections_list=np.rint(self.connections_list)[1:] self.connections_list=np.rint(self.connections_list)[1:]
self.find_multi_path(self.connections_list)
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.dwg.saveas(self.dxf_name) self.dwg.saveas(self.dxf_name)
# os.system("inkscape -f silhouette_ele.dxf -e silouette_ele.png") # os.system("inkscape -f silhouette_ele.dxf -e silouette_ele.png")
...@@ -65,6 +68,8 @@ class dxf_editor: ...@@ -65,6 +68,8 @@ class dxf_editor:
# self.img=cv2.imread(path+self.img_name) # self.img=cv2.imread(path+self.img_name)
# print(self.img) # print(self.img)
def update_img(self,i):
self.img.set_array(i)
def create_layer(self,layer_name,color): def create_layer(self,layer_name,color):
if not layer_name in self.dwg.layers: if not layer_name in self.dwg.layers:
...@@ -187,26 +192,27 @@ class dxf_editor: ...@@ -187,26 +192,27 @@ class dxf_editor:
'linetype':'DASHDOT'}) 'linetype':'DASHDOT'})
def get_cost(self,path): def get_cost(self,path):
if len(path)==0: if len(path)==0: #if no path found
cost=1000 cost=1000
else: cost=len(path) else: cost=len(path)
return cost return cost
def find_multi_path(self,pin_connections): def find_multi_path(self,i):
"""pin_connection shape : NX2X2 """ """pin_connection shape : NX2X2 """
E=2 E=1
print('test=========')
for episode in range(E): for episode in range(E):
self.matrix_temp=copy.deepcopy(self.matrix) self.matrix_temp=copy.deepcopy(self.matrix)
self.Q=0 self.Q=0
random_ix=random.randint(0,len(pin_connections)-1) random_ix=random.randint(0,len(self.connections_list)-1)
init_s=pin_connections[random_ix] init_s=self.connections_list[random_ix]
con_list_temp=np.delete(pin_connections,random_ix,axis=0) 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]) cur_path=self.find_a_path(self.matrix_temp,init_s[0],init_s[1])
self.draw_a_path(cur_path,self.matrix_temp,True) self.draw_a_path(cur_path,self.matrix_temp)
self.img.set_array(self.matrix_temp)
cost=self.get_cost(cur_path) cost=self.get_cost(cur_path)
self.Q=self.Q+cost self.Q=self.Q+cost
...@@ -218,14 +224,16 @@ class dxf_editor: ...@@ -218,14 +224,16 @@ class dxf_editor:
curpath=self.find_a_path(self.matrix_temp,next_conn[0],next_conn[1]) curpath=self.find_a_path(self.matrix_temp,next_conn[0],next_conn[1])
self.draw_a_path(curpath,self.matrix_temp,True) self.draw_a_path(curpath,self.matrix_temp)
self.img.set_array(self.matrix_temp)
cost=self.get_cost(curpath) cost=self.get_cost(curpath)
self.Q=self.Q+cost self.Q=self.Q+cost
episode+=1 episode+=1
plt.imshow(self.matrix_temp)
plt.show() # plt.imshow(self.matrix_temp)
# plt.show()
......
journal_media/path_learning.gif

97.4 KiB

This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment