population=[[[0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1], [4], [0]],
[[0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1], [3], [1]],
[[0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0], [4], [2]],
[[1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0], [1], [3]]]
selected_chromosomes=[[[0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0], [5], [2]],
[[0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1], [3], [0]]]
child1=[0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0]
child2=[0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1]
def PopulationAdjustment(population, selected_chromosomes):
for game in range(0, len(selected_chromosomes)):
if game in selected_chromosomes[game][2]==game in population[game][2]:
population.remove(game)
return population
So the objective here is to replace the parents for the children in a population (list), my approach was to delete the parents then append the children, based on the same counter. The structure of the list is [[chromosome],[fitness],[counter]]
, however they are not exactly the same since I manipulated the fitness during the selection to avoid 0 probabilities.
I am trying to index the items that have the same counter and delete them from the list, then the next step would be just to append
the children.
Ive been trying some different ways but I couldnt get it working properly, any thoughts on how to fix that? Also, if there is a way of replacing them directly by the children without having to perform 2 steps (remove and append) it would be aslo very welcome. Thanks!!