eckity.genetic_operators.selections.selection_method
1from abc import abstractmethod 2from overrides import override 3 4from typing import List 5 6from eckity.event_based_operator import Operator 7from eckity.individual import Individual 8 9 10class SelectionMethod(Operator): 11 def __init__( 12 self, 13 events=None, 14 ): 15 if events is None: 16 events = ["after_selection"] 17 super().__init__(events=events) 18 self.selected_individuals = None 19 20 @override 21 def apply_operator(self, payload): 22 return self.select(payload[0], payload[1]) 23 24 @abstractmethod 25 def select( 26 self, source_inds: List[Individual], dest_inds: List[Individual] 27 ) -> List[Individual]: 28 pass 29 30 def event_name_to_data(self, event_name): 31 if event_name == "after_selection": 32 return {"applied_individuals": self.selected_individuals} 33 else: 34 return {}
11class SelectionMethod(Operator): 12 def __init__( 13 self, 14 events=None, 15 ): 16 if events is None: 17 events = ["after_selection"] 18 super().__init__(events=events) 19 self.selected_individuals = None 20 21 @override 22 def apply_operator(self, payload): 23 return self.select(payload[0], payload[1]) 24 25 @abstractmethod 26 def select( 27 self, source_inds: List[Individual], dest_inds: List[Individual] 28 ) -> List[Individual]: 29 pass 30 31 def event_name_to_data(self, event_name): 32 if event_name == "after_selection": 33 return {"applied_individuals": self.selected_individuals} 34 else: 35 return {}
Helper class that provides a standard way to create an ABC using inheritance.
@abstractmethod
def
select( self, source_inds: List[eckity.individual.Individual], dest_inds: List[eckity.individual.Individual]) -> List[eckity.individual.Individual]: