Skip to content

Instantly share code, notes, and snippets.

@machkouroke
Created April 14, 2023 16:28
Show Gist options
  • Save machkouroke/e02ad8256e5081fea7d6c245df2dd314 to your computer and use it in GitHub Desktop.
Save machkouroke/e02ad8256e5081fea7d6c245df2dd314 to your computer and use it in GitHub Desktop.
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