Skip to content

Commit 9aacebe

Browse files
authored
Merge pull request #103 from jonathanfischer97/master
Fix stepsize and population referencing in DE algorithm
2 parents 443b653 + 1ea1394 commit 9aacebe

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/algorithms/DE/DE.jl

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ function DE(;
6868
)
6969

7070

71-
parameters =
72-
DE(N, promote(F, CR, CR_min, CR_max, F_min, F_max)..., strategy)
71+
parameters = DE(N, promote(F, CR, CR_min, CR_max, F_min, F_max)..., strategy)
7372

7473
Algorithm(parameters; kargs...)
7574

@@ -85,21 +84,15 @@ function update_state!(
8584
args...;
8685
kargs...
8786
)
88-
population = status.population
89-
90-
F = parameters.F
91-
CR = parameters.CR
9287

9388

94-
rng = options.rng
9589
# stepsize
9690
if parameters.F_min < parameters.F_max
97-
F = parameters.F_min + (parameters.F_max - parameters.F_min) * rand(rng)
91+
parameters.F = parameters.F_min + (parameters.F_max - parameters.F_min) * rand(options.rng)
9892
end
9993

10094
if parameters.CR_min < parameters.CR_max
101-
CR =
102-
parameters.CR_min + (parameters.CR_max - parameters.CR_min) * rand(rng)
95+
parameters.CR = parameters.CR_min + (parameters.CR_max - parameters.CR_min) * rand(options.rng)
10396
end
10497

10598
new_vectors = reproduction(status, parameters, problem)
@@ -192,25 +185,25 @@ end
192185

193186

194187
function reproduction(status, parameters::AbstractDifferentialEvolution, problem)
195-
@assert !isempty(status.population)
188+
population = status.population
189+
@assert !isempty(population)
196190

197191
N = parameters.N
198-
D = length(get_position(status.population[1]))
192+
D = length(get_position(population[1]))
199193

200194
strategy = parameters.strategy
201195
xBest = get_position(status.best_sol)
202-
population = status.population
203196
F = parameters.F
204197
CR = parameters.CR
205198

206-
X = zeros(eltype(xBest), N,D)
199+
X = zeros(eltype(xBest), N, D)
207200

208201
for i in 1:N
209202
x = get_position(population[i])
210203
u = DE_mutation(population, F, strategy, 1)
211204
v = DE_crossover(x, u, CR)
212205
evo_boundary_repairer!(v, xBest, problem.search_space)
213-
X[i,:] = _fix_type(v, problem.search_space)
206+
X[i,:] .= _fix_type(v, problem.search_space)
214207
end
215208

216209
X

0 commit comments

Comments
 (0)