Commit b385133d authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

progress towards partial planning

parent 7bed2ab7
......@@ -18,7 +18,7 @@ tdfast = tempdecay(215, 25, 0.08)
### LOAD IN DATA
obj = "/Users/jayant/phd/tempaware/models/" * "M5"
obj = "/Users/jayant/phd/tempaware/models/" * "M3"
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
......
......@@ -605,7 +605,7 @@ end
function plot(rl::Vector{Int}, cdata::contourdata)
n = length(rl)
cols = range(HSV(720,1,1), stop=HSV(-720,1,1), length=n)
cols = range(HSV(0,1,1), stop=HSV(-360,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
Markdown is supported
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