Created
April 14, 2023 16:28
-
-
Save machkouroke/e02ad8256e5081fea7d6c245df2dd314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pop(vector::Vector{T}, element::T) where {T<:Any} | |
copy_vector = deepcopy(vector) | |
index = findfirst(==(element), vector) | |
if index !== nothing | |
deleteat!(copy_vector, index) | |
end | |
return copy_vector | |
end | |
function fitness(x::Chromosome)::Float64 | |
result = sum( | |
same_line(queen, pop(x.queens, queen)) | |
+ same_column(queen, pop(x.queens, queen)) | |
+ same_diagonal(queen, pop(x.queens, queen)) | |
for queen in x.queens | |
) | |
return 1 / (1 + result) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment