[Tutor] Tutor Digest, Vol 35, Issue 38
Carlos
carloslara at web.de
Sat Jan 13 10:32:09 CET 2007
Hello,
> Unfortunately, no. I for one can't interpret "I need the info every
> time that it gets updated by the loop"
The GA is creating solutions for a given problem, that are contained in
self.entities that looks like this:
Generation_01: [[1, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 0,
0, 0], [1, 1, 0, 0, 1, 1, 1, 1, 1, 1], [0, 1, 1, 1, 1, 0, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0, 1, 1, 0, 1]]
Generation_02, Generation_03, Generation_04...
Generation_25:[[1, 1, 1, 1, 1, 1, 1, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1,
1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
self.entities gets new values with each generation, because the solution
to a given problem is evolving and getting closer to a correct result.
The problem is that with:
Phenotypes = ga_inst.evolve(Gen)
I only get the last generation -or iteration- and I need to actualize
some objects position before evaluating the generation, so what I need
is to get the values of self.entity on each generation. Since this
values are going to be evaluted, I need to actualize some gemetrical
objects with every new self.entities before evaluating the solution.
I tried this:
def evolve(self, generations = 100):
""" Process a number of generations
Stop if:
- number of generations = generations
- halt variable has been set AND
there is an entity with a fitness which has obtained or exceeded
the halt value
Return the list of entities, or the halt-entity if prematurely
halted
"""
self.halt_reached = 0
for gen in range(generations):
print 'TEST', self.entities ### THIS IS MY CHANGE
self.do_mutation()
self.do_crossover()
print "Average fitness generation " + str(gen) + ": " +
str(self.avg_fitness())
if self.debug == 1:
self.echo_fitness()
if self.halt >= 0:
max_entity = self.get_max_fitness()
fit = self.calc_fitness(max_entity)
if fit >= halt:
self.halt_reached = 1
return [max_entity]
return self.entities
I can actually print the self.entities list once for each iteration,
before the evaluation takes place. What I dont know is how to actually
do something with the list, like putting it in a variable or something
to get access to it and actualize the geometry of my project. So
basically if there are 100 iterations I would need a way to get this
list 100 times, one for each iteration with its new data.
And just in case that it helps, the address of the forum were I uploaded
a piece of the code:
http://python-forum.org/py/viewtopic.php?p=11063#11063
And the GA project page:
Genetic Algorithm Python module
http://www.alextreme.org/projects/python_ai/
If you can help me please do it, this is critical for my project :(
Thanks for helping
Carlos
More information about the Tutor
mailing list