The AHA Model  Revision: 12809
Reference implementation 04 (HEDG02_04)
m_evolut.f90 File Reference

THE_EVOLUTION Module implements the Genetic Algorithm for the AHA Model. More...

Go to the source code of this file.

Modules

module  the_evolution
 Implementation of the genetic algorithm.
 

Functions/Subroutines

subroutine the_evolution::init_environment_objects ()
 Initialise the environmental objects. Most of the environmental objects, such as the environment, habitats etc. are kept static throughout the model running. There are, however, patterned and stochastic changes in the environment, such as diurnal variation of the illumination level. More...
 
integer function, public the_evolution::preevol_steps_adaptive (generation)
 Calculate the adaptive number of time steps for the fixed fitness preevolution stage of the genetic algorithm. More...
 
subroutine, public the_evolution::preevol_steps_adaptive_save_csv (csv_file_name, is_success)
 This is a diagnostic subroutine to save the number of time steps for the adaptive GA. More...
 
subroutine the_evolution::generations_swap ()
 Swap generation pointers between parents and offspring. More...
 
subroutine the_evolution::selection ()
 Select reproducing agents, the best commondata::ga_reproduce_pr portion of agents. More...
 
subroutine the_evolution::mate_reproduce ()
 Mate, reproduce and mutate. More...
 
subroutine, public the_evolution::generations_loop_ga ()
 This procedure implements the main Genetic Algorithm for evolving the agents. More...
 
subroutine lifecycle_preevol (active_population)
 This subroutine implements the full life cycle in a whole population of agents. It is built around the main loop LIFECYCLE_PREEVOL_LOOP. More...
 
subroutine generation_stats_record_write ()
 Save generation-wise statistics. This procedure only writes a single record of data after each generation. Opening the file, definition of the file handling objects that are used here etc. are done in the upstream procedure the_evolution::generations_loop_ga(). More...
 

Variables

character(len= *), parameter, private the_evolution::modname = "(THE_EVOLUTION)"
 
type(timer_cpu), public the_evolution::stopwatch_global
 Model-global stopwatch objects. More...
 
type(timer_cpu), public the_evolution::stopwatch_generation
 
type(timer_cpu), public the_evolution::stopwatch_op_current
 
type(timer_cpu), public the_evolution::single
 
type(timer_cpu), public the_evolution::operation
 
type(habitat), public the_evolution::habitat_safe
 We have an environment composed of two habitats, safe and a dangerous. More...
 
type(habitat), public the_evolution::habitat_dangerous
 
type(population), target, public the_evolution::generation_one
 Here we create instances for two populations which will then serve as parents and offspring. And then we declare pointers that will point to parents and offspring. More...
 
type(population), target, public the_evolution::generation_two
 
type(population), pointer, public the_evolution::proto_parents
 
type(population), pointer, public the_evolution::proto_offspring
 

Detailed Description

THE_EVOLUTION Module implements the Genetic Algorithm for the AHA Model.

Author
Sergey Budaev serge.nosp@m.y.bu.nosp@m.daev@.nosp@m.uib..nosp@m.no
Jarl Giske jarl..nosp@m.gisk.nosp@m.e@uib.nosp@m..no
Date
2016-2017

Definition in file m_evolut.f90.

Function/Subroutine Documentation

◆ lifecycle_preevol()

subroutine generations_loop_ga::lifecycle_preevol ( class(population), intent(inout)  active_population)

This subroutine implements the full life cycle in a whole population of agents. It is built around the main loop LIFECYCLE_PREEVOL_LOOP.

Implementation details

First, the ages of all agents are reset to 0 before the cycle of their life (time steps of the model).

Second, each generation is subjected to selective birth mortality by the_population::population::mortality_birth() at birth, before the first time step.

Note
Forced mean and sd values from generation 1 data. Normally must be obtained from the first generation data, with global parameters added.

Then, calculate the number of time steps for the current generation. The number of time steps is based on the adaptive algorithm implemented in the the_evolution::preevol_steps_adaptive() function.

The arrays that keep time-step wise statistics for the current generation are allocated with the above number of time steps.

Some of these arrays are integer counts.

... and they also initialised to commondata::missing value (integer arrays to commondata::unknown).

Start the main life cycle loop LIFECYCLE_PREEVOL_LOOP over all the time steps (limited by the adaptive algorithm).

Reset/update the global commondata::global_time_step_model_current.

Prepare the environment

Perform the sinusoidal vertical migration of the food items, they are relocating to the depth appropriate for specific time step of the model. Food migration is done here with the the_environment::migrate_food_vertical() directly on the global array of habitats the_environment::global_habitats_available to avoid the need to synchronise the array with the habitat objects.

The average distance between the food items is reported to the log. The average distance between the food items is good to know, e.g. to compare it with the agent's random walk step size.

Habitat-specific mortality

Agents are subjected to random habitat-specific mortality by calling the_population::population::mortality_habitat().

Warning
Mortality is so far disabled.

Agents do a single time step of life

Perform a single step of the life cycle of the whole population of agents. The agents do this step of their life cycle in a random (or non-random) order. See the_population::population::lifecycle_step() for details.

Immediately after the time step is done, time step-wise statistics are calculated.

The habitat and food resource data are disassembled back into the original static habitat objects out of the global array the_environment::global_habitats_available. This transfers the changes in the food resources (e.g. the agents consume the food) from the global array back to the original static habitat objects. See the_environment::disassemble() procedure.

Now, the time-step-wise habitat statistics can be computed for the current time step.

Maximum rescale motivation updated

The population-wise maximum motivation parameter commondata::global_rescale_maximum_motivation is updated based on the global maximum value.

The agents are subjected to predation

It is implemented by cycling over all predators within the safe and dangerous habitat and calling the the_population::population::attacked() method for each predator.

  • Safe habitat: PREDATION_HAB_SAFE block;

