evolutionary_optimization.genotype.implemented_genotypes package

Submodules

evolutionary_optimization.genotype.implemented_genotypes.binary_list_genotype module

class BinaryListGenotype(genotype=None, mutation_probability=0.5, ratio_of_population_for_crossover=0.5, number_of_genes=32, value_range=(0, 1))[source]

Bases: AbstractGenotype

__init__(genotype=None, mutation_probability=0.5, ratio_of_population_for_crossover=0.5, number_of_genes=32, value_range=(0, 1))[source]

Initialise instance of AbstractGenotype.

Parameters
  • genotype (Optional[List[int]]) – genotype used for mutation, crossover and to calculate phenotype_value in binary form.

  • 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 (Optional[Tuple[int, int]]) – minimum and maximum values of a gene.

Warning

This genotype can only be used for single value optimization e.g. for a ParabolaPhenotype, and would not work for BoothPhenotype.

classmethod build_random_genotype(number_of_genes=32, value_range=(0, 1), mutation_probability=0.1, ratio_of_population_for_crossover=0.5)[source]

Build random genotype attribute based on requirements.

Parameters
  • number_of_genes (int) – 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

BinaryListGenotype

Returns

Genotype object with updated genotype attribute.

crossover(parent_2_genotype)[source]

Performs single point crossover operation for 1 set of parents.

A random integer is generated to split the genotype of the two individuals - this is the gene slice index. Then two child genotypes are generated with the complementary parts of the parent genotypes. If the parent’s genotype length is 1, crossover is impossible so the parent instances are returned.

Example

parent_1.genotype = [1, 2, 3, 4] parent_2.genotype = [A, B, C, D] gene_slice_index = 1

child_1.genotype = [1, B, C, D] child_2.genotype = [A, 2, 3, 4]

Parameters

parent_2_genotype (BinaryListGenotype) – Individual which will be used to create an offspring.

Return type

Tuple[BinaryListGenotype, BinaryListGenotype]

Returns

Tuple of AbstractGenotype, representing two children genotypes that are a combination of the parents.

classmethod from_genotype(base_genotype, new_genotype)[source]

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

Return type

BinaryListGenotype

property genotype

Genotype value used for evaluation of phenotype.

Warning

This is the integer form of the self.binary_genotype.

mutate()[source]

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

return_integer_form()[source]

Return integer form of a binary number.

evolutionary_optimization.genotype.implemented_genotypes.float_list_genotype module

class FloatListGenotype(genotype=None, mutation_probability=0.5, ratio_of_population_for_crossover=0, number_of_genes=1, value_range=(-10000, 10000))[source]

Bases: object

__init__(genotype=None, mutation_probability=0.5, ratio_of_population_for_crossover=0, number_of_genes=1, value_range=(-10000, 10000))[source]

Initialise instance of AbstractGenotype.

Parameters
  • genotype (Optional[List[float]]) – 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.

classmethod build_random_genotype(number_of_genes=1, value_range=(-10000, 10000), mutation_probability=0.5, ratio_of_population_for_crossover=0)[source]

Build random genotype attribute based on class parameters.

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

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

Return type

AbstractGenotype

Returns

AbstractGenotype object with a randomly generated genotype attribute.

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.

classmethod from_genotype(base_genotype, new_genotype)[source]

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

Return type

FloatListGenotype

property genotype

Genotype value used for evaluation of phenotype.

mutate()[source]

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

evolutionary_optimization.genotype.implemented_genotypes.integer_list_genotype module

class IntegerListGenotype(genotype=None, mutation_probability=0.1, ratio_of_population_for_crossover=0.5, number_of_genes=1, value_range=(-10000, 10000))[source]

Bases: AbstractGenotype

__init__(genotype=None, mutation_probability=0.1, ratio_of_population_for_crossover=0.5, number_of_genes=1, value_range=(-10000, 10000))[source]

Initialise instance of AbstractGenotype.

Parameters
  • genotype (Optional[List[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.

classmethod build_random_genotype(number_of_genes=1, value_range=(-10000, 10000), mutation_probability=0.5, ratio_of_population_for_crossover=0.5)[source]

Builds random genotype attribute based on requirements.

Parameters
  • number_of_genes (int) – 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

IntegerListGenotype

Returns

Genotype object with updated genotype attribute.

crossover(parent_2_genotype)[source]

Performs single point crossover operation for 1 set of parents.

A random integer is generated to split the genotype of the two individuals - this is the gene slice index. Then two child genotypes are generated with the complementary parts of the parent genotypes. If the parent’s genotype length is 1, crossover is impossible so the parent instances are returned.

Example

parent_1.genotype = [1, 2, 3, 4] parent_2.genotype = [A, B, C, D] gene_slice_index = 1

child_1.genotype = [1, B, C, D] child_2.genotype = [A, 2, 3, 4]

Parameters

parent_2_genotype (IntegerListGenotype) – Individual which will be used to create an offspring.

Return type

Tuple[IntegerListGenotype, IntegerListGenotype]

Returns

Tuple of AbstractGenotype, representing two children genotypes that are a combination of the parents.

classmethod from_genotype(base_genotype, new_genotype)[source]

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

Return type

IntegerListGenotype

property genotype

Genotype value used for evaluation of phenotype.

mutate()[source]

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

Module contents