Commit 114d9dea authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

running some experiments

parent c47c5863
# different decay rates (Not under our control but whatever)
tds_decay = [tempdecay(215,25, 0.02*i) for i in 1:10]
push!(tds_decay, tempdecay(215,25, 0.4))
push!(tds_decay, tempdecay(215,25, 0.6))
decay_results = Dict[]
for td in tds_decay[11:12]
println(td)
obj="obj" * string(rand(1:1000000))
println(obj)
n_local_searches = 100
max_iterations = 250
k = 150
# Load data
f_name = Symbol("cost_" * obj)
construct_cost(cdata, vd, ABS, td, f_name)
cost_func = getfield(Main, f_name)
construct_best_neighbor(cdata, cost_func, k)
results = Dict()
# 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")
#Threads.@threads
for i in 1:n_local_searches
rl = random_rollout(cdata)
random_cost = cost_func(rl) # change to random
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("best LS: " * string(results[obj]["cost_local"]))
push!(decay_results, results[obj])
end
ys_default = [r["cost_default"] for r in decay_results]
ys_local = [r["cost_local"] for r in decay_results]
xs = [td.decay_rate for td in tds_decay]
Plots.plot(xs, ys_default, label="Default")
plot!(xs, ys_local, label="Local search")
Plots.xlabel!("Decay rate")
Plots.ylabel!("Cost")
# different print speeds
print_speeds = [0.1, 0.25, 0.5, 1, 1.5, 2, 2.5]
speed_results = Dict[]
for speed in print_speeds
println(speed)
# change print speed
for c in cdata.contours
c.time *= speed
end
obj="obj" * string(rand(1:1000000))
println(obj)
n_local_searches = 100
max_iterations = 250
k = 150
# Load data
f_name = Symbol("cost_" * obj)
construct_cost(cdata, vd, ABS, td, f_name)
cost_func = getfield(Main, f_name)
construct_best_neighbor(cdata, cost_func, k)
results = Dict()
# default rollout cost
rl_d = Vector(1:length(cdata.contours))
@eval 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")
#Threads.@threads
for i in 1:n_local_searches
rl = random_rollout(cdata)
random_cost = cost_func(rl) # change to random
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("best LS:" * string(results[obj]["cost_local"]))
push!(speed_results, results[obj])
# return to default print speed
for c in cdata.contours
c.time /= speed
end
end
ys_default = [r["cost_default"] for r in speed_results]
ys_local = [r["cost_local"] for r in speed_results]
xs = print_speeds
Plots.plot(xs, ys_default, label="Default")
plot!(xs, ys_local, label="Local search")
Plots.xlabel!("Print speed (time*x so 0.25 is 4x fast)")
Plots.ylabel!("Cost")
# different models
models = ["M1", "M2", "M3", "M4"]
model_results = Dict[]
for obj in models[3:end]
# load data
println("Loading data...")
obj_add = add * obj
contours = clean_contour.(contour.(JSON.parse(open(obj_add * "contours.json"))))
contours = [c for c in contours if c!=nothing]
cdata = contourdata(contours, 20, 5) # contour data
@time vd = voxdata(obj_add * "_voxels.csv", cdata)
stress_multiplier!(vd.voxels,10)
println(obj)
n_local_searches = 100
max_iterations = 250
k = 150
# Load data
f_name = Symbol("cost_" * obj)
construct_cost(cdata, vd, ABS, td, f_name)
cost_func = getfield(Main, f_name)
construct_best_neighbor(cdata, cost_func, k)
results = Dict()
# default rollout cost
rl_d = Vector(1:length(cdata.contours))
@eval 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")
#Threads.@threads
for i in 1:n_local_searches
rl = random_rollout(cdata)
random_cost = cost_func(rl) # change to random
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("best LS:" * string(results[obj]["cost_local"]))
push!(model_results, results[obj])
end
ys_default = [r["cost_default"] for r in model_results]
ys_local = [r["cost_local"] for r in model_results]
xs = models
Plots.plot(xs, ys_default, label="Default")
plot!(xs, ys_local, label="Local search")
Plots.xlabel!("Print speed (time*x so 0.25 is 4x fast)")
Plots.ylabel!("Cost")
\ No newline at end of file
......@@ -15,34 +15,35 @@ ABS = material(α_ABS, E_ABS, σ̄_ABS, Tcutoff)
tdmed = tempdecay(215, 25, 0.04) # extrusion temp, room temp, decay rate
tdslow = tempdecay(215, 25, 0.01)
tdfast = tempdecay(215, 25, 0.08)
visualise_tempdecay(tdslow)
td=tdmed
visualise_tempdecay(tdfast)
td=tdfast
add = "/Users/jayant/phd/tempaware/models/"
### MAIN LOOP
results = Dict()# JSON.parse(open(add * "results.json"))
n_local_searches = 100
max_iterations = 250
k = 150
obj = "tempaware"
obj = "M1"
# 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, 2) # contour data
contours = [c for c in contours if c!=nothing]
cdata = contourdata(contours, 20, 5) # contour data
@time vd = voxdata(obj_add * "_voxels.csv", cdata)
stress_multiplier!(vd.voxels,10)
stress_multiplier!(vd.voxels,0)
println("Constructing Cost function...")
construct_cost(cdata, vd, ABS, td, f_name)
construct_cost_hist(cdata, vd, ABS, td)
cost_func = getfield(Main, f_name)
construct_best_neighbor(cdata, cost_func, k)
results = Dict()# JSON.parse(open(add * "results.json"))
# default rollout cost
rl_d = Vector(1:length(cdata.contours))
......@@ -59,12 +60,12 @@ plot(rl_g)
println("Doing local search " * string(n_local_searches) * " times")
#Threads.@threads
for i in 1:n_local_searches
rl = greedish_rollout(cdata)
rl = random_rollout(cdata)
random_cost = cost_func(rl) # change to random
# println("RANDOM COST: " * string(random_cost))
update_result(results, obj, rl, random_cost, :greedish)
println("RANDOM COST: " * string(random_cost))
update_result(results, obj, rl, random_cost, :random)
local_cost = local_search!(rl, max_iterations)
# println("LOCAL COST: " * string(local_cost))
println("LOCAL COST: " * string(local_cost))
update_result(results, obj, rl, local_cost, :local)
end
println(results[obj])
......@@ -73,11 +74,11 @@ save_result(results, add * "results.json")
### Visualisations
# distribution of stresses
data_stress = .( vd.voxels.Sx.^2 + vd.voxels.Sy.^2 + vd.voxels.Sz.^2)
data_strain = .(vd.voxels.Txy.^2 + vd.voxels.Tyz.^2 + vd.voxels.Txz.^2)
data = data_stress
histogram(data) # vast majority of voxels near 0 stress - can ignore
histogram!(sort(data, rev=true)[1:1000]) # vast majority of voxels near 0 stress - can ignore
# data_stress = .√( vd.voxels.Sx.^2 + vd.voxels.Sy.^2 + vd.voxels.Sz.^2)
# data_strain = .√(vd.voxels.Txy.^2 + vd.voxels.Tyz.^2 + vd.voxels.Txz.^2)
# data = data_stress
# histogram(data) # vast majority of voxels near 0 stress - can ignore
# histogram!(sort(data, rev=true)[1:1000]) # vast majority of voxels near 0 stress - can ignore
# voxmap sanity check
# plot(vd, 1000, cdata)
......@@ -88,14 +89,14 @@ rl_r = random_rollout(cdata)
rl_g = greedy_rollout(cdata)
rl_l = Vector{Int}(results[obj]["best_rollout"])
plot(rl_l) # plot rollout line graph
plot(rl_g) # plot rollout line graph
plot(rl_d, cdata) # plot rollout 3d graph
plot(rl_r, cdata)
plot(rl_g, cdata)
plot(rl_l, cdata)
# plot rollout animated
@time plot_animate(rl_l, cdata, rate=1)
@time plot_animate(rl_g, cdata, rate=1)
# plot results
plot(results)
......
......@@ -60,7 +60,9 @@ end
function visualise_tempdecay(td::tempdecay; tmax=200)
Temp(t::Number) = td.ambient + (td.extrusion-td.ambient)*^(-td.decay_rate*t)
plot(Temp, 0, tmax)
Plots.plot(Temp, 0, tmax)
xlabel!("Time (s)")
ylabel!("Temperature (C)")
end
......@@ -82,6 +84,14 @@ function contour(d::Dict)
return contour(vecvec_to_matrix(d["pos"]), d["time"])
end
function interp_half(mat)
l = size(mat)[1]
m = copy(mat)
for i in 2:l
m=vcat(m,(m[i-1,:] + (m[i,:] - m[i-1,:])/2)')
end
return m
end
function contourdata(cons::Vector{contour}, max_layers::Int, min_dist::Number)
G = LightGraphs.SimpleDiGraph(0)
......@@ -98,7 +108,7 @@ function contourdata(cons::Vector{contour}, max_layers::Int, min_dist::Number)
push!(layers[l], i)
push!(clayeri, l)
add_vertex!(G)
push!(contour_trees, KDTree(transpose(cons[i].pos)))
push!(contour_trees, KDTree(transpose(interp_half(interp_half(cons[i].pos)))))
end
# loop through contours from previous layer and compare waypoints
......@@ -643,6 +653,9 @@ function clean_contour(c::contour)
# remove first element of array if second element is the same
while c.pos[1,:] == c.pos[2,:]
c.pos = c.pos[2:end, :]
if size(c.pos)[1]==1
return
end
end
return c
end
......
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