1

I used deap library on Python to work with genetic algorithm. For example: I have individual [0,1,1,1,1,0], I have 3 methods of mutation such as mutation1, mutation2, mutation3. With deap library, I do the mutation as below:

for mutate in [mutate1, mutate2, mutate3]: mutate(individual)

How can I save the population data after each mutation method? Besides, I'm trying to use deap.logbook for this but it doesn't work. Anyone have any suggestion about this?

Windy764
  • 77
  • 7
  • for more details, what I mean is likes after mutate1, individual becomes [0,1,1,1,0,0], then after mutate2 it becomes [0,0,1,1,1,0] and after mutate3 it becomes [0,1,1,0,1,0] for example. I want to get all of these results – Windy764 Oct 08 '18 at 08:30

1 Answers1

1

You could open 3 files and in each iteration after each method append the population to correct file.

files = ['path/to/method_1', 'path/to/method_2', 'path/to/method_3']

files_list = [open(i, 'a+') for i in files]

for mutate in range(len([mutate1, mutate2, mutate3])):
    mutated = mutate[i](individual)
    files[i].write(mutated)
Novak
  • 2,143
  • 1
  • 12
  • 22