Skip to content

Instantly share code, notes, and snippets.

@fyr91
Last active October 3, 2019 09:20
Show Gist options
  • Save fyr91/def2a7ea5bea7a2c5349f1314fbc5196 to your computer and use it in GitHub Desktop.
Save fyr91/def2a7ea5bea7a2c5349f1314fbc5196 to your computer and use it in GitHub Desktop.
population = []
offsprings = []
# when offspring not enough for 10% of the population
# breed
while len(offsprings) < len(elite):
# select parent pairs for breeding
parents_pairs = np.random.choice(elite, size=(int(len(elite)/2),2), replace=False)
for parents in parents_pairs:
# pre-pregancy checkup
if breedable(parents):
lineup1, lineup2 = breed(parents)
offsprings.append(lineup1)
if len(offsprings) < len(elite):
offsprings.append(lineup2)
population.extend(elite)
population.extend(offsprings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment