How to clear the data after each run in Python

49 Views Asked by At

I face a problem with the modification of dataframe.

For each individual of population will go to function chromo_eval and return fitness. However, when I run formula "fitness_set", it returns the wrong total cost of each individual. Because after running the first individual, the _data doesn't turn back to original status (before running), it saves and keeps modifying for next individual in population. That's why it returns wrong fitness for each individual.

Is there any ways to clear _data after running each individual, so it will return correct fitness of each individual in population?

def chromo_eval(_data,TimeWindow,_chromo):
  _data=_data.copy(deep=True)
  ...
  return totalcost,

population = toolbox.population(n=num_population)

fitness_set = list(toolbox.map(toolbox.evaluate, population))
for ind, fit in zip(population, fitness_set):
    ind.fitness.values = fit
0

There are 0 best solutions below