Skip to content

Instantly share code, notes, and snippets.

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