Skip to content

Commit 38da82c

Browse files
committed
Cleanup
1 parent 94eadef commit 38da82c

File tree

1 file changed

+1
-103
lines changed

1 file changed

+1
-103
lines changed

src/utils.jl

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,14 @@ end
2424
i = @index(Global, Linear)
2525

2626
dim = length(prob.u0)
27-
lb = prob.lb
28-
ub = prob.ub
2927
cost_func = prob.f
3028
p = prob.p
3129

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-
4730
position = StaticArrays.sacollect(T,
4831
ifelse(abs(prob.u0[i]) > 0,
4932
prob.u0[i] + rand(eltype(prob.u0)) * abs(prob.u0[i]),
5033
rand(eltype(prob.u0))) for i in 1:dim)
5134

52-
# KernelAbstractions.@print "$(position[1]) \n"
53-
5435
velocity = zero(T)
5536

5637
if !isnothing(prob.f.cons)
@@ -76,33 +57,7 @@ end
7657
cost_func = prob.f
7758
p = prob.p
7859

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))
10661

10762
velocity = zero(T)
10863

@@ -124,11 +79,8 @@ end
12479
i = @index(Global, Linear)
12580

12681
dim = length(prob.u0)
127-
lb = prob.lb
128-
ub = prob.ub
12982
cost_func = prob.f
13083
p = prob.p
131-
num_particles = opt.num_particles
13284

13385
@inbounds position = StaticArrays.sacollect(T, qmc_particles[j, i] for j in 1:dim)
13486
velocity = zero(T)
@@ -145,63 +97,9 @@ end
14597

14698
@inbounds particles[i] = SPSOParticle(
14799
position, velocity, cost, best_position, best_cost)
148-
# push!(particles, SPSOParticle(position, velocity, cost, best_position, best_cost))
149100

150101
end
151102

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-
205103
function init_particles!(particles, prob, opt, ::Type{T}) where {T <: SArray}
206104
dim = length(prob.u0)
207105
lb = prob.lb

0 commit comments

Comments
 (0)