Skip to content

Commit 25c2098

Browse files
committed
Simplify uniformranking
1 parent 19e75b4 commit 25c2098

2 files changed

Lines changed: 6 additions & 29 deletions

File tree

src/Evolutionary.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using Random
1212
discrete, waverage, intermediate, line,
1313
pmx, ox1, cx, ox2, pos,
1414
# GA selections
15-
ranklinear, uniformranking, roulette, sus, tournament, #truncation
15+
ranklinear, rankuniform, roulette, sus, tournament, #truncation
1616
# Optimization methods
1717
es, cmaes, ga
1818

src/selections.jl

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,23 @@ function ranklinear(sp::Float64)
77
@assert 1.0 <= sp <= 2.0 "Selective pressure has to be in range [1.0, 2.0]."
88
function rank(fitness::Vector{Float64}, N::Int)
99
λ = length(fitness)
10-
<<<<<<< Updated upstream
1110
rank = sortperm(fitness)
1211

1312
prob = Vector{Float64}(undef, λ)
14-
=======
15-
idx = sortperm(fitness)
16-
17-
ranks = Vector{Float64}(undef, λ)
18-
>>>>>>> Stashed changes
1913
for i in 1:λ
2014
prob[i] = ( 2.0- sp + 2.0*(sp - 1.0)*(rank[i] - 1.0) /- 1.0) ) / λ
2115
end
2216

23-
<<<<<<< Updated upstream
2417
return pselection(prob, N)
25-
=======
26-
return pselection(ranks, N)
27-
>>>>>>> Stashed changes
2818
end
2919
return rank
3020
end
3121

32-
# (μ, λ)-uniform ranking selection
33-
function uniformranking::Int)
34-
function uniformrank(fitness::Vector{Float64}, N::Int)
35-
λ = length(fitness)
36-
<<<<<<< Updated upstream
37-
@assert μ < λ "μ should be less then $(λ)"
38-
39-
prob = fill(1/μ, μ)
40-
return pselection(prob, N)
41-
=======
42-
@assert μ < λ "μ should equal $(λ)"
43-
44-
ranks = fill(1/μ, μ)
45-
46-
return pselection(ranks, N)
47-
>>>>>>> Stashed changes
48-
end
49-
return uniformrank
22+
# uniform ranking selection
23+
function rankuniform(fitness::Vector{Float64}, N::Int)
24+
μ = length(fitness)
25+
prob = fill(1/μ, μ)
26+
return pselection(prob, N)
5027
end
5128

5229
# Roulette wheel (proportionate selection) selection

0 commit comments

Comments
 (0)