Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rocoelectrical
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jingyan Ling
rocoelectrical
Commits
5a46cc97
Commit
5a46cc97
authored
5 years ago
by
Jingyan Ling
Browse files
Options
Downloads
Patches
Plain Diff
update journal
parent
9fc6a14e
Branches
Branches containing commit
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+3
-1
3 additions, 1 deletion
README.md
analyze_dxf.py
+86
-31
86 additions, 31 deletions
analyze_dxf.py
silhouette_ele.dxf
+3276
-486
3276 additions, 486 deletions
silhouette_ele.dxf
with
3365 additions
and
518 deletions
README.md
+
3
−
1
View file @
5a46cc97
...
...
@@ -165,6 +165,8 @@
~~~~
-
Q here represents total cost of certain choice of path finding order.
-
Cost defined by length of path
-
If path cannot be found, cost 200
-
If path cannot be found, cost 1000
-
Input: NX2X2 array specifies desired pin connections
-
Research on KiCAD import needs and python API
\ No newline at end of file
This diff is collapsed.
Click to expand it.
analyze_dxf.py
+
86
−
31
View file @
5a46cc97
...
...
@@ -9,12 +9,18 @@ import os
from
pathfinding.core.diagonal_movement
import
DiagonalMovement
from
pathfinding.core.grid
import
Grid
from
pathfinding.finder.a_star
import
AStarFinder
import
copy
import
matplotlib.pyplot
as
plt
import
matplotlib.animation
as
animation
class
dxf_editor
:
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'
...
...
@@ -34,15 +40,24 @@ class dxf_editor:
self
.
matrix_shape
=
(
270
,
210
)
self
.
read_dxf_as_matrix
()
start_point_arr
=
(
120
,
60
)
end_point_arr
=
(
120
,
172
)
start_point
=
[
int
(
start_point_arr
[
0
]),
int
(
start_point_arr
[
1
])]
end_point
=
[
int
(
end_point_arr
[
0
]),
int
(
end_point_arr
[
1
])]
self
.
path
=
self
.
find_a_path
(
start_point
,
end_point
)
self
.
draw_a_path
(
self
.
path
)
# 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
)
connection_amount
=
5
for
i
in
range
(
connection_amount
):
s
=
random
.
randint
(
0
,
len
(
self
.
center_arr
)
-
1
)
e
=
random
.
randint
(
0
,
len
(
self
.
center_arr
)
-
1
)
connections
=
np
.
array
([[
self
.
center_arr
[
s
],
self
.
center_arr
[
e
]]]).
reshape
(
1
,
2
,
2
)
self
.
connections_list
=
np
.
append
(
self
.
connections_list
,
connections
,
axis
=
0
)
self
.
connections_list
=
np
.
rint
(
self
.
connections_list
)[
1
:]
self
.
find_multi_path
(
self
.
connections_list
)
self
.
dwg
.
saveas
(
self
.
dxf_name
)
# os.system("inkscape -f silhouette_ele.dxf -e silouette_ele.png")
...
...
@@ -142,44 +157,84 @@ class dxf_editor:
j
-=
1
self
.
matrix
[
j
,
i
]
=
0
def
find_a_path
(
self
,
start_point
,
end_point
):
grid
=
Grid
(
matrix
=
self
.
matrix
)
start
=
grid
.
node
(
start_point
[
0
],
start_point
[
1
])
end
=
grid
.
node
(
end_point
[
0
],
end_point
[
1
])
finder
=
AStarFinder
(
diagonal_movement
=
DiagonalMovement
.
always
)
def
find_a_path
(
self
,
matrixws
,
start_point
,
end_point
):
"""
find a path between two points on img=matrix
start_point and end_point shape: (2,)
"""
#DEBUG:
# if not np.array_equal(matrixws,self.matrix):
# print('Map updated')
grid
=
Grid
(
matrix
=
matrixws
)
start
=
grid
.
node
(
int
(
start_point
[
0
]),
int
(
start_point
[
1
]))
end
=
grid
.
node
(
int
(
end_point
[
0
]),
int
(
end_point
[
1
]))
finder
=
AStarFinder
(
diagonal_movement
=
4
)
path
,
runs
=
finder
.
find_path
(
start
,
end
,
grid
)
return
path
def
draw_a_path
(
self
,
path
):
def
draw_a_path
(
self
,
path
,
matrix
,
dxf
=
False
):
"""
draw a path on img=matrix, or on dxf file too
"""
#draw on matrix:
for
point
in
path
:
self
.
matrix
[
point
[
1
],
point
[
0
]]
=
-
1
matrix
[
point
[
1
],
point
[
0
]]
=
0
#draw on dxf:
for
i
in
range
(
len
(
path
)
-
1
):
self
.
msp
.
add_line
(
path
[
i
],
path
[
i
+
1
],
dxfattribs
=
{
'
layer
'
:
'
Circuit
'
,
'
linetype
'
:
'
DASHDOT
'
})
if
dxf
:
for
i
in
range
(
len
(
path
)
-
1
):
self
.
msp
.
add_line
(
path
[
i
],
path
[
i
+
1
],
dxfattribs
=
{
'
layer
'
:
'
Circuit
'
,
'
linetype
'
:
'
DASHDOT
'
})
def
get_cost
(
self
,
path
):
if
len
(
path
)
==
0
:
cost
=
1000
else
:
cost
=
len
(
path
)
# print(self.matrix)
return
cost
def
find_multi_path
(
self
,
pin_connections
):
"""
pin_connection shape : NX2X2
"""
E
=
2
for
episode
in
range
(
E
):
self
.
matrix_temp
=
copy
.
deepcopy
(
self
.
matrix
)
self
.
Q
=
0
random_ix
=
random
.
randint
(
0
,
len
(
pin_connections
)
-
1
)
init_s
=
pin_connections
[
random_ix
]
con_list_temp
=
np
.
delete
(
pin_connections
,
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
,
True
)
cost
=
self
.
get_cost
(
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
]
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
,
True
)
cost
=
self
.
get_cost
(
curpath
)
self
.
Q
=
self
.
Q
+
cost
episode
+=
1
plt
.
imshow
(
self
.
matrix_temp
)
plt
.
show
()
# def main():
path
=
'
/home/jingyan/Documents/summer_intern_lemur/roco_electrical/
'
dxf_file
=
'
graph-silhouette.dxf
'
edit
=
dxf_editor
(
path
,
dxf_file
)
# animation.FuncAnimation(edit.fig,plt.imshow(edit.matrix_temp))
# plt.show()
# if __name__ == '__main__':
...
...
This diff is collapsed.
Click to expand it.
silhouette_ele.dxf
+
3276
−
486
View file @
5a46cc97
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment