GeneticAlgorithm  0.5 (beta)
A python framework for rapid GA prototyping
src/GeneticAlgorithm/EvaluationOperators.py
Go to the documentation of this file.
00001 import Core
00002 
00003 ## @class BaseEvaluationOperator
00004 #  @brief This class provides an easy way of developing evaluation operators that only evaluate recently replaced individuals
00005 class BaseEvaluationOperator(Core.GeneticOperator):
00006     ## @fn evaluateIndividual(self, individual)
00007     #  @brief This function evaluates one individual; Overload this function on all derived operators
00008     def evaluateIndividual(self, individual):
00009         individual.fitness = 0.0
00010     ## @fn evaluate(self, population)
00011     #  @brief This function applies the evaluateIndividual function to every recently replaced individual in the population
00012     def evaluate(self, population):
00013         # Evaluate only recently generated items (pointed to by population.lethals)        
00014         lethals = getattr(population, 'lethals', None )
00015         #  If population.lethals does not exist, update every individual (and set the lethals list to contain every index)
00016         if not lethals:
00017             lethals = range(len(population.individuals))        
00018         # Iterate over recently replaced individuals
00019         for i in lethals:
00020             self.evaluateIndividual(population.individuals[i])
00021             
00022     initialize = evaluate
00023     iterate    = evaluate
00024     finalize   = evaluate
 All Classes Namespaces Files Functions Variables