SCM_Predation_Operator.py

This class is designed to assess replicating features in the population and offspring as well as to provide a fitness factor which allows Natural Selection to differentiate between structures. This class is effectly an interface

class Organisms.GA.Predation_Operators.SCM_Predation_Operator.Cluster_Block(collection, collection_type, index)

This is used by the Remove_Cluster_Due_To_Predation_Violation definition to store information in an easy way to help the user understand what is going on in this method

Parameters:
  • collection (Population or Offspring_Pool) – This is the collection to record. This is either the instance of the Population or the Offspring_Pool

  • collection_type (str.) – This describes if the cluster recorded is in the population (given as ‘pop’) or the offspring (given as ‘off’).

  • index (int) – The position/index of the cluster in the collection.

class Organisms.GA.Predation_Operators.SCM_Predation_Operator.SCM_Predation_Operator(Predation_Information, fitness_information, population, no_of_cpus, print_details)

This predation operator uses the similarities from the SCM to determine whether to exclude clusters from the population because they are too similar to each other.

Parameters:
  • Predation_Information (dict.) – This contains all the information needed by the Predation Operator you want to use to run.

  • fitness_information (dict.) – This is all the settings needed for the SCM predation operator. This is needed if the fitness operator is the structure + energy fitness operator, where the CNA Database maybe the same database for the predation and fitness operator.

  • population (Organisms.GA.Population) – This is the population that this Operator will be controlling to make sure that no two clusters in the population have the same energy.

  • no_of_cpus (int) – This is the number of cpus to use.

  • print_details (bool) – Print details of the predation operator, like verbose

add_to_database(collection)

Add clusters similarities to the CNA database to be stored for future generations.

Parameters:

collection (Organisms.GA.Collection.Collection) – update the fitnesses of clusters in the collection.

assess_for_violations(offspring_pool, force_replace_pop_clusters_with_offspring)

This definition is designed to determine which offspring (and the clusters in the population) violate the Predation Operator. It will not remove or change any clusters in the offspring or population, but instead will record which offspring violate the Predation Operator.

It will return two tuples with nothing in them, as required by this def.

Parameters:
  • offspring_pool (Organisms.GA.Offspring_Pool.Offspring_Pool) – This is the collection of offspring to assess for violations to the Predation Operator.

  • force_replace_pop_clusters_with_offspring (bool.) – This will tell the genetic algorithm whether to swap clusters in the population 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.

Returns:

A list of the names of the offspring to be removed * force_replacement (tuple of (int, int)): A list of the clusters in the population that should be replaced, and the offspring they should be replaced by.

Return type:

  • offspring_to_remove (tuple of ints)

assess_for_violations_force_replacement(offspring_pool)

This definition is designed to determine which offspring (and the clusters in the population) violate the Predation Operator. It will not remove or change any clusters in the offspring or population, but instead will record which offspring violate the Predation Operator.

It will return two tuples with nothing in them, as required by this def.

Parameters:

offspring_pool (Organisms.GA.Offspring_Pool.Offspring_Pool) – This is the collection of offspring to assess for violations to the Predation Operator.

Returns:

A list of the names of the offspring to be removed * force_replacement (tuple of (int, int)): A list of the clusters in the population that should be replaced, and the offspring they should be replaced by.

Return type:

  • offspring_to_remove (tuple of ints)

assess_for_violations_message(swap_P_O, remove_O_similar_to_too_many_P, removal_O_P, removal_O_O)

This method will tell the information that offspring are removed or replaced and why.

Parameters:
  • swap_P_O (tuple of (Organisms.GA.SCM_Predation_Operator.Cluster_Block, Organisms.GA.SCM_Predation_Operator.Cluster_Block)) – The clusters in the population to swap out, and the offspring to swap in its place. These will be replaced because the offspring has a higher fitness than the cluster in the population, even though they are similar.

  • remove_O_similar_to_too_many_P (tuple of (Organisms.GA.SCM_Predation_Operator.Cluster_Block, Organisms.GA.SCM_Predation_Operator.Cluster_Block)) – Remove offspring because there are too many similar clusters to it in the population already.

  • removal_O_P (tuple of (Organisms.GA.SCM_Predation_Operator.Cluster_Block, Organisms.GA.SCM_Predation_Operator.Cluster_Block)) – Remove offspring because they are similar to a cluster in the population. These offspring are less fit than their similar counterparts in the population.

  • removal_O_O (tuple of (Organisms.GA.SCM_Predation_Operator.Cluster_Block, Organisms.GA.SCM_Predation_Operator.Cluster_Block)) – Remove offpsring because they are similar to other clusters in the Offspring_Pool. This offspring is less fit than their similar counterparts in the offspring_pool.

assess_for_violations_no_force_replacement(offspring_pool)

This definition is designed to determine which offspring (and the clusters in the population) violate the Predation Operator. It will not remove or change any clusters in the offspring or population, but instead will record which offspring violate the Predation Operator.

It will return two tuples with nothing in them, as required by this def.

Parameters:

offspring_pool (Organisms.GA.Offspring_Pool.Offspring_Pool) – This is the collection of offspring to assess for violations to the Predation Operator.

Returns:

A list of the names of the offspring to be removed * force_replacement (tuple of (int, int)): A list of the clusters in the population that should be replaced, and the offspring they should be replaced by.

Return type:

  • offspring_to_remove (tuple of ints)

check_initial_population(return_report=False)

This definition is responsible for making sure that the initialised population obeys the CNA Predation Operator.

Parameters:

return_report (bool.) – Will return a dict with all the information about what clusters are similar to what other clusters in the population.

Returns:

a list of the clusters to remove from the population as they violate the Predation Operator. Format is [(index in population, name fo cluster),…] * CNA_report (dict.): a dictionary with information on the clusters being removed and the other clusters in the population which have caused the violation to the SCM Predation Operator. This information is only used to display information so they know why there are violations to the Predation Operator when they occur. For is {removed cluster: [list of clusters that this cluster is similar to in the population.]}

Return type:

  • clusters_to_remove (list of ints)

get_similar_clusters_to_remove(return_report)

Will update the CNA_Database and return all the names of clusters in the population that violate the SCM predation operator

Parameters:

return_report (bool.) – Will return a dict with all the information about what clusters are similar to what other clusters in the population.

remove_from_database(cluster_names_to_remove)

Clusters to remove from the CNA database

Parameters:

cluster_names_to_remove (list of ints) – A list of the names of all the clusters to remove from the CNA database

reset()

Reset the CNA database with no inputs