Dangerous habitat: PREDATION_HAB_DANGER block.

Save all agent data

All agents data are saved to CSV file using the_population::population::save_csv() method. However, this is done only if the parameter commondata::enable_save_agents_each_timestep is set to TRUE. This is implemented in the SAVE_ALL_AGENTSblock.

Additionally, the previous and the latest behaviour of the agent is also saved for each time step.

If commondata::is_zip_outputs is TRUE, CSV output data file is compressed using commondata::cmd_zip_output.

Save time-step-wise data

After the life cycle loop is completed, time-step-wise statistics are saved into CSV data file for the current generation.

The CSV output data file can be optionally compressed with the commondata::cmd_zip_output command if commondata::is_zip_outputs is set to TRUE.

Definition at line 1053 of file m_evolut.f90.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generation_stats_record_write()

subroutine generations_loop_ga::generation_stats_record_write
private

Save generation-wise statistics. This procedure only writes a single record of data after each generation. Opening the file, definition of the file handling objects that are used here etc. are done in the upstream procedure the_evolution::generations_loop_ga().

Warning
This subroutine neither opens nor closes the output CSV file, only writes a single record of statistical data from the current generation commondata::global_generation_number_current into it.

Implementation notes

First, initialise an empty record for CSV data.

Then calculate and append each of the statistical data fields to build the complete record of the CSV output file. Note that the fields must agree with the columns defined by the FILE_STATS_GENER_COLS parameter array.

  • "GENERATION" – generation number;

"PREEVOL_STEPS" – lifespan, number of time steps;

  • "MUTAT_POINT" – adaptive rate of point mutations;
  • "MUTAT_BATCH" – adaptive rate of batch mutations;
  • "ELITE_GROUP" – the number of reproducing agents;
  • "N_ALIVE" – number of agents alive at the end;
  • "N_GROWN" – number of agents that had grown;
  • "N_MALES_L" – number of males alive;
  • "N_FEMALES_L" number of females alive;
  • "N_EATEN_PRED" number of agents that are eaten by predators;
  • "BODY_MASS" – average body mass;
  • "BODY_LEN" – average body length;
  • "BIRTH_MASS" – body mass at birth;
  • "BIRTH_LENGTH" – body length at birth;
  • "BIRTH_ENERGY" – energy reserves at birth;
  • "ENERGY" – energy reserve;
  • "STOMACH" – stomach contents, mass;
  • "SMR" – average SMR;
  • "CTRL_RND" – average control trait;
  • "REPRFACT" – average reproductive factor;
  • "P_REPR" – probability of reproduction;
  • "N_REPROD" – total nuber or reproductions;
  • "N_OFFSPRING" – number of offspring;
  • "GOS_AROUSAL" – GOS arousal;
  • "FOODS_TRY" – average number of attempts to catch food items;
  • "FOODS_EATEN" – average number of food items eaten;
  • "FMASS_EATEN" – average number of food items eaten;
  • "PERC_FOOD" – food perception, average;
  • "PERC_CONS" – conspecific perception, average;
  • "PERC_PRED" – predator perception, average;
  • "DEPTH" – location depth at the end,
  • "N_SAFE_HABITAT" – number of agents in the "safe" habitat;
  • "N_DANG_HABITAT" – number of agents in the "dangerous" habitat.
  • Calculate perception averages in the safe habitat:
  • "PERC_FOOD_SAFE" – food perception in "safe" habitat;
  • "PRC_FDIST_SAFE" – food perception in "safe" habitat;
  • "PERC_CONS_SAFE" – conspecific perception in "dangerous" habitat;
  • "PERC_PRED_SAFE" – predator perception in "safe" habitat;
  • Calculate perception averages in the dangerous habitat:
  • "PERC_FOOD_DANG" – food perception in "dangerous" habitat;
  • "PRC_FDIST_DANG" – food perception in "dangerous" habitat;
  • "PERC_CONS_DANG" – conspecific perception in "dangerous" habitat;
  • "PERC_PRED_DANG" – predator perception in "dangerous" habitat;
  • "FDIST_SAFE" – average distance between food items in the safe habitat;
  • "FDIST_DANGER" - average distance between food items in the dangerous habitat;
  • "FITNESS_MIN" – minimum fitness value.
  • "FITNESS_MEAN" – average fitness.
  • "N_FOODS_SAFE" – number of food items available in "safe" habitat;
  • "N_FOODS_DANG" – number of food items available in "dangerous" habitat.

The following characteristics are calculated for alive agents.

Here the ALIVE block implements sorting out the individuals that are the_genome:individual_genome::is_alive().

  • "BODY_MASS_L" – average body mass of alive agents;
  • "BODY_LENGTH_L" – average body length of alive agents;
  • "ENERGY_L" – average energy reserves of alive agents;
  • "SMR_L" – average SMR of alive agents;
  • "CONTROL_L" – control trait of alive agents;
  • "REPRFACT_L" – reproductive factor of alive agents;
  • "P_REPROD_L" – probability of reproduction of alive agents;
  • "FOODS_TRY_L" – average rate of attempts to catch food items by alive agents;
  • "FOODS_EATEN_L" – average rate of successful food captures;
  • "FMASS_EATEN_L" – average rate of successful food captures;
  • "N_SAFE_HAB_L" – number of alive agents in "safe" habitats;
  • "N_DANG_HAB_L" – number of alive agents in "dangerous" habitat;
  • "FITNESS_MEAN_L" – mean fitness of alive agents.

Once the record is fully built, it is written to the file using the CSV_RECORD_WRITE procedure (see CSV_IO).

Definition at line 1425 of file m_evolut.f90.

Here is the call graph for this function:
Here is the caller graph for this function: