Created
December 16, 2021 17:37
-
-
Save Ifihan/af584a7ea6f56588a5eec4968259640b to your computer and use it in GitHub Desktop.
Mutation algorithm implementation in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def mutation(individual, mutation_rate): | |
for i in range(len(individual)): | |
if random.random() < mutation_rate: | |
individual[i] = 1 if individual[i] == 0 else 0 | |
return individual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment