Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jayant Khatkar
tempaware
Commits
039bada7
Commit
039bada7
authored
Sep 21, 2021
by
Jayant Khatkar
Browse files
basic local search loop but slow - need to make faster
parent
bae6283c
Changes
1
Hide whitespace changes
Inline
Side-by-side
main.jl
View file @
039bada7
...
...
@@ -436,6 +436,12 @@ function check_validity(rollout::Vector{Int}, cdata::contourdata)
end
function
swap!
(
rollout
::
Vector
{
Int
},
i
::
Int
,
j
::
Int
)
# swap values at ith and jth indices
rollout
[
i
],
rollout
[
j
]
=
rollout
[
j
],
rollout
[
i
]
end
function
test_voxmap
()
# create vox
vox
=
[
0
,
0
,
0.5
]
...
...
@@ -492,6 +498,7 @@ function calc_cost(rollout::Vector{Int}, cdata::contourdata, vd::voxdata, mat::m
considered_voxels
=
considered_voxels
[
.!
isnan
.
(
voxtimes
[
vd
.
below
[
considered_voxels
]])]
Δt
=
voxtimes
[
considered_voxels
]
-
voxtimes
[
vd
.
below
[
considered_voxels
]]
ΔT
=
Tcutoff
.-
Temp
.
(
Δt
)
replace!
(
x
->
x
<
0
?
0
:
x
,
ΔT
)
# calculate stresses at each voxel
F
=
(
2
/
mat
.
σ̄
[
1
,
1
]
^
2
-
1
/
mat
.
σ̄
[
3
,
3
]
^
2
)
/
2
...
...
@@ -515,7 +522,7 @@ function calc_cost(rollout::Vector{Int}, cdata::contourdata, vd::voxdata, mat::m
end
function
construct_cost
(
cdata
::
contourdata
)
function
construct_cost
(
cdata
::
contourdata
,
vd
::
voxdata
,
mat
::
material
)
a
=
1
b
=
:
(
$
a
+
5
)
# using $ 'interpolates' literal expression into the 'quoted' expression
c
=
:
(
5
*
5
+
a
)
...
...
@@ -539,6 +546,18 @@ function clean_contour(c::contour)
return
c
end
function
stress_multiplier!
(
a
::
DataFrame
,
mul
::
Number
)
a
.
Sx
=
a
.
Sx
*
mul
a
.
Sy
=
a
.
Sy
*
mul
a
.
Sz
=
a
.
Sz
*
mul
a
.
Txy
=
a
.
Txy
*
mul
a
.
Tyz
=
a
.
Tyz
*
mul
a
.
Txz
=
a
.
Txz
*
mul
return
end
# ABS material properties
α_ABS
=
100
# 78 - 108
E_ABS
=
2.5e9
# 1.19e9 - 2.9e9
...
...
@@ -555,7 +574,34 @@ obj = "/Users/jayant/phd/tempaware/" * "M1"
contours
=
clean_contour
.
(
contour
.
(
JSON
.
parse
(
open
(
obj
*
"contours.json"
))))
cdata
=
contourdata
(
contours
,
5
,
5
)
# contour data
vd
=
voxdata
(
obj
*
"_voxels.csv"
,
cdata
)
# TODO Need to debug
stress_multiplier!
(
vd
.
voxels
,
0.5
)
rl
=
random_rollout
(
cdata
)
@benchmark
rl
=
random_rollout
(
cdata
)
# 20/second
@benchmark
valid_swap
(
rl
,
rand
(
1
:
length
(
contours
)),
rand
(
1
:
length
(
contours
)),
cdata
)
# 1mil/second
calc_cost
(
rl
,
cdata
,
vd
,
ABS
)
# 500/second
\ No newline at end of file
calc_cost
(
rl
,
cdata
,
vd
,
ABS
)
# 500/second
# local search loop
o_rl
=
copy
(
rl
)
n
=
length
(
rl
)
k
=
5
cost_val
=
Inf
for
l
in
1
:
10
println
(
l
)
println
(
cost_val
)
costs
=
Dict
()
for
i
in
1
:
n
-
1
for
j
in
i
+
1
:
min
(
i
+
k
,
n
)
if
valid_swap
(
rl
,
i
,
j
,
cdata
)
swap!
(
rl
,
i
,
j
)
costs
[
i
,
j
]
=
calc_cost
(
rl
,
cdata
,
vd
,
ABS
)
swap!
(
rl
,
i
,
j
)
end
end
end
v
,
(
i
,
j
)
=
findmin
(
costs
)
if
v
<
cost_val
cost_val
=
v
swap!
(
rl
,
i
,
j
)
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment