original_docstring: Creates a new gene randomly inheriting attributes from its parents.
docstring: Creates a new gene randomly inheriting attributes from its parents.
docstring_tokens: Creates a new gene randomly inheriting attributes from its parents .
code: def crossover(self, gene2: BaseGene) -> BaseGene:
          """Creates a new gene randomly inheriting attributes from its parents."""
          assert self.key == gene2.key
  
          # Note: we use "a if random() > 0.5 else b" instead of choice((a, b))
          # here because `choice` is substantially slower.
          new_gene: BaseGene = self.__class__(self.key)
          for a in self._gene_attributes:
              if random() > 0.5:
                  setattr(new_gene, a.name, getattr(self, a.name))
              else:
                  setattr(new_gene, a.name, getattr(gene2, a.name))
  
          return new_gene
code_tokens: def crossover ( self , gene2 : BaseGene ) -> BaseGene : assert self . key == gene2 . key new_gene : BaseGene = self . __class__ ( self . key ) for a in self . _gene_attributes : if random ( ) > 0.5 : setattr ( new_gene , a . name , getattr ( self , a . name ) ) else : setattr ( new_gene , a . name , getattr ( gene2 , a . name ) ) return new_gene
short_docstring: Creates a new gene randomly inheriting attributes from its parents.
short_docstring_tokens: Creates a new gene randomly inheriting attributes from its parents .
comment: """Creates a new gene randomly inheriting attributes from its parents."""$SEP$# Note: we use "a if random() > 0.5 else b" instead of choice((a, b))$SEP$# here because `choice` is substantially slower.