Skip to content

Commit

Permalink
Simplify uniformranking
Browse files Browse the repository at this point in the history
  • Loading branch information
aahaselgrove committed Sep 30, 2019
1 parent 31b085e commit 12a93e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Evolutionary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using Random
discrete, waverage, intermediate, line,
pmx, ox1, cx, ox2, pos,
# GA selections
ranklinear, uniformranking, roulette, sus, tournament, #truncation
ranklinear, rankuniform, roulette, sus, tournament, #truncation
# Optimization methods
es, cmaes, ga

Expand Down
33 changes: 5 additions & 28 deletions src/selections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,23 @@ function ranklinear(sp::Float64)
@assert 1.0 <= sp <= 2.0 "Selective pressure has to be in range [1.0, 2.0]."
function rank(fitness::Vector{Float64}, N::Int)
λ = length(fitness)
<<<<<<< Updated upstream
rank = sortperm(fitness)

prob = Vector{Float64}(undef, λ)
=======
idx = sortperm(fitness)

ranks = Vector{Float64}(undef, λ)
>>>>>>> Stashed changes
for i in 1:λ
prob[i] = ( 2.0- sp + 2.0*(sp - 1.0)*(rank[i] - 1.0) /- 1.0) ) / λ
end

<<<<<<< Updated upstream
return pselection(prob, N)
=======
return pselection(ranks, N)
>>>>>>> Stashed changes
end
return rank
end

# (μ, λ)-uniform ranking selection
function uniformranking::Int)
function uniformrank(fitness::Vector{Float64}, N::Int)
λ = length(fitness)
<<<<<<< Updated upstream
@assert μ < λ "μ should be less then $(λ)"

prob = fill(1/μ, μ)
return pselection(prob, N)
=======
@assert μ < λ "μ should equal $(λ)"

ranks = fill(1/μ, μ)

return pselection(ranks, N)
>>>>>>> Stashed changes
end
return uniformrank
# uniform ranking selection
function rankuniform(fitness::Vector{Float64}, N::Int)
μ = length(fitness)
prob = fill(1/μ, μ)
return pselection(prob, N)
end

# Roulette wheel (proportionate selection) selection
Expand Down

0 comments on commit 12a93e8

Please sign in to comment.