Predation Operator

Meow

class Organisms.GA.Predation_Operators.Predation_Operator.Predation_Operator(predation_information, population, print_details)

This is an abstract class to act as the skeleton of the Predation_Operator class.

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

  • 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.

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

abstract 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.

abstract 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 also recommend which clusters in the population should be removed and be replaced by which offspring prior to the natural selection process. Here, the cluster in the population and the offspring will be in violation of each other, however it may be advantageous to keep the offspring rather than the cluster in the population as the offspring is fitter than the cluster in the offspring

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)

check()

This method will check to make sure that the predation operator is available.

abstract check_initial_population(return_report=False)

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

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)

abstract 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

remove_offspring_and_replace_with_population_that_violate_predation_operator(population, offspring_pool, offspring_to_remove, population_to_be_replaced_by_offspring)

This method will remove similar offspring in the offspring_pool, and replace any offspring with clusters in the population (if desired).

Parameters:
  • population (Organisms.GA.Population.Population) – This is the population.

  • offspring_pool (Organisms.GA.Offspring_Pool.Offspring_Pool) – This is all the offspring.

  • offspring_to_remove (list of int) – These are all the offspring to remove from the offspring_pool.

  • population_to_be_replaced_by_offspring (list of (int, int)) – These are the names of the clusters in the population to be replaced by offspring in the offspring_pool. This is a list of (name of cluster in population to be replaced, name of offsring to replaced that cluster).

remove_offspring_that_violate_the_predation_operator(offspring_pool, offspring_to_remove)

Remove offspring from the Offspring_Pool

Parameters:
replace_population_with_offspring(population, offspring_pool, population_to_be_replaced_by_offspring)

Replace clusters in the population with offspring in the offspring_pool. These population clusters are replaced by similar offspring that have higher fitnesses than the offspring in the Offspring_Pool.

Parameters:
  • population (Organisms.GA.Population.Population) – This is the population.

  • offspring_pool (Organisms.GA.Offspring_Pool.Offspring_Pool) – This is all the offspring.

  • population_to_be_replaced_by_offspring (list of (int, int)) – These are the names of the clusters in the population to be replaced by offspring in the offspring_pool. This is a list of (name of cluster in population to be replaced, name of offsring to replaced that cluster).

abstract reset()

Reset the CNA database with no inputs