Commit 076c6ace authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

valid random rollout to initiate local search approaches

parent 113cfbc7
......@@ -4,6 +4,7 @@ using JSON
using LightGraphs
using NearestNeighbors
using Statistics
using BenchmarkTools
struct contour
......@@ -16,7 +17,7 @@ struct problem
contours::Vector{contour}
G::SimpleDiGraph
layers::Vector
done_contours::Vector
travel_dists::Dict
layer_height::Number
end
......@@ -81,7 +82,7 @@ function problem(cons::Vector{contour}, max_layers::Int, min_dist::Number)
end
end
return problem(cons, G, layers, [], layer_heights[1])
return problem(cons, G, layers, Dict(), layer_heights[1])
end
......@@ -123,10 +124,12 @@ function seg_intersect(p1,q1,p2,q2)
return false
end
dist(p1, p2) = √sum((p1 -p2).^2)
interpolate(p1, p2, xi, axis) = p1 + (p2-p1)*(xi-p1[axis])/(p2[axis]-p1[axis])
interpolate(p1, p2, x1, xi, x2) = p1 + (p2-p1)*(xi-x1)/(x2-x1)
function voxmap(vox, vox_d, prob::problem)
# for one vox, get all contours which pass through it
......@@ -277,9 +280,54 @@ function voxmap(vox, vox_d, prob::problem)
return voxmap(seglen, segoffset, segcontours)
end
function random_rollout(prob::problem)
done_contours = Set{Int}()
avail_contours = Set(prob.layers[1])
todo_contours = Set(1:length(prob.contours))
rollout = Vector{Int}()
while length(avail_contours) > 0
c = rand(avail_contours)
push!(rollout, c)
# remove selected contour from todo and avail, add to done
delete!(avail_contours, c)
delete!(todo_contours, c)
push!(done_contours, c)
# update available contours
for i in todo_contours
if i in avail_contours
continue
elseif length(inneighbors(prob.G, i)) == 0
push!(avail_contours, i)
continue
end
add = true
for j in inneighbors(prob.G, i)
if !(j in done_contours)
add = false
break
end
end
if add
push!(avail_contours, i)
end
end
end
return rollout
end
#voxels = DataFrames.DataFrame(CSV.File("tensile-1-1.csv"))
#contours = contour.(JSON.parse(open("tensilecontours.json")))
#dt = problem(contours, 5, 5)
contours = contour.(JSON.parse(open("tensilecontours.json")))
dt = problem(contours, 5, 5)
@benchmark random_rollout(dt.G)
function test_voxmap()
# create vox
......@@ -305,4 +353,4 @@ function test_voxmap()
prob = problem(contours, 1, 1)
vm = voxmap(vox, vox_d, prob)
return vm
end
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