Question

Looking for a way to reuse 50% of previous population best individuals in different GA iteration .

For example at the end of current iteration inside a process do "population = ga.getPopulation()".Next iteration initialize 50% of that pop.

Does anyone know how to handle the population results?

Was it helpful?

Solution 2

Slices of code applied to this problem.

Function required:

def createOwnGen(self , ga_engine):
        gen = ga_engine.getCurrentGeneration()
        if gen == 0 and self.previous_population != []:
            population = ga_engine.getPopulation()
            popSize = len(population)
            for i in xrange(popSize/2):
                population[popSize/2+i] = self.previous_population[i]
            population.sort()
        return False

stepCallback (native function from pyevolve) is called in every generation .

....
ga.stepCallback.set(self.createOwnGen)
....
bestIndividue = ga.bestIndividual()
population = ga.getPopulation()
self.previous_population = population.internalPop
....

OTHER TIPS

You can use the method setElitismReplacement (see here) to define the number of individuals that the elitism will use.

Just for the record. setElitismReplacement would be a good solution in case to specify number of individuals to elitism in 1 GA complete run. In every generation just that number of individuals will be selected for next generation.

What i've meant was in diferent running store best population achieved of all generations and reuse 50% of previous best results to initialize next run.

Anyway an example has been posted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top