Skip to content

Commit

Permalink
Population initialization function accepts custom individual init fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
erwanlecarpentier committed Apr 30, 2021
1 parent dc2f243 commit 41a8af0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/evolution.jl
Expand Up @@ -51,10 +51,15 @@ function save_gen(e::AbstractEvolution)
end

"create all members of the first generation"
function initialize(itype::Type, cfg::NamedTuple)
function initialize(itype::Type, cfg::NamedTuple; kwargs...)
population = Array{itype}(undef, cfg.n_population)
kwargs_dict = Dict(kwargs)
for i in 1:cfg.n_population
population[i] = itype(cfg)
if haskey(kwargs_dict, :init_function)
population[i] = kwargs_dict[:init_function](cfg)
else
population[i] = itype(cfg)
end
end
population
end
Expand Down

0 comments on commit 41a8af0

Please sign in to comment.