[Tutor] Problems with a Class

Carlos carloslara at web.de
Sat Jan 13 01:08:53 CET 2007


Hello,

I'm just about to finish my project, but something is causing me 
trouble. I need to find out how to get some information out of the 
genetic algorithm that Im using. This algorithm is generating some 
coordinates for a collection of objects, until now I needed only the 
final result of the process. But I discovered that the final information 
is not enough, I need to get some intermediate data to actualize the 
positions of the objects and then evaluate those positions.

This is the area of the algorith that I think holds the info that I need:

def evolve(self, generations = 100):
  
        self.halt_reached = 0
       
        for gen in range(generations):

            #Changed.
            print 'GEN:',gen, self.entities
           
            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]

The line marked as #Changed is what I changed,  with this I was able to 
print the info, but I'm sorry to say that I have no clue at how to apply 
something like return() that would give me this self.entities list. As 
you can see there is a for loop and I need the info every time that it 
gets updated by the loop.

Hopefully I'm making myself clear and the info is enough.

Thanks for your help in advance
Carlos




More information about the Tutor mailing list