The AHA Model
Revision: 12809
Reference implementation 04 (HEDG02_04)
|
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 |
THE_EVOLUTION Module implements the Genetic Algorithm for the AHA Model.
Definition in file m_evolut.f90.
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
.
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.
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.
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.
Agents are subjected to random habitat-specific mortality by calling the_population::population::mortality_habitat().
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.
The population-wise maximum motivation parameter commondata::global_rescale_maximum_motivation is updated based on the global maximum value.
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.
PREDATION_HAB_SAFE
block;Dangerous habitat: PREDATION_HAB_DANGER
block.
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_AGENTS
block.
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.
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.
|
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().
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.
"PREEVOL_STEPS" – lifespan, number of time steps;
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().
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.