Crossover.py

This describes the

MatingProcedure.py, 13/04/2017, Geoffrey R. Weal

This program is designed to run the mating proceedure of the Genetic Algorithm.

class Organisms.GA.Crossover.Crossover(crossover_type, r_ij, vacuumAdd, size_of_clusters)

This class is designed to perform the mating proceedure of the genetic algorithm. This will produce a cluster that is an outcome of the mating proceedure.

Parameters
  • crossover_type (str.) –

    This is the type of mating proceedure the user would like to use. There are currently a few options implimented into this mating proceedure:

    • ”CAS_weighted”-: Cut and Splice - Deavon and Ho - weighted by fitness of parents (CAS_weighted)

    • ”CAS_random”: Cut and Splice - Deavon and Ho - cut a random percent x% of parent 1 and (100-x)% of parent 2 (CAS_random)

    • ”CAS_half”: Cut and Splice - Deavon and Ho - cut both parents by half (CAS_half)

    • ”CAS_custom_XX”: Cut and Splice - Deavon and Ho - cut a random percent XX% of parent 1 and (100-XXX)% of parent 2. To use this set crossType = CAS_custom_XX, where XX is a float of your choice between 0 and 100.

  • r_ij (float) – the maximum bond distance between atoms in the cluster. This should be the largest value possible for your cluster.

  • vacuumAdd (float) – The vacuum around the cluster

  • size_of_clusters (int) – The number of atoms in the cluster.

Cut_and_Splice_Devon_and_Ho(parents)

This definition is designed to perform the Cut and Splice Method as specified by Devon and Ho to mate the parents to give the offspring. The method works as follows:

  1. Rotate each parent by some random amount in the theta and phi directions.

  2. Sort the assignment of atoms in the cluster from most positive to most negative z value.

  3. Perform a Cut and Splice proceedure, where the parents are cut in some way and spliced together to give the offspring.

Parameters

parents ([Organisms.GA.Cluster, Organisms.GA.Cluster]) – This is the population to choose clusters from to mate together.

Returns

Returns an offspring that has been created from mating two parent clusters together.

Rtypes

Organisms.GA.Cluster

centre_offspring_at_centre_of_cell(offspring)

This method will center the offspring as required.

Parameters

offspring (Organisms.GA.Cluster) – The offspring cluster.

centre_parents_about_origin(parents)

This method will center the parents about the zero point. This is to make sure that their two halfs will allign correctly when they are cut and spliced to form a new offsping

Parameters

parents ([Organisms.GA.Cluster, Organisms.GA.Cluster]) – This is the population to choose clusters from to mate together.

Returns

The parents which have been centered about the (0,0,0) point of the unit cell

Rtypes

[Organisms.GA.Cluster, Organisms.GA.Cluster]

half_index_custom_method(cross_type)

This method will determine how to cut the cluster based on the atom to divide from, where the atoms have been numbered in order of the z axis.

This version of the method divides the parents based on a percentage of atoms to take from parent 1

Here, percentage of parent1 is taken, while 1.0-percentage of parent2 two is taken.

Parameters

crossover_type (str.) – This is the type of mating proceedure the user would like to use. This should be set to “CAS_custom_XX”, where XX is the percentage of parent 1 to be cut.

Returns

The atom number in the cluster to cut the atom.

Return type

int

half_index_half_method()

This method will determine how to cut the cluster based on the atom to divide from, where the atoms have been numbered in order of the z axis.

This version of the method divides the parents in half.

Returns

The atom number in the cluster to cut the atom.

Return type

int

half_index_random_method()

This method will determine how to cut the cluster based on the atom to divide from, where the atoms have been numbered in order of the z axis.

This version of the method divides the parents at some random atom indice

Returns

The atom number in the cluster to cut the atom.

Return type

int

half_index_weighted_method(parents)

This method will determine how to cut the cluster based on the atom to divide from, where the atoms have been numbered in order of the z axis.

This version of the method divides the parents based on their relative fitnesses.

Parameters

parents ([Organisms.GA.Cluster, Organisms.GA.Cluster]) – This is the population to choose clusters from to mate together.

Returns

The atom number in the cluster to cut the atom.

Return type

int

mate_Cut_and_Splice(parents)

This method will perform the mating proceedure as specified by the user. This can been designed to be used with multiple parents, however currently it is set up for 2 parents. It has also been developed for mating multi-metallic (multi-elemental) clusters together.

Parameters

parents ([Organisms.GA.Cluster, Organisms.GA.Cluster]) – This is the population to choose clusters from to mate together.

Returns

Returns an offspring that has been created from mating two parent clusters together.

Rtypes

Organisms.GA.Cluster

mate_Cut_and_Splice_error_checking_1(parents)

This is a method for checking if there are any issues with the Cut_and_splice method.

This method is only needed when you are developing or modifying a mating proceedure, to help with debugging. Otherwise, you dont need to use this algorithm

Parameters

parents ([GA.Cluster, GA.Cluster]) – This is the population to choose clusters from to mate together.

Returns

A list which indicates the types of elements, and the number of those elements, in the cluster

Return type

{str: int, ..}

mate_Cut_and_Splice_error_checking_2(elemental_makeup_of_parents, offspring)

This is a method for checking if there are any issues with the Cut_and_splice method.

This method is only needed when you are developing or modifying a mating proceedure, to help with debugging. Otherwise, you dont need to use this algorithm

Parameters
  • elemental_makeup_of_parents ({str: int, ..}) – A list which indicates the types of elements, and the number of those elements, in the cluster

  • offspring (Organisms.GA.Cluster) – The offspring cluster.

mating(parents)

This definition is designed as a switch to choose the mating method the user wishes to use for the genetic algorithm.

Parameters

parents ([Organisms.GA.Cluster, Organisms.GA.Cluster]) – This is the population to choose clusters from to mate together.

Returns

Returns an offspring that has been created from mating two parent clusters together.

Rtypes

Organisms.GA.Cluster

pickParentsFromThePopulation(population)

This definition will pick the parents for mating.

Parameters

population (Organisms.GA.Population) – This is the population to choose clusters from to mate together.

Returns

two clusters from the population that will be mated together to give the offspring.

Rtypes

(Organisms.GA.Cluster, Organisms.GA.Cluster)

rotate(cluster)

Rotate the cluster by some random angle in the theta and phi directions.

Parameters

cluster (Organisms.GA.Cluster) – The cluster to be randomly rotated

roulette(population)

Performed the roulette wheel method to obtain the parents for a Mating proceedure

Reference: https://pubs.rsc.org/en/content/articlepdf/2003/dt/b305686d

Parameters

population (Organisms.GA.Population) – This is the population to choose clusters from to mate together.

Returns

Will return a tuple of two integers that represent the indices of clusters in the population to use as parent to mate together to give a new offspring.

Rtypes

[int, int]

run(run_input)

Run this the Mating Proceedure and gives an offspring.

Parameters

population (Organisms.GA.Population) – This is the population to choose clusters from to mate together.

Returns

offspring

Rtypes

Organisms.GA.Cluster

tournament(population)

Performed the tournament method to obtain the parents for a Mating proceedure

Reference: https://pubs.rsc.org/en/content/articlepdf/2003/dt/b305686d

Parameters

population (Organisms.GA.Population) – This is the population to choose clusters from to mate together.

Returns

Will return a tuple of two integers that represent the indices of clusters in the population to use as parent to mate together to give a new offspring.

Rtypes

[int, int]