Modifying fitness values after each generation

34 views
Skip to first unread message

João Antunes

unread,
Nov 25, 2015, 4:46:29 PM11/25/15
to pyevolve
Hello, so I'm new to pyevolve and I'm trying to implement a binary coded rastring minimization GA with roulette wheel selection.
As the roulette only accepts maximization, I have to change the calculated fitness value of the chromossome to maxfitness - fitness.
I'm trying to do this with this function as setcallback:

def calculateRealFitness(ga_engine):
   best = ga_engine.bestIndividual()
   bestfitness = best.getFitnessScore()
   population = ga_engine.getPopulation()
   for i in xrange(10):   #10 is the size of the population in this case
      population[i].fitness = bestfitness - population[i].fitness
   ga_engine.internalPop = population
   return False

Unfortunately, it doesn't change anything. What is wrong with my code? What's the best way to do it?

Arseniy Terekhin

unread,
Nov 26, 2015, 9:01:48 AM11/26/15
to pyev...@googlegroups.com
I have't touched pyevolve for over two years, but example at http://pyevolve.sourceforge.net/0_6rc1/examples.html#example-3-schaffer-f6-deceptive-function say you CAN minimize:

   # Genetic Algorithm Instance
   ga = GSimpleGA.GSimpleGA(genome)
   ga.selector.set(Selectors.GRouletteWheel)

   ga.setMinimax(Consts.minimaxType["minimize"])



--

---
You received this message because you are subscribed to the Google Groups "pyevolve" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyevolve+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
I remain,
Arseniy Terekhin
Reply all
Reply to author
Forward
0 new messages