Genetic algorithm with tournaments selection
def tournament(n, population): # Pick n random individuals from the population candidates = [random.choice(population) for _ in range(n)] # Find the best candidate return max(candidates, key=lambda c: c.fitness)