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

quick cleanup, also speedup was 4x in last commit

parent a67612f2
......@@ -524,7 +524,7 @@ function calc_cost(rollout::Vector{Int}, cdata::contourdata, vd::voxdata, mat::m
end
#function construct_cost(cdata::contourdata, vd::voxdata, mat::material)
function construct_cost(cdata::contourdata, vd::voxdata, mat::material)
# store contour time lengths inside function
contour_times = [cdata.contours[c].time[end] for c in 1:length(cdata.contours)]
......@@ -544,32 +544,7 @@ end
relmaps = vd.maps[considered_voxels]
relbelows = vd.below[considered_voxels]
rel_voxels = vd.voxels[considered_voxels,:]
# trying to flatten to one equation
# n = length(relmaps)
# voxtimes = [:() for i in 1:length(vd.maps)]
# for i in 1:length(vd.maps)
# v = vd.maps[i]
# if length(v.segcontours) == 0
# continue
# end
# c = 0
# for j in 1:length(v.segcontours)
# if j == 1
# v_time = :(timestart[$(v.segcontours[j])] * $(v.seglen[j]/sum(v.seglen)))
# else
# v_time = :($v_time + timestart[$(v.segcontours[j])] * $(v.seglen[j]/sum(v.seglen)))
# end
# c += v.segoffset[j] *v.seglen[j]/sum(v.seglen)
# end
# v_time = :($v_time + $c)
# voxtimes[i] = v_time
# end
# voxtimes_expression = :[]
# voxtimes_expression.args = voxtimes
# replace!(x-> x==:() ? 0 : x, voxtimes_expression.args)
a = quote
return quote
function cost_f(rl::Vector{Int})
# println("Cumulative Sum") # 100k
timestart = cumsum([$contour_times[c] for c in rl])
......@@ -601,8 +576,8 @@ end
return cost
end
end
# return
#end
end
function clean_contour(c::contour)
# remove first element of array if second element is the same
......@@ -640,10 +615,7 @@ obj = "/Users/jayant/phd/tempaware/" * "M1"
contours = clean_contour.(contour.(JSON.parse(open(obj * "contours.json"))))
cdata = contourdata(contours, 5, 5) # contour data
@time vd = voxdata(obj * "_voxels.csv", cdata)
#stress_multiplier!(vd.voxels, 0.5)
rl = random_rollout(cdata)
#@benchmark rl = random_rollout(cdata) # 20/second
#@benchmark valid_swap(rl, rand(1:length(contours)), rand(1:length(contours)), cdata) # 1mil/second
calc_cost(rl, cdata, vd, ABS) # 500/second
......@@ -653,7 +625,7 @@ n = length(rl)
k = 5
cost_val = Inf
o=0
@time for l in 1:10
@time for l in 1:100
println(l)
println(cost_val)
costs = Dict()
......@@ -661,7 +633,7 @@ o=0
for j in i+1:min(i+k,n)
if valid_swap(rl, i, j, cdata)
swap!(rl, i, j)
costs[i,j] = calc_cost(rl, cdata, vd, ABS)
costs[i,j] = cost_f(rl)
swap!(rl, i, j)
o += 1
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