Skip to content

Instantly share code, notes, and snippets.

@NicolleLouis
Created November 27, 2017 17:21
Show Gist options
  • Save NicolleLouis/77968797815e433545022e09c38cf405 to your computer and use it in GitHub Desktop.
Save NicolleLouis/77968797815e433545022e09c38cf405 to your computer and use it in GitHub Desktop.
Intermutation Knapsack
def mutate_one_individual(individual, mutationRate):
for geneIndex in range(len(individual)):
if (100 * random.random() < mutationRate):
individual[geneIndex] = not individual[geneIndex]
return individual
def mutate_population(population, mutationRate):
for individual in population:
individual = mutate_one_individual(individual, mutationRate)
return (population)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment