Energy_Fitness.py

Meow

class Organisms.GA.Fitness_Operators.Energy_Fitness_Operator.Energy_Fitness_Operator(fitness_information, predation_operator, population, print_details)

The Fitness class is designed to determine and assign the appropriate fitness value to clusters created during the genetic algorithm. The fitnesses are based on the energies of the clusters in the offspring and the population.

There are only two methods that need to be written for the predation operator that is to be used. These are:
  • assign_population_fitnesses

  • assign_all_fitnesses

Parameters:
  • fitness_information (dict.) – This is all the information that is needed about the fitness class

  • predation_operator (Organisms.GA.Predation_Operator) – This is the predation operator that this fitness class will take information from if needed to obtain a fitness.

  • population (Organisms.GA.Population) – The population to assign fitnesses to

  • print_details (bool) – Print the details of the energy fitness operator. True if yes, False if no

add_to_database(collection)

This method is required by Organisms.GA.Fitness_Operators.Fitness_Operator, but does not do anything

Parameters:

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

assign_all_fitnesses_after_assessing_against_predation_operator(all_offspring_pools, current_generation_no, offspring_to_remove)

This method is to be used in the GA program. This will assign all the fitnesses of all clusters in the current generation (population and offspring) after the offspring are assessed to understand if they violate the predation operator (i.e. an offspring is Class 1 similar to a cluster in the population, or another offspring).

See the description given for the “assign_all_fitnesses” def on what the crux of this method is.

If you write your own diversiy and fitness classes, you do not need to implement this method in your fitness class.

Parameters:
  • all_offspring_pools (list of Organisms.GA.Offspring_Pool) – All of the offspring_pools

  • current_generation_no (int) – The current generation

  • offspring_to_remove (list of int) – a list of all the names of clusters in the offspring that will be removed.

assign_all_fitnesses_after_natural_selection(current_generation_no)

This method is to be used in the GA program. This will assign all the fitnesses to all the clusters in the population before the offspring are assessed to understand if they violate the predation operator (i.e. an offspring is Class 1 similar to a cluster in the population, or another offspring).

See the description given for the “assign_population_fitnesses” def on what the crux of this method is.

If you write your own diversiy and fitness classes, you do not need to implement this method in your fitness class.

Parameters:

current_generation_no (int) – The current generation

assign_all_fitnesses_before_assessing_against_predation_operator(all_offspring_pools, current_generation_no)

This method is to be used in the GA program. This will assign all the fitnesses of all clusters in the current generation (population and offspring) before the offspring are assessed to understand if they violate the predation operator (i.e. an offspring is Class 1 similar to a cluster in the population, or another offspring).

See the description given for the “assign_all_fitnesses” def on what the crux of this method is.

If you write your own diversiy and fitness classes, you do not need to implement this method in your fitness class.

Parameters:
  • all_offspring_pools (list of Organisms.GA.Offspring_Pool) – list of all the offspring pools of offspring to assign fitness values to.

  • current_generation_no (int) – The current generation

assign_initial_population_fitnesses()

This method is designed to assign fitness values to the clusters of the population only at the start of the GA, when the population has been initialised

assign_resumed_population_fitnesses(resume_from_generation)

This method is designed to assign fitness values to the clusters of the population only at the beginning of a resumed GA.

Parameters:

resume_from_generation (int) – The current generation to resume from.

energy_fitness_options(fitness_information, predation_operator)

This method is designed to set the variables requires for this fitness.

Parameters:
  • fitness_information (dict.) – This is all the information that is needed about the fitness class

  • predation_operator (Organisms.GA.Predation_Operator) – This is the predation operator that this fitness class will take information from if needed to obtain a fitness.

remove_from_database(cluster_names_to_remove)

This method is required by Organisms.GA.Fitness_Operators.Fitness_Operator, but does not do anything.

Parameters:

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

reset()

This method is required by Organisms.GA.Fitness_Operators.Fitness_Operator, but does not do anything