Energy_Predation_Operator.py

This class is designed to allow the user to implement the Energy Predation Operator into your genetic algorithm run.

Eenrgy_Predation_Operator.py, Geoffrey Weal, 28/10/2018

This is one of the Predation Operators that can be used by the genetic algorithm program.

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

This is one of the Predation Operators that can be used by the genetic algorithm program.

This class will allow the genetic algorithm to procedure without any Predation Operator. Instead, this class provide a way to use the energetic fitness to obtain a fitness for each cluster. This Operator will not remove any clusters from the population or the offspring pool.

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

Energy_Predation_Operators_Options(predation_information)

This method is designed to add and check the options that you have placed in to the predation_information dictionary for the Energy Predation Operator

Parameters:

predation_information (dict.) – This contains all the information needed by the Predation Operator you want to use to run.

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 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_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)

get_energy_predation_methods()

This method is designed to import the methods needed to run this Predation Operator, using with the ‘simple’ or ‘comprehensive’ mode.

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