Created
November 16, 2019 06:08
-
-
Save IntegerMan/31c2637588662578950a74fe9cc81128 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
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