Skip to content

Instantly share code, notes, and snippets.

@Dhrumilcse
Last active September 19, 2018 17:50
Show Gist options
  • Save Dhrumilcse/1ea39182cbc107545a3bf474745f6dff to your computer and use it in GitHub Desktop.
Save Dhrumilcse/1ea39182cbc107545a3bf474745f6dff to your computer and use it in GitHub Desktop.
import random
def createChild(individual1, individual2):
child = ""
for i in range(len(individual1)):
if (int(100 * random.random()) < 50):
child += individual1[i]
else:
child += individual2[i]
return child
def createChildren(breeders, number_of_child):
nextPopulation = []
for i in range(len(breeders)/2):
for j in range(number_of_child):
nextPopulation.append(createChild(breeders[i], breeders[len(breeders) -1 -i]))
return nextPopulation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment