From 68d13a4fce78d7f5230e11e1d89e138d28ee722a Mon Sep 17 00:00:00 2001 From: Jonathan Fischer PEPE Date: Mon, 22 Jan 2024 18:39:45 -0500 Subject: [PATCH 1/2] new stepsize actually written to parameters; was just a copy before --- src/algorithms/DE/DE.jl | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/algorithms/DE/DE.jl b/src/algorithms/DE/DE.jl index 30e15e18..4dd4ca50 100644 --- a/src/algorithms/DE/DE.jl +++ b/src/algorithms/DE/DE.jl @@ -68,8 +68,7 @@ function DE(; ) - parameters = - DE(N, promote(F, CR, CR_min, CR_max, F_min, F_max)..., strategy) + parameters = DE(N, promote(F, CR, CR_min, CR_max, F_min, F_max)..., strategy) Algorithm(parameters; kargs...) @@ -85,21 +84,15 @@ function update_state!( args...; kargs... ) - population = status.population - - F = parameters.F - CR = parameters.CR - rng = options.rng # stepsize if parameters.F_min < parameters.F_max - F = parameters.F_min + (parameters.F_max - parameters.F_min) * rand(rng) + parameters.F = parameters.F_min + (parameters.F_max - parameters.F_min) * rand(options.rng) end if parameters.CR_min < parameters.CR_max - CR = - parameters.CR_min + (parameters.CR_max - parameters.CR_min) * rand(rng) + parameters.CR = parameters.CR_min + (parameters.CR_max - parameters.CR_min) * rand(options.rng) end new_vectors = reproduction(status, parameters, problem) @@ -203,7 +196,7 @@ function reproduction(status, parameters::AbstractDifferentialEvolution, problem F = parameters.F CR = parameters.CR - X = zeros(eltype(xBest), N,D) + X = zeros(eltype(xBest), N, D) for i in 1:N x = get_position(population[i]) From acc0e5188541ab1d7bdaba34286d37ec943b236e Mon Sep 17 00:00:00 2001 From: Jonathan Fischer PEPE Date: Mon, 22 Jan 2024 18:53:34 -0500 Subject: [PATCH 2/2] Cleaned up population reference; used more idiomatic broadcast assignment in loop --- src/algorithms/DE/DE.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/algorithms/DE/DE.jl b/src/algorithms/DE/DE.jl index 4dd4ca50..9f77ecc7 100644 --- a/src/algorithms/DE/DE.jl +++ b/src/algorithms/DE/DE.jl @@ -185,14 +185,14 @@ end function reproduction(status, parameters::AbstractDifferentialEvolution, problem) - @assert !isempty(status.population) + population = status.population + @assert !isempty(population) N = parameters.N - D = length(get_position(status.population[1])) + D = length(get_position(population[1])) strategy = parameters.strategy xBest = get_position(status.best_sol) - population = status.population F = parameters.F CR = parameters.CR @@ -203,7 +203,7 @@ function reproduction(status, parameters::AbstractDifferentialEvolution, problem u = DE_mutation(population, F, strategy, 1) v = DE_crossover(x, u, CR) evo_boundary_repairer!(v, xBest, problem.search_space) - X[i,:] = _fix_type(v, problem.search_space) + X[i,:] .= _fix_type(v, problem.search_space) end X