[Tutor] Problems with a Class

Dom Hamon python-tutor at runtime.nu
Sat Jan 13 02:08:16 CET 2007


 

> -----Original Message-----
> From: tutor-bounces at python.org 
> [mailto:tutor-bounces at python.org] On Behalf Of Carlos
> Sent: 12 January 2007 16:09
> To: tutor at python.org
> Subject: [Tutor] Problems with a Class
> 
> 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]

I think if you change this line to:

			 return self.entities, [max_entity]

And handle the return as a tuple of two lists, you should get what you 
want. It does mean changing the code that calls this function to handle 
the different return value, of course. 

dom




More information about the Tutor mailing list