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
b385133d
Commit
b385133d
authored
Oct 10, 2021
by
Jayant Khatkar
Browse files
progress towards partial planning
parent
7bed2ab7
Changes
2
Hide whitespace changes
Inline
Side-by-side
main.jl
View file @
b385133d
...
...
@@ -18,7 +18,7 @@ tdfast = tempdecay(215, 25, 0.08)
### LOAD IN DATA
obj
=
"/Users/jayant/phd/tempaware/models/"
*
"M
5
"
obj
=
"/Users/jayant/phd/tempaware/models/"
*
"M
3
"
contours
=
clean_contour
.
(
contour
.
(
JSON
.
parse
(
open
(
obj
*
"contours.json"
))))
cdata
=
contourdata
(
contours
,
20
,
5
)
# contour data
@time
vd
=
voxdata
(
obj
*
"_voxels.csv"
,
cdata
)
...
...
@@ -31,26 +31,9 @@ c = cost_f(rl)
# local search loop
k
=
150
# TODO k is hardcoded in function below (uses global variable)
function
best_neighbor!
(
rl
::
Vector
{
Int
},
current_cost
::
Number
)
costs
=
Dict
()
for
i
in
1
:
1
:
length
(
rl
)
-
1
for
j
in
i
+
1
:
min
(
i
+
k
,
length
(
rl
))
# TODO length rl is constant
if
valid_swap
(
rl
,
i
,
j
,
cdata
)
swap!
(
rl
,
i
,
j
)
costs
[
i
,
j
]
=
cost_f
(
rl
)
# TODO cost function global vairable being used here
swap!
(
rl
,
i
,
j
)
end
end
end
v
,
(
i
,
j
)
=
findmin
(
costs
)
if
abs
(
v
-
current_cost
)
<
current_cost
/
1e6
return
0
elseif
v
<
current_cost
swap!
(
rl
,
i
,
j
)
return
v
end
return
0
end
layer_range
=
[(
1
,
1
),
(
15
,
25
)]
crange
=
contour_range
(
layer_range
,
cdata
)
construct_neighbour_searcher
(
k
,
cost_f
,
crange
)
function
local_search!
(
rl
::
Vector
{
Int
},
max_iter
::
Int
)
...
...
@@ -71,6 +54,8 @@ end
rl
=
random_rollout
(
cdata
)
cost_f
(
rl
)
max_iterations
=
50
rl
=
Vector
(
1
:
length
(
rl
))
cost_f
(
rl
)
@time
local_search!
(
rl
,
max_iterations
)
# run many times
...
...
utils.jl
View file @
b385133d
...
...
@@ -605,7 +605,7 @@ end
function
plot
(
rl
::
Vector
{
Int
},
cdata
::
contourdata
)
n
=
length
(
rl
)
cols
=
range
(
HSV
(
72
0
,
1
,
1
),
stop
=
HSV
(
-
72
0
,
1
,
1
),
length
=
n
)
cols
=
range
(
HSV
(
0
,
1
,
1
),
stop
=
HSV
(
-
36
0
,
1
,
1
),
length
=
n
)
traces
=
Vector
{
GenericTrace
}()
layout
=
Layout
(
yaxis
=
attr
(
scaleanchor
=
"x"
,
scaleratio
=
1
)
...
...
@@ -622,4 +622,46 @@ function plot(rl::Vector{Int}, cdata::contourdata)
))
end
plot
(
traces
,
layout
)
end
function
contour_range
(
layer_ranges
::
Vector
{
Tuple
{
Int
,
Int
}},
cdata
::
contourdata
)
contour_ranges
=
Vector
{
Tuple
{
Int
,
Int
}}()
for
lr
in
layer_ranges
push!
(
contour_ranges
,
(
cdata
.
layers
[
lr
[
1
]][
1
],
cdata
.
layers
[
lr
[
2
]][
end
]))
end
return
contour_ranges
end
function
construct_neighbour_searcher
(
k
::
Int
,
cost_func
::
Function
,
search_ranges
::
Vector
{
Tuple
{
Int
,
Int
}})
# k -> max swpa dist
# cost_func
# search_ranges allowed ranges of swaps
a
=
quote
function
best_neighbor!
(
rl
::
Vector
{
Int
},
current_cost
::
Number
)
costs
=
Dict
()
for
(
s
,
e
)
in
$
search_ranges
for
i
in
s
:
e
-
1
for
j
in
i
+
1
:
e
if
valid_swap
(
rl
,
i
,
j
,
cdata
)
swap!
(
rl
,
i
,
j
)
costs
[
i
,
j
]
=
$
cost_func
(
rl
)
swap!
(
rl
,
i
,
j
)
end
end
end
end
v
,
(
i
,
j
)
=
findmin
(
costs
)
if
abs
(
v
-
current_cost
)
<
current_cost
/
1e6
return
0
elseif
v
<
current_cost
swap!
(
rl
,
i
,
j
)
return
v
end
return
0
end
end
return
eval
(
a
)
# create best_neighbour function to use below
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