Skip to content

Instantly share code, notes, and snippets.

@rocreguant
Created January 31, 2021 16:36
Show Gist options
  • Save rocreguant/e4a0b7e63c4f3219805a4fd8b751e1e8 to your computer and use it in GitHub Desktop.
Save rocreguant/e4a0b7e63c4f3219805a4fd8b751e1e8 to your computer and use it in GitHub Desktop.
def mate_progenitors(prog_a, prog_b, max_weight, objects_dict):
offspring = []
for i in zip(prog_a, prog_b):
offspring.extend(i)
offspring = list(dict.fromkeys(offspring)) #Removing duplicates
offspring = fit_in_knapsack(offspring, max_weight, objects_dict)
return offspring
def mate_population(progenitor_list, max_weight, objects_dict):
new_population_set = []
for i in range(progenitor_list.shape[1]):
prog_a, prog_b = progenitor_list[0][i], progenitor_list[1][i]
offspring = mate_progenitors(prog_a, prog_b, max_weight, objects_dict)
new_population_set.append(offspring)
return new_population_set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment