Created
January 31, 2021 16:36
-
-
Save rocreguant/e239834877c61b827a665c05b4aebc43 to your computer and use it in GitHub Desktop.
This file contains 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
def mutate_offspring(offspring, max_weight, object_list, objects_dict): | |
for mutation_number in range(int(len(offspring)*mutation_rate)): | |
a = np.random.randint(0,len(object_list)) | |
b = np.random.randint(0,len(offspring)) | |
offspring.insert(b, object_list[a]) | |
offspring = fit_in_knapsack(offspring, max_weight, objects_dict) | |
return offspring | |
def mutate_population(new_population_set, max_weight, object_list, objects_dict): | |
mutated_pop = [] | |
for offspring in new_population_set: | |
mutated_pop.append(mutate_offspring(offspring, max_weight, object_list, objects_dict)) | |
return mutated_pop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment