Skip to content

Instantly share code, notes, and snippets.

@machkouroke
Created April 14, 2023 22:21
Show Gist options
  • Save machkouroke/a841951aceb7975687ced7a24ffee7c1 to your computer and use it in GitHub Desktop.
Save machkouroke/a841951aceb7975687ced7a24ffee7c1 to your computer and use it in GitHub Desktop.
function mutation(child::Chromosome, n::Int64)::Chromosome
mutated_child::Chromosome = deepcopy(child)
probability::Float64 = 0.8
for i in 1:2
if (rand()) < probability
swap_index::Int64 = rand(setdiff(1:n, i))
mutated_child[i], mutated_child[swap_index] = Queen(i, mutated_child[swap_index].y), Queen(swap_index, mutated_child[i].y)
end
end
return mutated_child
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment