|
24 | 24 | i = @index(Global, Linear) |
25 | 25 |
|
26 | 26 | dim = length(prob.u0) |
27 | | - lb = prob.lb |
28 | | - ub = prob.ub |
29 | 27 | cost_func = prob.f |
30 | 28 | p = prob.p |
31 | 29 |
|
32 | | - # gbest_position = StaticArrays.sacollect(T, |
33 | | - # ifelse( |
34 | | - # abs(prob.u0[i]) > 0, prob.u0[i] + rand(eltype(prob.u0)) * abs(prob.u0[i]), |
35 | | - # rand(eltype(prob.u0))) for i in 1:dim) |
36 | | - |
37 | | - # gbest_position = convert(T, gbest_position) |
38 | | - # gbest_cost = cost_func(gbest_position, p) |
39 | | - # if !isnothing(prob.f.cons) |
40 | | - # penalty = calc_penalty(gbest_position, prob, 1, opt.θ, opt.γ, opt.h) |
41 | | - # gbest_cost = cost_func(gbest_position, p) + penalty |
42 | | - # else |
43 | | - # gbest_cost = cost_func(gbest_position, p) |
44 | | - # end |
45 | | - # gbest_cost = cost_func(gbest_position, p) |
46 | | - |
47 | 30 | position = StaticArrays.sacollect(T, |
48 | 31 | ifelse(abs(prob.u0[i]) > 0, |
49 | 32 | prob.u0[i] + rand(eltype(prob.u0)) * abs(prob.u0[i]), |
50 | 33 | rand(eltype(prob.u0))) for i in 1:dim) |
51 | 34 |
|
52 | | - # KernelAbstractions.@print "$(position[1]) \n" |
53 | | - |
54 | 35 | velocity = zero(T) |
55 | 36 |
|
56 | 37 | if !isnothing(prob.f.cons) |
|
76 | 57 | cost_func = prob.f |
77 | 58 | p = prob.p |
78 | 59 |
|
79 | | - if lb === nothing || (all(isinf, lb) && all(isinf, ub)) |
80 | | - gbest_position = StaticArrays.sacollect(T, |
81 | | - ifelse( |
82 | | - abs(prob.u0[i]) > 0, prob.u0[i] + rand(eltype(prob.u0)) * abs(prob.u0[i]), |
83 | | - rand(eltype(prob.u0))) for i in 1:dim) |
84 | | - else |
85 | | - gbest_position = StaticArrays.sacollect(T, uniform_itr(dim, lb, ub)) |
86 | | - end |
87 | | - |
88 | | - gbest_position = convert(T, gbest_position) |
89 | | - gbest_cost = cost_func(gbest_position, p) |
90 | | - if !isnothing(prob.f.cons) |
91 | | - penalty = calc_penalty(gbest_position, prob, 1, opt.θ, opt.γ, opt.h) |
92 | | - gbest_cost = cost_func(gbest_position, p) + penalty |
93 | | - else |
94 | | - gbest_cost = cost_func(gbest_position, p) |
95 | | - end |
96 | | - gbest_cost = cost_func(gbest_position, p) |
97 | | - |
98 | | - if lb === nothing || (all(isinf, lb) && all(isinf, ub)) |
99 | | - position = StaticArrays.sacollect(T, |
100 | | - ifelse(abs(prob.u0[i]) > 0, |
101 | | - prob.u0[i] + rand(eltype(prob.u0)) * abs(prob.u0[i]), |
102 | | - rand(eltype(prob.u0))) for i in 1:dim) |
103 | | - else |
104 | | - position = StaticArrays.sacollect(T, uniform_itr(dim, lb, ub)) |
105 | | - end |
| 60 | + position = StaticArrays.sacollect(T, uniform_itr(dim, lb, ub)) |
106 | 61 |
|
107 | 62 | velocity = zero(T) |
108 | 63 |
|
|
124 | 79 | i = @index(Global, Linear) |
125 | 80 |
|
126 | 81 | dim = length(prob.u0) |
127 | | - lb = prob.lb |
128 | | - ub = prob.ub |
129 | 82 | cost_func = prob.f |
130 | 83 | p = prob.p |
131 | | - num_particles = opt.num_particles |
132 | 84 |
|
133 | 85 | @inbounds position = StaticArrays.sacollect(T, qmc_particles[j, i] for j in 1:dim) |
134 | 86 | velocity = zero(T) |
|
145 | 97 |
|
146 | 98 | @inbounds particles[i] = SPSOParticle( |
147 | 99 | position, velocity, cost, best_position, best_cost) |
148 | | - # push!(particles, SPSOParticle(position, velocity, cost, best_position, best_cost)) |
149 | 100 |
|
150 | 101 | end |
151 | 102 |
|
152 | | -# @kernel function gpu_init_particles!(gpu_particles, prob, opt, ::Type{T}) where {T <: SArray} |
153 | | -# i = @index(Global, Linear) |
154 | | - |
155 | | -# dim = length(prob.u0) |
156 | | -# lb = prob.lb |
157 | | -# ub = prob.ub |
158 | | -# cost_func = prob.f |
159 | | -# p = prob.p |
160 | | -# num_particles = opt.num_particles |
161 | | - |
162 | | -# if lb === nothing || (all(isinf, lb) && all(isinf, ub)) |
163 | | -# gbest_position = StaticArrays.sacollect(T, |
164 | | -# ifelse( |
165 | | -# abs(prob.u0[i]) > 0, prob.u0[i] + rand(eltype(prob.u0)) * abs(prob.u0[i]), |
166 | | -# rand(eltype(prob.u0))) for i in 1:dim) |
167 | | -# else |
168 | | -# gbest_position = StaticArrays.sacollect(T, uniform_itr(dim, lb, ub)) |
169 | | -# end |
170 | | - |
171 | | -# gbest_position = convert(T, gbest_position) |
172 | | -# gbest_cost = cost_func(gbest_position, p) |
173 | | -# if !isnothing(prob.f.cons) |
174 | | -# penalty = calc_penalty(gbest_position, prob, 1, opt.θ, opt.γ, opt.h) |
175 | | -# gbest_cost = cost_func(gbest_position, p) + penalty |
176 | | -# else |
177 | | -# gbest_cost = cost_func(gbest_position, p) |
178 | | -# end |
179 | | -# gbest_cost = cost_func(gbest_position, p) |
180 | | - |
181 | | -# if lb === nothing || (all(isinf, lb) && all(isinf, ub)) |
182 | | -# position = StaticArrays.sacollect(T, |
183 | | -# ifelse(abs(prob.u0[i]) > 0, |
184 | | -# prob.u0[i] + rand(eltype(prob.u0)) * abs(prob.u0[i]), |
185 | | -# rand(eltype(prob.u0))) for i in 1:dim) |
186 | | -# else |
187 | | -# position = StaticArrays.sacollect(T, uniform_itr(dim, lb, ub)) |
188 | | -# end |
189 | | - |
190 | | -# velocity = zero(T) |
191 | | - |
192 | | -# if !isnothing(prob.f.cons) |
193 | | -# penalty = calc_penalty(position, prob, 1, opt.θ, opt.γ, opt.h) |
194 | | -# cost = cost_func(position, p) + penalty |
195 | | -# else |
196 | | -# cost = cost_func(position, p) |
197 | | -# end |
198 | | - |
199 | | -# best_position = position |
200 | | -# best_cost = cost |
201 | | -# @inbounds particles[i] = SPSOParticle( |
202 | | -# position, velocity, cost, best_position, best_cost) |
203 | | -# end |
204 | | - |
205 | 103 | function init_particles!(particles, prob, opt, ::Type{T}) where {T <: SArray} |
206 | 104 | dim = length(prob.u0) |
207 | 105 | lb = prob.lb |
|
0 commit comments