Skip to content

Commit

Permalink
v3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jmejia8 committed Nov 12, 2021
1 parent 0403076 commit 90ac970
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Metaheuristics"
uuid = "bcdb8e00-2c21-11e9-3065-2b553b22f898"
authors = ["Jesus Mejia <jesusmejded@gmail.com>"]
version = "3.1.0"
version = "3.1.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
19 changes: 10 additions & 9 deletions src/algorithms/SPEA2/SPEA2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ end


function environmental_selection!(population, parameters::SPEA2)
fitness = compute_fitness(population)
Distance = compute_distances(population)
fitness = compute_fitness(population, Distance)
N = parameters.N

next = fitness .< 1
Expand All @@ -126,7 +127,7 @@ function environmental_selection!(population, parameters::SPEA2)
rank = sortperm(fitness)
next[rank[1:N]] .= true
elseif K > N
del = truncation(population[next], K-N)
del = truncation(population[next], K-N, Distance[next,next])
temp = findall(next)
next[temp[del]] .= false
end
Expand All @@ -153,20 +154,20 @@ function compute_distances(population)
return distances
end

function truncation(population,K)
distance = compute_distances(population)
function truncation(population, K, distance = compute_distances(population))
del = zeros(Bool, length(population))
while count(del) < K
remain = findall(.!del)
temp = sort(distance[remain,remain], dims = 2)
rank = sortslicesperm(temp, dims=1)
del[remain[rank[1]]] = true
#temp = sortperm(distance[remain,remain], dims = 2)
# rank = sortslicesperm(temp, dims=1)
nn = argmin(distance[remain,remain])
del[remain[nn.I[1]]] = true
end

return del
end

function compute_fitness(population)
function compute_fitness(population, Distance = compute_distances(population))
N = length(population)
dominate = zeros(Bool,N, N)
for i in 1:N
Expand All @@ -180,7 +181,7 @@ function compute_fitness(population)
S = sum(dominate,dims=2)[:,1]
R = [ sum(S[dominate[:,i]]) for i in 1:N]

distance = sort(compute_distances(population),dims=2)
distance = sort(Distance,dims=2)


D = 1 ./ (distance[:,floor(Int,sqrt(N))] .+ 2)
Expand Down

0 comments on commit 90ac970

Please sign in to comment.