GA_Program.py

This is the main component of the genetic algorithm.

class Organisms.GA.GA_Program.GA_Program(cluster_makeup, pop_size, generations, no_offspring_per_generation, creating_offspring_mode, crossover_type, mutation_types, chance_of_mutation, r_ij, vacuum_to_add_length, Minimisation_Function, surface_details=None, epoch_settings={'use epoch': 'off'}, cell_length='default', memory_operator_information={'perform_memory_operator': 'Off'}, predation_information={'Predation_Switch': 'Off'}, fitness_information={'Fitness_Switch': 'Energy'}, ga_recording_information={}, force_replace_pop_clusters_with_offspring=True, user_initialised_population_folder=None, rounding_criteria=2, print_details=False, no_of_cpus=1, finish_algorithm_if_found_cluster_energy=None, total_length_of_running_time=None)

The Otago Research Genetic Algorithm for Nanoclusters, Including Structural Methods and Similarity (Organisms) program has been designed to perform a genetic algorithm for a nanoparticle of any composition and any size.

It has been designed for that it can be modified by others in the Garden group after I have left. Hopefully the code is readable and can be tuned, however I have tried to note what is happening during the code and why. More notes can be found in the

Parameters:
  • cluster_makeup ({str: int, ...}) – This contains the information on the makeup of the cluster you would like to optimise for. Format is a dictionary in the form of: {element: number of that element}

  • pop_size (int) – The size of the population

  • generations (int) – The number of generations that are run

  • no_offspring_per_generation (int) – The number of offspring that are created per generation

  • creating_offspring_mode (str.) – This indicates how the offspring are created, either via the mating method ‘followed’ by the mutation method, or by only perform the mating method ‘or’ mutation method, or (i.e. either mating and/or mutation). See manual for how to set this.

  • crossover_type (str.) – This is the type of crossover that you would like to use. See the manual for more information.

  • mutation_types (list of (str., float)) – This is a list that contains all the information about the mutation methods you would like to use.

  • chance_of_mutation (float) – This indicates the change of a mutation occuring. See the manual on specifically how this works.

  • r_ij (float) – This is the maximum bond distance that we would expect in this cluster. See the manual for more information.

  • vacuum_to_add_length (float) – This is the amount of vacuum to place around the cluster.

  • Minimisation_Function (__func__) – This is a function that determines how to locally minimise clusters. See manual for more information.

  • surface_details (None) – This functionality has not been designed yet. Default: None

  • epoch_settings (dict.) – This is designed to hold the information about the epoch method.

  • cell_length (float) – This is the length of the cubic unit cell to construct clusters in. See manual for more information. Default: ‘default’

  • predation_information (dict.) – This holds all the information about the predation operator. Default: {‘Predation Operator’:”Off”}

  • fitness_information (dict.) – This holds all the information about the fitness operator. Default: {‘Fitness Operator’:”Off”}

  • ga_recording_information (dict.) – Default: {}

  • force_replace_pop_clusters_with_offspring (bool.) – This will tell the genetic algorithm whether to swap clusters in the populatino with offspring if the predation operator indicates they are the same but the predation operator has a better fitness value than the cluster in the population.

  • user_initialised_population_folder (str. or None) – This is the directory to a folder containing any custom made clusters you would like to include in the initial population. Set this to None if you do not have any initial clusters to add into the population. Default: None

  • rounding_criteria (int) – The number of decimal places to round the energies of clusters made during the genetic algorithm to. Default: 2

  • print_details (bool.) – Verbose for this algorithm.

  • no_of_cpus (int) – The number of cpus that the algorithm can use via multiprocessing. Default: 1

  • finish_algorithm_if_found_cluster_energy (dict. or None) – If desired, the algorithm can finish if the LES is located. This is useful to use for methods testing. The algorithm will determine that the LES is found when the genetic algorithm locates the energy of the LES. Read the manual on how to use this. Default: None

  • total_length_of_running_time (int or None) – The total amount of time to run the genetic algorithm for. If the algorithm is still running after this time, the algorithm will safety finish. Time given in hours. None means no limit on time, Default: None.

get_tasks(previous_cluster_name, generation_number)

This provides a generator that contains the inputs needed to create the offspring via parallelisation.

natural_selection(offspring_pool, generation_number)

This definition allows the genetic algorithm to perform the natural selection procedure.

The algorithm works as follows:

  • The fitness of the population and the offspring are assessed.

  • The clusters in the population are ordered from lowest to highest fitness.

  • The offspring are ordered from highest to lowest fitness.

  • Replace the clusters in the population with the lowest fitnesses with the offspring with the highest fitnesses.

  • Once done, the Natural Selection procedure is finished.

Parameters:
  • generation_number (int) – This is the current generation of the genetic algorithm run. This mauy not be 0 if you are restarting the algorithm

  • offspring_pool (Offspring) – This is the offspring pool the GA will be using.

This Natural Selection procedure will update self.population

perform_epoch_on_population(generation_number)

This definition will perform an epoch upon the population

Parameters:

generation_number (int) – This is the current generation of the genetic algorithm run. This mauy not be 0 if you are restarting the algorithm

run_GA()

This definition is the base of the algorithm. Once the algorithm has set itself up, this will run the genetic algorithm