Skip to content

Instantly share code, notes, and snippets.

@MBlogs
MBlogs / genetic_optimisation.py
Last active September 15, 2020 22:33
Minimilistic code for conducting genetic optimisation. Two parents and singe-point crossover. Tournament selection.
import random
def create_child(population, genes, tournament_size, mutation_rate):
# Breed two parents, returning (possibly mutated) offspring
parent1 = select(population, tournament_size)
parent2 = select(population, tournament_size)
child = crossover(parent1, parent2)
child = mutate(child, mutation_rate, genes)
return child