Generation

generate functionSat, 12 Nov 2022

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)

Questions about programming?Chat with your personal AI assistant