eckity.evaluators.simple_individual_evaluator
1from abc import abstractmethod 2 3from overrides import overrides 4 5from eckity.evaluators.individual_evaluator import IndividualEvaluator 6 7 8class SimpleIndividualEvaluator(IndividualEvaluator): 9 """ 10 Computes fitness value for the given individuals. 11 In simple case, evaluates each individual separately. 12 You will need to extend this class with your user-defined fitness evaluation methods. 13 """ 14 15 @overrides 16 def evaluate(self, individual, environment_individuals): 17 """ 18 Updates the fitness score of the given individuals, then returns the best individual 19 20 Parameters 21 ---------- 22 individual: Individual 23 the current individual to evaluate its fitness 24 25 environment_individuals: list of Individuals 26 the individuals in the current individual's environment 27 those individuals will affect the current individual's fitness 28 (not used in simple case) 29 30 Returns 31 ------- 32 Individual 33 the individual with the best fitness out of the given individuals 34 """ 35 super().evaluate(individual, environment_individuals) 36 fitness_score = self.evaluate_individual(individual) 37 individual.fitness.set_fitness(fitness_score) 38 return individual 39 40 @abstractmethod 41 def evaluate_individual(self, individual): 42 """ 43 Evaluate the fitness score for the given individual. 44 This function must be implemented by subclasses of this class (user-defined evaluators) 45 46 Parameters 47 ---------- 48 individual: Individual 49 The individual to compute the fitness for 50 51 Returns 52 ------- 53 float 54 The evaluated fitness value for the given individual 55 """ 56 raise ValueError("evaluate_individual is an abstract method in SimpleIndividualEvaluator")
9class SimpleIndividualEvaluator(IndividualEvaluator): 10 """ 11 Computes fitness value for the given individuals. 12 In simple case, evaluates each individual separately. 13 You will need to extend this class with your user-defined fitness evaluation methods. 14 """ 15 16 @overrides 17 def evaluate(self, individual, environment_individuals): 18 """ 19 Updates the fitness score of the given individuals, then returns the best individual 20 21 Parameters 22 ---------- 23 individual: Individual 24 the current individual to evaluate its fitness 25 26 environment_individuals: list of Individuals 27 the individuals in the current individual's environment 28 those individuals will affect the current individual's fitness 29 (not used in simple case) 30 31 Returns 32 ------- 33 Individual 34 the individual with the best fitness out of the given individuals 35 """ 36 super().evaluate(individual, environment_individuals) 37 fitness_score = self.evaluate_individual(individual) 38 individual.fitness.set_fitness(fitness_score) 39 return individual 40 41 @abstractmethod 42 def evaluate_individual(self, individual): 43 """ 44 Evaluate the fitness score for the given individual. 45 This function must be implemented by subclasses of this class (user-defined evaluators) 46 47 Parameters 48 ---------- 49 individual: Individual 50 The individual to compute the fitness for 51 52 Returns 53 ------- 54 float 55 The evaluated fitness value for the given individual 56 """ 57 raise ValueError("evaluate_individual is an abstract method in SimpleIndividualEvaluator")
Computes fitness value for the given individuals. In simple case, evaluates each individual separately. You will need to extend this class with your user-defined fitness evaluation methods.
@overrides
def
evaluate(self, individual, environment_individuals):
16 @overrides 17 def evaluate(self, individual, environment_individuals): 18 """ 19 Updates the fitness score of the given individuals, then returns the best individual 20 21 Parameters 22 ---------- 23 individual: Individual 24 the current individual to evaluate its fitness 25 26 environment_individuals: list of Individuals 27 the individuals in the current individual's environment 28 those individuals will affect the current individual's fitness 29 (not used in simple case) 30 31 Returns 32 ------- 33 Individual 34 the individual with the best fitness out of the given individuals 35 """ 36 super().evaluate(individual, environment_individuals) 37 fitness_score = self.evaluate_individual(individual) 38 individual.fitness.set_fitness(fitness_score) 39 return individual
Updates the fitness score of the given individuals, then returns the best individual
Parameters
- individual (Individual): the current individual to evaluate its fitness
- environment_individuals (list of Individuals): the individuals in the current individual's environment those individuals will affect the current individual's fitness (not used in simple case)
Returns
- Individual: the individual with the best fitness out of the given individuals
@abstractmethod
def
evaluate_individual(self, individual):
41 @abstractmethod 42 def evaluate_individual(self, individual): 43 """ 44 Evaluate the fitness score for the given individual. 45 This function must be implemented by subclasses of this class (user-defined evaluators) 46 47 Parameters 48 ---------- 49 individual: Individual 50 The individual to compute the fitness for 51 52 Returns 53 ------- 54 float 55 The evaluated fitness value for the given individual 56 """ 57 raise ValueError("evaluate_individual is an abstract method in SimpleIndividualEvaluator")
Evaluate the fitness score for the given individual. This function must be implemented by subclasses of this class (user-defined evaluators)
Parameters
- individual (Individual): The individual to compute the fitness for
Returns
- float: The evaluated fitness value for the given individual