Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let getChildGenes (random: System.Random) parent1 parent2 mutationChance =
// Map from one parent to another, choosing a point to switch from one parent as the source
// to the other. Being an identical copy to either parent is also possible
let crossoverIndex = random.Next(Array.length parent1 + 1)
Array.mapi2 (fun i m f -> if i <= crossoverIndex then
m
else
f
) parent1 parent2
// Next allow each gene to be potentially mutated
|> mutateGenes random mutationChance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment