How to get a single (or a list) of individuals from a population?

178 views
Skip to first unread message

Paulo Almeida

unread,
Nov 21, 2013, 2:34:40 AM11/21/13
to pyev...@googlegroups.com
Hi,

  In the first place, I would like to congratulate the authors of pyevolve for the nice module and documentation available. Keep working, you are really making the difference.

  For educational/didatical purposes, I am solving a very simple problem using GSimpleGA class and would like to get, for each generation, the raw values (or contents) of each individual from the population at a particular generation, and print them out. I could not find a method to give me that. So far, I can only get the best individual from the population.

  Is there a way to do this? Thank you for your support.

Cheers,

  Paulo

Christian S. Perone

unread,
Nov 21, 2013, 2:24:47 PM11/21/13
to pyev...@googlegroups.com
Hello Paulo, note that the population object has the iteration protocol impelemented, so you can easily do something like this:

population = ga_engine.getPopulation()
for individual in population:
    # ... do what you need with the individual

Please see the Example #5.

Yours,
- Christian S. Perone



--
 
---
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/groups/opt_out.



--
"Forgive, O Lord, my little jokes on Thee, and I'll forgive Thy great big joke on me."

Paulo Almeida

unread,
Nov 22, 2013, 1:32:54 AM11/22/13
to pyev...@googlegroups.com
Hi Christian,

  Thx for your feedback.

  I knew about getPopulation(), but did not realize, until now, how to find the appropriate method to return the binary value of each individual. Of course, I was looking in the wrong place, not the GPopulation class but, in my case, the G1DBinaryString class. There, I found the method getBinary(), which does what I need.

  Just for the records, to print individual values I am using:

pop = ga_engine.getPopulation()
for indiv in pop:
    ...:     print indiv.getBinary()
 
Cheers, Paulo

Christian S. Perone

unread,
Nov 22, 2013, 6:14:13 AM11/22/13
to pyev...@googlegroups.com
Thanks for posting back the answer of your problem here Paulo.
Reply all
Reply to author
Forward
0 new messages