EnergyProfile.py

This class is designed to record the energies of the clusters during the genetic algorithm.

class Organisms.GA.EnergyProfile.EnergyProfile(collection, end_name=None)

This class is designed to record the energies of the clusters during the genetic algorithm.

Parameters:
  • collection (Organisms.GA.Collection) – This is the specific collection of the genetic algorithm this class will be recording for.

  • end_name (str.) – Include a suffix to the EnergyProfile.txt filename

GA_Starts()

This will write the energies of the collection into the recording EnergyProfile text file.

add_collection(collection, generation_number)

This will add information about the collection to the EenrgyProfile.txt

Inputs:

collection (Organisms.GA.collection): This is the collection to be added to the EnergyProfile.txt, should be an Offspring_Pool. generation_number (int): This is the current generation number of the running Organisms program.

add_epoch_note()

Add a note to the energyprofile to say that an epoch event occurred at this point

add_epoch_note_due_to_population_energy_convergence()

Add a note to the energyprofile to say that an epoch event occurred at this point due to the energies in the cluster having converged.

add_found_LES_note()

Add a note to the energyprofile to say that the LES was located, such that your genetic algorithm will now finish.

add_to(cluster, generation_number)

This definition will add the information of a cluster. Designed to be used when offspring are created.

Inputs:

cluster (Organisms.GA.Cluster): This is the cluster to write information about in the EnergyProfile.txt generation_number (int): This is the current generation number of the running Organisms program.

check(resume_from_generation, no_offspring_per_generation)

Check the EnergyProfile to make sure it is all good to go. As well as if the LES has been located by the genetic algorthm, and to remove any information from the end of the EnergyProfile document that attains to future generations that the algorithm did not complete successfully.

Parameters:
  • resume_from_generation (int) – The generation that the algorithm is resuming from

  • no_offspring_per_generation (int) – The number of offspring generated per generation.

close()

This will close the EnergyProfile text file that is being recorded to.

This is designed to be a private definition

create()

This definition will create the folders and text files for

get_current_generation_and_last_cluster_generated_from_EnergyProfile()

Get the number of the last generation and the name of the last cluster that was recorded in the EnergyProfile

:returns The last recorded generation, and the name of the last recorded cluster. :rtype int, int

is_LES_note_in_EnergyProfile()

Look through the EnergyProfile if it exists for a note saying that the LES had be found.

:returns True if the EnergyProfile states the LES has been found, otherwise return False. :rtype bool.

open(read_type)

This will open the EnergyProfile text file that is being recorded to.

This is designed to be a private definition

Inputs:

read_type (str.): This is the way to open the file, either read (‘r’’), write (‘w’), or append (‘a’).

Organisms.GA.EnergyProfile.remove_end_lines_from_text(file, number_of_lines_to_remove)

This method removes the last number of lines from the document.

For more information, see: https://superuser.com/questions/127786/efficiently-remove-the-last-two-lines-of-an-extremely-large-text-file

Parameters:
  • file (str.) – This is the file path to the path you want to read the end of

  • number_of_lines_to_remove (int) – This is the number of lines to remove from the document.

Organisms.GA.EnergyProfile.tail(f, n, offset=0)

This method will read the last lines from a text file

Parameters:
  • f (str.) – This is the file path to the path you want to read the end of

  • n (int) – This is the last lines to read from the document.

  • offset (int) – This is an offset number of line that should at least have been read, but this can be kept as 0 and given in n. For the user to decide.

returns lines: These are the line to be read from the end of the document rtype lines: list of str.