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

remove main loop

parent e54b574c
......@@ -34,65 +34,57 @@ n_local_searches = 10
n_models = 10
max_iterations = 50
k = 150
for i in 1:n_models
s = time()
obj = "M" * string(i)
# if obj in keys(results) || obj == "M4" || obj == "M9"
if obj == "M4" || obj == "M9"
continue # skip is already done
end
println("Starting " * obj)
# Load data
f_name = Symbol("cost_" * obj)
try
cost_func = getfield(Main, f_name)
catch
println("Loading data...")
obj_add = add * obj
contours = clean_contour.(contour.(JSON.parse(open(obj_add * "contours.json"))))
cdata = contourdata(contours, 40, 10) # contour data
println(string(length(cdata.contours)) * " contours")
vd = voxdata(obj_add * "_voxels.csv", cdata)
println("Constructing Cost function...")
construct_cost(cdata, vd, ABS, td, f_name)
cost_func = getfield(Main, f_name)
println(cost_func)
construct_best_neighbor(cdata, cost_func, k)
end
i=7 # ith model
obj = "M" * string(i)
# if obj in keys(results) || obj == "M4" || obj == "M9"
# if obj == "M4" || obj == "M9"
# continue # skip is already done
# end
println("Starting " * obj)
# Load data
f_name = Symbol("cost_" * obj)
println("Loading data...")
obj_add = add * obj
contours = clean_contour.(contour.(JSON.parse(open(obj_add * "contours.json"))))
cdata = contourdata(contours, 40, 10) # contour data
try
cost_func = getfield(Main, f_name)
catch
vd = voxdata(obj_add * "_voxels.csv", cdata)
println("Constructing Cost function...")
construct_cost(cdata, vd, ABS, td, f_name)
end
cost_func = getfield(Main, f_name)
construct_best_neighbor(cdata, cost_func, k)
# default rollout cost
rl_d = Vector(1:length(cdata.contours))
c = cost_func(rl_d)
update_result(results, obj, rl_d, c, :default)
# greedy rollout cost
rl_g = greedy_rollout(cdata)
c = cost_func(rl_g)
update_result(results, obj, rl_g, c, :greedy)
# local search
# println("Doing local search " * string(n_local_searches) * " times")
# opt_costs = zeros(n_local_searches)
# Threads.@threads for i in 1:n_local_searches
# rl = random_rollout(cdata)
# random_cost = cost_f(rl)
# update_result(results, obj, rl, random_cost, :random)
# local_cost = local_search!(rl, max_iterations)
# update_result(results, obj, rl, local_cost, :local)
# end
println("Completed in " * string(time()-s) * " seconds")
# default rollout cost
rl_d = Vector(1:length(cdata.contours))
c = cost_func(rl_d)
update_result(results, obj, rl_d, c, :default)
# greedy rollout cost
rl_g = greedy_rollout(cdata)
c = cost_func(rl_g)
#update_result(results, obj, rl_g, c, :greedy)
plot(rl_g)
# local search
println("Doing local search " * string(n_local_searches) * " times")
opt_costs = zeros(n_local_searches)
Threads.@threads for i in 1:n_local_searches
rl = greedish_rollout(cdata)
greedish_cost = cost_func(rl)
println("GREEDISH COST: " * string(greedish_cost))
update_result(results, obj, rl, greedish_cost, :greedish)
local_cost = local_search!(rl, max_iterations)
println("LOCAL COST: " * string(local_cost))
update_result(results, obj, rl, local_cost, :local)
end
save_result(results, add * "results.json")
### Load individual models for the plots
obj = "M1"
obj_add = add * obj
contours = clean_contour.(contour.(JSON.parse(open(obj_add * "contours.json"))))
cdata = contourdata(contours, 40, 10) # contour data
vd = voxdata(obj_add * "_voxels.csv", cdata)
### Visualisations
# distribution of stresses
......@@ -105,18 +97,19 @@ histogram!(sort(data, rev=true)[1:4000]) # vast majority of voxels near 0 stress
# voxmap sanity check
plot(vd, 1500, cdata)
# rollout order 3d
# rollouts
rl_d = Vector(1:length(cdata.contours))
rl_r = random_rollout(cdata)
rl_g = greedy_rollout(cdata)
rl_l = Vector{Int}(results[obj]["best_rollout"])
plot(rl_d, cdata)
plot(rl_d) # plot rollout line graph
plot(rl_d, cdata) # plot rollout 3d graph
plot(rl_r, cdata)
plot(rl_g, cdata)
plot(rl_l, cdata)
# rollout order animated
# plot rollout animated
@time plot_animate(rl_g, cdata, rate=5)
# plot results
......
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