-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParallel_Optimization.jl
80 lines (45 loc) · 1.54 KB
/
Parallel_Optimization.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#### Parallel ###
function Run_Parallel_Optimization!(a::agent, obstacle::geometry, steps::Int, Δsteps::Int, ΔE)
#show progress
q = Progress(steps, 0.1)
trajectories = fill((0.0, 0.0), Int(round(steps/Δsteps)+1), length(a.traj))
energies = fill(0.0, steps+1)
energies[1] = E(a, obstacle)
trajectories[1, :] .= a.traj
j, k = 1, steps+1
ϵ_temp, traj_temp = 0.0, fill((0.0, 0.0), length(a.traj))
for i in 1:steps
ϵ_temp, traj_temp = Calc_Parallel!(a, obstacle, ϵ_temp, traj_temp)
Update_Parallel!(a, ϵ_temp, traj_temp)
if mod(i, Δsteps) == 0
j+=1
trajectories[j, :] .= a.traj
end
energies[i+1] = E(a, obstacle)
if abs(energies[i+1] - energies[i]) < ΔE*a.γ
println("Convergence criterum was met at step ", i, "!")
k = i-1
trajectories[j, :] .= a.traj
break
end
next!(q)
end
trajectories[1:j, :], energies[1:k]
end
function Calc_Parallel!(a::agent, obstacle::geometry, ϵ_temp, traj_temp)
ϵ_temp = Calc_ϵ(a, obstacle::geometry)
for site in 1:length(a.traj)
traj_temp[site] = Calc_at(site, a, obstacle)
end
ϵ_temp, traj_temp
end
function Calc_at(site::Int, a::agent, obstacle::geometry)
a.traj[site] .- a.γ .* ∇E(a, site, obstacle)
end
function Calc_ϵ(a::agent, obstacle::geometry)
a.ϵ - a.γ*∇E_ϵ(a, obstacle)
end
function Update_Parallel!(a::agent, ϵ_temp, traj_temp)
a.ϵ = ϵ_temp
a.traj = traj_temp
end