evolutionary_optimization.genotype.genotype_model package

Submodules

evolutionary_optimization.genotype.genotype_model.abstract_genotype module

class AbstractGenotype(genotype, mutation_probability, ratio_of_population_for_crossover, number_of_genes, value_range)[source]

Bases: ABC

abstract __init__(genotype, mutation_probability, ratio_of_population_for_crossover, number_of_genes, value_range)[source]

Initialise instance of AbstractGenotype.

Parameters
  • genotype (List[Union[float, int]]) – genotype used for mutation, crossover and to calculate phenotype_value.

  • mutation_probability (float) – probability of a gene mutating.

  • ratio_of_population_for_crossover (float) – ratio of population used for crossover when updating population.

  • number_of_genes (int) – number of genes in the genotype.

  • value_range (Tuple[int, int]) – minimum and maximum values of a gene.

abstract classmethod build_random_genotype(number_of_genes, value_range, mutation_probability, ratio_of_population_for_crossover)[source]

Build random genotype attribute based on class parameters.

Parameters
  • number_of_genes – number of genes in the genotype.

  • value_range (Tuple[int, int]) – minimum and maximum values of a gene.

  • mutation_probability (Optional[float]) – probability of a gene mutating.

  • ratio_of_population_for_crossover (Optional[float]) – ratio of population used for crossover when updating population.

Return type

AbstractGenotype

Returns

AbstractGenotype object with a randomly generated genotype attribute.

abstract crossover(parent_2_genotype)[source]

Perform crossover between two phenotypes.

Combines a portion of this object’s genotype with that of parent_2 to return 2 new phenotypes based on the combined genotypes. The new genotype length is the same as of the parents.

Parameters

parent_2_genotype (AbstractGenotype) – a genotype of the same class whose genotype will be mixed with

Return type

Tuple[AbstractGenotype, AbstractGenotype]

Returns

Two new phenotype instances based on the combined genotypes of the two parents.

abstract classmethod from_genotype(base_genotype, new_genotype)[source]

Create a new genotype using the parameters of an existing genotype.

Return type

AbstractGenotype

abstract property genotype

Genotype value used for evaluation of phenotype.

abstract mutate()[source]

In place modification of the genotype by randomly changing genes based on mutation probability.

evolutionary_optimization.genotype.genotype_model.genotype_interface module

class Genotype[source]

Bases: object

Maps Genotypes to their associated concrete class based on AbstractGenotype.

genotypes_dictionary = {Genotypes.BINARY_LIST: <class 'evolutionary_optimization.genotype.implemented_genotypes.binary_list_genotype.BinaryListGenotype'>, Genotypes.FLOAT_LIST: <class 'evolutionary_optimization.genotype.implemented_genotypes.float_list_genotype.FloatListGenotype'>, Genotypes.INTEGER_LIST: <class 'evolutionary_optimization.genotype.implemented_genotypes.integer_list_genotype.IntegerListGenotype'>}
classmethod get_genotype(genotype_enum)[source]

Return class of desired AbstractGenotype.

Return type

ABCMeta

class Genotypes(value)[source]

Bases: str, Enum

Enum containing implemented genotypes.

BINARY_LIST = 'binary_list'
FLOAT_LIST = 'float_list'
INTEGER_LIST = 'integer_list'

evolutionary_optimization.genotype.genotype_model.genotype_utils module

single_point_crossover(parent_1_genotype, parent_2_genotype, gene_slice_index)[source]

A single point crossover for genotype of type list.

This is a single point crossover. Using the gene_slice_index, for both parents the genotype are sliced. The slice [:gene_slice_index] is taken from parent_1 and the slice [gene_slice_index:] is taken from parent_2. The two complementary slices are then joined to create a new genotype (a child genotype).

Parameters
  • parent_1_genotype (List[int]) – genotype which will be used to create an offspring.

  • parent_2_genotype (List[int]) – genotype which will be used to create an offspring.

  • gene_slice_index (int) – random integer at which the parent genotypes will be sliced.

Return type

List[int]

Returns

A genotype used to build a Genotype object.

Module contents