25 character (len=*),
parameter,
private ::
modname =
"(THE_POPULATION)"
37 integer :: person_number
60 integer :: population_size
72 character (len=LABEL_LENGTH) :: pop_name
145 procedure,
public :: mortality_individ => &
162 procedure,
public :: ga_mutat_adaptive => &
172 procedure,
public :: lifecycle_eatonly => &
195 integer,
intent(in) :: idnumber
197 this%person_number = idnumber
211 idnumber = this%person_number
227 class(environment),
intent(in) :: environ
231 environ%depth_min(), &
232 environ%depth_max() ) ) )
234 call this%position( &
238 environ%depth_min(), &
239 environ%depth_max() ) ) )
241 call this%position( environ%uniform() )
263 logical,
optional,
intent(in) :: non_debug_log
266 logical :: do_show_log
269 integer,
parameter :: HIST_N=10
271 do_show_log = .
false.
280 if (
present(non_debug_log))
then
281 if (non_debug_log) do_show_log = .
true.
285 if (.not. do_show_log)
return
287 call log_msg(
"Agent # " // tostr(this%get_id()) //
" with name " // &
288 trim(this%individ_label()) //
" dies." )
289 call log_msg(
"Agent properties: " )
290 call log_msg(
" body mass: " // tostr(this%get_mass()) // &
291 ", body mass at birth: " // tostr(this%body_mass_birth) // &
292 ", max body mass: " // tostr(this%body_mass_maximum) // &
293 ", body length: " // tostr(this%get_length()) // &
294 ", energy reserves: " // tostr(this%get_energy()) // &
295 ", SMR: " // tostr(this%get_smr()) // &
296 ", stomach content: " // tostr(this%get_stom_content()) )
297 call log_msg(
" Latest body mass (" // tostr(hist_n) //
") history: " // &
298 tostr(this%body_mass_history( &
300 call log_msg(
" Latest body length (" // tostr(hist_n) //
") history: " &
301 // tostr(this%body_length_history( &
303 call log_msg(
"Agent's GOS is " // this%gos_label() // &
304 ", arousal: " // tostr(this%arousal()) //
"." )
307 call log_msg(
" Latest GOS states: " // &
308 tostr(this%memory_motivations%gos_main( &
324 integer,
intent(in) :: pop_size
326 integer,
optional,
intent(in) :: pop_number_here
328 character (len=*),
optional,
intent(in) :: pop_name_here
334 character(len=*),
parameter :: PROCNAME =
"(init_population_random)"
337 this%population_size = pop_size
340 if (.not.
allocated(this%individual)) &
341 allocate(this%individual(this%population_size))
344 do i=1, this%population_size
346 call this%individual(i)%init()
348 call this%individual(i)%set_id(i)
353 if (
present(pop_number_here))
then
354 this%pop_number = pop_number_here
358 this%pop_number = rand_i(1,huge(this%pop_number-1))
360 if (
present(pop_name_here))
then
361 this%pop_name = pop_name_here
365 this%pop_name = tostr(this%pop_number)
368 call log_msg(
ltag_info //
"Initialised population " // this%pop_name // &
369 " # " // tostr(this%pop_number) //
" with " // &
370 tostr(this%population_size) //
" agents." )
376 call log_msg(
ltag_info //
"Initial location is FIXED at " // &
379 call log_msg(
ltag_info //
"Initial location is GAUSSIAN at " // &
383 call log_msg(
ltag_info //
"Initial location is fully uniform." )
394 this%population_size = 0
397 if (
allocated(this%individual))
deallocate(this%individual)
415 real(SRP),
optional,
intent(in) :: energy_mean
418 real(SRP),
optional,
intent(in) :: energy_sd
421 real(SRP) :: energy_mean_loc, energy_sd_loc
423 real(SRP) :: mortality
432 real(SRP),
parameter,
dimension(*) :: MORTALITY_BIRTH_INIT_ENERG_ABSCISSA &
433 = [ 0.7_srp, 1.0_srp, 1.5_srp, 2.0_srp, 3.0_srp ]
441 real(SRP),
parameter,
dimension(*) :: MORTALITY_BIRTH_INIT_ENERG_ORDINATE &
442 = [ 0.0_srp, 0.002_srp, 0.01_srp, 0.1_srp, 1.0_srp ]
444 if (
present(energy_mean))
then
445 energy_mean_loc = energy_mean
447 energy_mean_loc =
average( this%individual%get_energ_birth() )
450 if (
present(energy_sd))
then
451 energy_sd_loc = energy_sd
453 energy_sd_loc =
std_dev( this%individual%get_energ_birth() )
456 inds:
do ind=1, this%population_size
475 mortality =
within(ddpinterpol(energy_mean_loc + &
476 mortality_birth_init_energ_abscissa * &
478 mortality_birth_init_energ_ordinate, &
479 this%individual(ind)%get_energ_birth()), &
488 grid_xx=energy_mean_loc + mortality_birth_init_energ_abscissa * &
490 grid_yy=mortality_birth_init_energ_ordinate, &
491 ipol_value=this%individual(ind)%get_energ_birth(), &
492 algstr=
"DDPINTERPOL", &
493 output_file=
"plot_debug_mortality_birth_" // &
497 trim(this%individual(ind)%individ_label()) // &
501 if ( rand_r4() < mortality )
then
502 call this%individual(ind)%dies()
512 integer :: pop_size_output
514 pop_size_output = this%population_size
522 integer :: pop_number_output
524 pop_number_output = this%pop_number
532 character(len=LABEL_LENGTH) :: pop_name_string_out
534 pop_name_string_out = this%pop_name
546 integer,
optional,
intent(in) :: pop_number_here
548 character (len=*),
optional,
intent(in) :: pop_name_here
554 do i=1, this%population_size
555 call this%individual(i)%set_id(i)
560 if (
present(pop_number_here))
then
561 this%pop_number = pop_number_here
565 this%pop_number = rand_i(1,huge(this%pop_number-1))
567 if (
present(pop_name_here))
then
568 this%pop_name = pop_name_here
572 this%pop_name = tostr(this%pop_number)
584 do i=1, this%population_size
585 call this%individual(i)%sex_init()
605 class(environment),
optional,
intent(in) :: environ
608 type(environment) :: environ_here
617 if (
present(environ))
then
618 call environ_here%build( environ%lim_min(), environ%lim_max() )
620 call environ_here%build_unlimited()
625 do i=1, this%population_size
626 call this%individual(i)%place_uniform(environ_here)
641 call qsort(this%individual)
652 recursive pure subroutine qsort(A, is_reverse)
658 logical,
optional,
intent(in) :: is_reverse
668 if (
present(is_reverse))
then
669 if (is_reverse) a = a(
size(a):1:-1 )
679 integer,
intent(out) :: marker
696 if (a(j)%fitness <= x)
exit
701 if (a(i)%fitness >= x)
exit
727 environment_limits, n_walks )
731 real(SRP),
optional,
dimension(:),
intent(in) :: dist_array
733 real(SRP),
optional,
dimension(:),
intent(in) :: cv_array
736 real(SRP),
optional,
intent(in) :: dist_all
739 real(SRP),
optional,
intent(in) :: cv_all
745 class(environment),
intent(in),
optional :: environment_limits
749 integer,
optional,
intent(in) :: n_walks
752 real(SRP),
dimension(this%population_size) :: dist_array_here, cv_array_here
753 integer :: n_walks_here
756 real(SRP),
dimension(this%population_size) :: step_size_walk
757 integer :: j, i, ind, pop_n
758 integer,
dimension(this%population_size) :: pop_permutation
761 real(SRP),
parameter :: CV_DEFAULT = 0.5_srp
765 pop_n = this%population_size
767 if (
present(dist_array))
then
768 dist_array_here = dist_array
770 dist_array_here = this%individual%get_length()
773 if (
present(cv_array))
then
774 cv_array_here = cv_array
776 cv_array_here = cv_default
779 if (
present(dist_all))
then
780 dist_array_here = dist_all
782 dist_array_here = this%individual%get_length()
785 if (
present(cv_all))
then
786 cv_array_here = cv_all
788 cv_array_here = cv_default
791 if (
present(n_walks))
then
792 n_walks_here = n_walks
798 step_size_walk = dist2step(dist_array_here)
803 pop_permutation = permute_random(pop_n)
808 environ_restrict:
if (
present(environment_limits))
then
811 ind = pop_permutation(i)
812 if (this%individual(ind)%is_alive()) &
813 call this%individual(ind)%rwalk( step_size_walk(ind), &
814 cv_array_here(ind), &
818 else environ_restrict
821 ind = pop_permutation(i)
822 if (this%individual(ind)%is_alive()) &
823 call this%individual(ind)%rwalk( &
824 step_size_walk(ind), &
825 cv_array_here(ind), &
826 global_habitats_available( &
827 this%individual(ind)%find_environment( &
828 global_habitats_available) ) )
831 end if environ_restrict
839 dist_array_xy, cv_array_xy, &
840 dist_array_depth, cv_array_depth, &
841 dist_all_xy, cv_all_xy, &
842 dist_all_depth, cv_all_depth, &
843 environment_limits, n_walks )
847 real(SRP),
optional,
dimension(:),
intent(in) :: dist_array_xy
849 real(SRP),
optional,
dimension(:),
intent(in) :: cv_array_xy
852 real(SRP),
optional,
dimension(:),
intent(in) :: dist_array_depth
854 real(SRP),
optional,
dimension(:),
intent(in) :: cv_array_depth
858 real(SRP),
optional,
intent(in) :: dist_all_xy
862 real(SRP),
optional,
intent(in) :: cv_all_xy
866 real(SRP),
optional,
intent(in) :: dist_all_depth
870 real(SRP),
optional,
intent(in) :: cv_all_depth
876 class(environment),
intent(in),
optional :: environment_limits
879 integer,
optional,
intent(in) :: n_walks
882 real(SRP),
dimension(this%population_size) :: &
883 dist_array_xy_here, cv_array_xy_here
884 real(SRP),
dimension(this%population_size) :: &
885 dist_array_depth_here, cv_array_depth_here
886 integer :: n_walks_here
889 real(SRP),
dimension(this%population_size) :: step_size_walk_xy, &
891 integer :: j, i, ind, pop_n
892 integer,
dimension(this%population_size) :: pop_permutation
895 real(SRP),
parameter :: CV_DEFAULT = 0.5_srp
899 pop_n = this%population_size
901 if (
present(dist_array_xy))
then
902 dist_array_xy_here = dist_array_xy
904 dist_array_xy_here = this%individual%get_length()
907 if (
present(cv_array_xy))
then
908 cv_array_xy_here = cv_array_xy
910 cv_array_xy_here = cv_default
917 if (
present(dist_array_depth))
then
918 dist_array_depth_here = dist_array_depth
920 dist_array_depth_here = this%individual%get_length() / 2.0_srp
923 if (
present(cv_array_depth))
then
924 cv_array_depth_here = cv_array_depth
926 cv_array_depth_here = cv_default
929 if (
present(dist_all_xy))
then
930 dist_array_xy_here = dist_all_xy
932 dist_array_xy_here = this%individual%get_length()
935 if (
present(cv_all_xy))
then
936 cv_array_xy_here = cv_all_xy
938 cv_array_xy_here = cv_default
941 if (
present(dist_all_depth))
then
942 dist_array_depth_here = dist_all_depth
944 dist_array_depth_here = this%individual%get_length() / 2.0_srp
947 if (
present(cv_all_depth))
then
948 cv_array_depth_here = cv_all_depth
950 cv_array_depth_here = cv_default
953 if (
present(n_walks))
then
954 n_walks_here = n_walks
960 step_size_walk_xy = dist2step(dist_array_xy_here)
961 step_size_walk_depth = dist2step(dist_array_depth_here)
966 pop_permutation = permute_random(pop_n)
971 environ_restrict:
if (
present(environment_limits))
then
974 ind = pop_permutation(i)
975 if (this%individual(ind)%is_alive()) &
976 call this%individual(ind)%rwalk25d &
977 ( meanshift_xy = step_size_walk_xy(ind), &
978 cv_shift_xy = cv_array_xy_here(ind), &
979 meanshift_depth = step_size_walk_depth(ind), &
980 cv_shift_depth = cv_array_depth_here(ind), &
981 environment_limits = environment_limits )
984 else environ_restrict
987 ind = pop_permutation(i)
988 if (this%individual(ind)%is_alive()) &
989 call this%individual(ind)%rwalk25d &
990 ( meanshift_xy = step_size_walk_xy(ind), &
991 cv_shift_xy = cv_array_xy_here(ind), &
992 meanshift_depth = step_size_walk_depth(ind), &
993 cv_shift_depth = cv_array_depth_here(ind), &
994 environment_limits=global_habitats_available( &
995 this%individual(ind)%find_environment( &
996 global_habitats_available) ) )
999 end if environ_restrict
1011 class(predator),
intent(in) :: this_predator
1012 integer,
optional,
intent(in) :: time_step_model
1015 integer :: time_step_model_here
1021 real(SRP),
dimension(size(this%individual)) :: p_risk
1026 integer,
dimension(size(this%individual)) :: prey_index
1036 type(spatial),
dimension(size(this%individual)) :: tmp_location
1042 character(len=*),
parameter :: PROCNAME = &
1043 "(population_subject_predator_attack)"
1048 if (
present(time_step_model))
then
1049 time_step_model_here = time_step_model
1061 tmp_location = this%individual%location()
1062 call this_predator%risk_fish_group( &
1063 prey_spatial = tmp_location, &
1064 prey_length = this%individual%get_length(), &
1065 is_freezing = this%individual%freeze%is_executed(), &
1066 time_step_model = time_step_model_here, &
1067 risk_indexed = p_risk, &
1068 index_dist = prey_index )
1078 if ( this%individual(prey_index(i))%is_alive() )
then
1079 if ( rand_r4() < p_risk(i) )
then
1082 call this%individual(prey_index(i))%dies()
1084 " (" // tostr(i) //
")" // &
1085 " is caught by the predator and dies.", &
1088 tostr(this%individual(prey_index(i))%is_alive()) )
1113 character(len=*),
parameter :: PROCNAME =
"(population_subject_other_risks)"
1119 do i=1, this%population_size
1120 agent_in = this%individual(i)%find_environment()
1121 if (rand_r4() < global_habitats_available(agent_in)%get_mortality())
then
1124 call this%individual(i)%dies()
1126 tostr(this%individual(i)%get_id()) //
" dies due to " // &
1127 "habitat linked mortality risk " // &
1128 tostr(global_habitats_available(agent_in)%get_mortality()), &
1148 do i=1, this%population_size
1149 if ( rand_r4() < this%individual(i)%get_mortality() ) &
1150 call this%individual(i)%dies()
1164 integer,
dimension(this%population_size) :: inds_order
1181 character(len=*),
parameter :: PROCNAME = &
1182 "(population_lifecycle_step_preevol)"
1191 inds_order = permute_random(this%population_size)
1213 individuals:
do ind_seq = 1,
popsize
1216 ind_real = inds_order(ind_seq)
1218 associate( agent => this%individual(ind_real) )
1224 if (agent%is_dead())
then
1227 if (agent%starved_death())
then
1235 agent_in = agent%find_environment()
1236 if (agent_in<1 .or. agent_in>
size(global_habitats_available) )
then
1237 call log_msg(
ltag_error //
"agent_in zero in " // procname // &
1238 tostr([agent%xpos(),agent%ypos(),agent%dpos()]) )
1239 call log_msg(
ltag_error //
"Agent: " // tostr(ind_real) // &
1240 " in " // tostr(ind_seq) )
1247 call agent%perceptions_inner()
1251 call agent%perceptions_environ()
1259 call agent%see_food( global_habitats_available( agent_in )%food )
1260 call agent%see_consp( this%individual )
1261 call agent%see_pred( global_habitats_available( agent_in )%predators )
1266 call agent%perception_to_memory()
1272 call agent%motivations_percept_components()
1275 call agent%motivations_primary_calc()
1278 call agent%modulation()
1283 call agent%motivations_to_memory()
1288 call agent%gos_find()
1290 ", GOS is: " // agent%gos_label() // &
1291 ", GOS arousal :" // tostr(agent%arousal()), &
1297 maxval( this%individual%motivations%max_perception() )
1306 call agent%do_behave( &
1309 " executed behaviour: " // agent%behaviour_is() // &
1310 " (at global time_step " // &
1329 call agent%sex_steroids_update()
1330 call agent%subtract_living_cost()
1331 call agent%stomach_empify()
1332 call agent%energy_update()
1335 call agent%age_increment()
1340 if (agent%starved_death())
then
1362 integer,
dimension(this%population_size) :: inds_order
1379 integer :: food_item_selected
1382 character(len=*),
parameter :: PROCNAME = &
1383 "(population_lifecycle_step_eatonly_preevol)"
1392 inds_order = permute_random(this%population_size)
1414 individuals:
do ind_seq = 1, popsize
1417 ind_real = inds_order(ind_seq)
1419 associate( agent => this%individual(ind_real) )
1425 if (agent%is_dead())
then
1428 if (agent%starved_death())
then
1436 agent_in = agent%find_environment()
1437 if (agent_in<1 .or. agent_in>
size(global_habitats_available) )
then
1438 call log_msg( ltag_error //
"agent_in zero in " // procname // &
1439 tostr([agent%xpos(),agent%ypos(),agent%dpos()]) )
1440 call log_msg( ltag_error //
"Agent: " // tostr(ind_real) // &
1441 " in " // tostr(ind_seq) )
1448 call agent%perceptions_inner()
1452 call agent%perceptions_environ()
1460 call agent%see_food( global_habitats_available( agent_in )%food )
1461 call agent%see_consp( this%individual )
1462 call agent%see_pred( global_habitats_available( agent_in )%predators )
1467 call agent%perception_to_memory()
1473 call agent%motivations_percept_components()
1476 call agent%motivations_primary_calc()
1479 call agent%modulation()
1484 call agent%motivations_to_memory()
1489 call agent%gos_find()
1490 call log_dbg( ltag_info //
"Agent " // tostr(agent%get_id()) // &
1491 ", GOS is: " // agent%gos_label() // &
1492 ", GOS arousal :" // tostr(agent%arousal()), &
1497 global_rescale_maximum_motivation = &
1498 maxval( this%individual%motivations%max_perception() )
1506 do_behave:
if ( agent%has_food() )
then
1507 food_item_selected = agent%food_item_select( &
1508 rescale_max_motivation=global_rescale_maximum_motivation)
1510 call agent%do_eat_food_item( &
1511 food_item_selected, global_habitats_available( agent_in )%food )
1513 call agent%do_walk()
1516 call log_dbg( ltag_info //
"Agent " // tostr(agent%get_id()) // &
1517 " executed behaviour: " // agent%behaviour_is() // &
1518 " (at global time_step " // &
1519 tostr(global_time_step_model_current) // &
1531 call agent%sex_steroids_update()
1532 call agent%subtract_living_cost()
1533 call agent%energy_update()
1536 call agent%age_increment()
1541 if (agent%starved_death())
then
1555 save_header, is_logging, is_success)
1559 character(len=*),
intent(in) :: csv_file_name
1563 logical,
optional,
intent(in) :: save_header
1567 logical,
optional,
intent(in) :: is_logging
1570 logical,
optional,
intent(out) :: is_success
1573 logical :: logging_enabled
1582 type(csv_file) :: handle_csv
1585 character(len=:),
allocatable :: csv_record_tmp
1590 character(len=LABEL_LENGTH),
dimension(*), &
1591 parameter :: COLUMNS = [ character(len=label_length) :: &
1638 character(len=*),
parameter :: &
1639 PROCNAME =
"(population_save_data_all_agents_csv)"
1643 character(len=LABEL_LENGTH) :: habitat_in
1646 type(timer_cpu) :: file_write_timing
1648 if (
present(is_logging))
then
1649 logging_enabled = is_logging
1651 logging_enabled = is_debug
1654 if (logging_enabled)
then
1655 call log_msg (ltag_info //
"Saving all individuals in population # " // &
1656 tostr(this%pop_number) //
" (name '" // trim(this%pop_name) // &
1658 "generation # " // tostr(global_generation_number_current) // &
1659 ", time step " // tostr(global_time_step_model_current) // &
1660 " to file: " // csv_file_name )
1661 call file_write_timing%start( &
1662 "Writing population data for population '" // &
1663 trim(this%pop_name) //
"' " // tostr(
size(this%individual)) &
1673 handle_csv%name = csv_file_name
1676 call csv_open_write( handle_csv )
1681 if ( .not. handle_csv%status )
then
1682 call log_msg( ltag_error //
"Opening output CSV file FAILED: " // &
1683 csv_file_name //
", in " // procname )
1684 call log_msg( ltag_error //
"Data file " // csv_file_name // &
1685 " is not written in " // procname )
1686 if (
present(is_success)) is_success = handle_csv%status
1691 if (
present(save_header))
then
1692 if (save_header)
then
1693 call csv_header_write(
"Population: " // this%pop_name, handle_csv )
1694 if ( .not. handle_csv%status )
then
1695 if (
present(is_success)) is_success = .false.
1696 call csv_close( handle_csv )
1706 csv_record_tmp = repeat(
" ",
size(columns) * len(columns(1)) )
1713 call csv_record_append( csv_record_tmp, columns )
1714 call csv_record_write ( csv_record_tmp, handle_csv )
1715 if ( .not. handle_csv%status )
then
1716 if (
present(is_success)) is_success = .false.
1717 call csv_close( handle_csv )
1725 do ind = 1,
size(this%individual)
1728 csv_record_tmp = repeat(
" ", &
1729 max( csv_guess_record_length(
size(columns) + 1,0.0_srp),&
1730 len(this%individual(ind)%genome_label) ) )
1735 associate( agent => this%individual(ind) )
1736 call csv_record_append(csv_record_tmp,agent%person_number )
1737 call csv_record_append(csv_record_tmp,agent%genome_label )
1738 call csv_record_append(csv_record_tmp,conv_l2r(agent%alive) )
1739 call csv_record_append(csv_record_tmp,conv_l2r(agent%sex_is_male))
1740 call csv_record_append(csv_record_tmp,agent%body_length )
1741 call csv_record_append(csv_record_tmp,agent%body_length_birth )
1742 call csv_record_append(csv_record_tmp,agent%control_unselected )
1743 call csv_record_append(csv_record_tmp,agent%body_mass )
1744 call csv_record_append(csv_record_tmp,agent%body_mass_birth )
1745 call csv_record_append(csv_record_tmp,agent%energy_current )
1746 call csv_record_append(csv_record_tmp,agent%energy_birth )
1747 call csv_record_append(csv_record_tmp,agent%stomach_content_mass )
1748 call csv_record_append(csv_record_tmp,agent%maxstomcap )
1749 call csv_record_append(csv_record_tmp,agent%smr )
1750 call csv_record_append(csv_record_tmp,agent%cost_swim_std() )
1751 call csv_record_append(csv_record_tmp,agent%living_cost() )
1752 call csv_record_append(csv_record_tmp,agent%ind_mortality )
1753 call csv_record_append(csv_record_tmp,agent%growhorm_level )
1754 call csv_record_append(csv_record_tmp,agent%thyroid_level )
1755 call csv_record_append(csv_record_tmp,agent%adrenaline_level )
1756 call csv_record_append(csv_record_tmp,agent%cortisol_level )
1757 call csv_record_append(csv_record_tmp,agent%testosterone_level )
1758 call csv_record_append(csv_record_tmp,agent%estrogen_level )
1759 call csv_record_append(csv_record_tmp,agent%testosterone_baseline)
1760 call csv_record_append(csv_record_tmp,agent%estrogen_baseline )
1761 if ( agent%is_male() )
then
1762 call csv_record_append(csv_record_tmp,agent%testosterone_level )
1764 call csv_record_append(csv_record_tmp,agent%estrogen_baseline )
1766 call csv_record_append(csv_record_tmp, &
1767 agent%probability_reproduction() )
1768 call csv_record_append(csv_record_tmp,agent%n_reproductions )
1769 call csv_record_append(csv_record_tmp,agent%n_offspring )
1770 call csv_record_append(csv_record_tmp,agent%age )
1771 call csv_record_append(csv_record_tmp,agent%gos_main )
1772 call csv_record_append(csv_record_tmp,agent%gos_arousal )
1773 call csv_record_append(csv_record_tmp,agent%gos_repeated )
1774 call csv_record_append(csv_record_tmp,agent%n_eats_all_indicator )
1775 call csv_record_append(csv_record_tmp,agent%n_eaten_indicator )
1776 call csv_record_append(csv_record_tmp,agent%mass_eaten_indicator )
1777 call csv_record_append(csv_record_tmp, &
1778 agent%memory_stack%get_food_mean_n() )
1779 call csv_record_append(csv_record_tmp, &
1780 agent%memory_stack%get_consp_mean_n() )
1781 call csv_record_append(csv_record_tmp, &
1782 agent%memory_stack%get_pred_mean() )
1783 call csv_record_append(csv_record_tmp,agent%x )
1784 call csv_record_append(csv_record_tmp,agent%y )
1785 call csv_record_append(csv_record_tmp,agent%depth )
1786 if ( agent%is_alive() )
then
1787 habitat_in = global_habitats_available( &
1788 agent%find_environment())%get_label()
1792 habitat_in =
"agent_dead"
1794 call csv_record_append(csv_record_tmp,habitat_in )
1795 call csv_record_append(csv_record_tmp,agent%fitness )
1802 call csv_record_write( csv_record_tmp, handle_csv )
1803 if ( .not. handle_csv%status )
then
1804 if (
present(is_success)) is_success = .false.
1805 call csv_close( handle_csv )
1813 call csv_close( handle_csv )
1817 if (logging_enabled)
then
1818 call log_msg (ltag_info //
"Individual data saved, population size " // &
1819 tostr(this%population_size) // &
1820 ", number of columns " // tostr(
size(columns)) )
1821 if ( .not. handle_csv%status )
call log_msg( ltag_error // &
1822 "File write operation FAILED." )
1823 call log_msg( file_write_timing%log() )
1826 if (
present(is_success)) is_success = handle_csv%status
1831 if ( is_zip_outputs )
then
1832 call call_external(command=cmd_zip_output //
" " // csv_file_name, &
1833 suppress_output=.true., &
1834 is_background_task=zip_outputs_background )
1846 character(len=*),
intent(in) :: csv_file_name
1849 logical,
optional,
intent(out) :: is_success
1852 integer :: i, j, k, l, m
1860 character(len=*),
parameter :: TAG_CRO =
"CRO_"
1861 character(len=*),
parameter :: TAG_GAP =
"_"
1862 character(len=*),
parameter :: TAG_ALE =
"_ALE_"
1863 character(len=*),
parameter :: TAG_ACO =
"_AC_"
1867 integer,
parameter :: DIG_LEN = 2
1870 integer,
parameter :: COL_LEN = len(tag_cro) + dig_len + &
1871 len(tag_gap) + dig_len + &
1872 len(tag_ale) + dig_len + &
1873 len(tag_aco) + dig_len
1876 character(len=COL_LEN),
allocatable,
dimension(:) :: colname
1879 integer :: n_columns
1882 character(len=:),
allocatable :: record_csv
1891 integer :: record_csv_max_length
1892 integer :: allele_val_append
1902 do j=1, n_chromosomes
1903 do k=1, chromosome_ploidy
1904 do l=1, len_chromosomes(j)
1905 do m=1, additive_comps
1906 n_columns = n_columns + 1
1913 allocate(colname(n_columns))
1920 do j=1, n_chromosomes
1921 do k=1, chromosome_ploidy
1922 do l=1, len_chromosomes(j)
1923 do m=1, additive_comps
1925 colname(i) = tag_cro // tostr(j) // &
1926 tag_gap // tostr(k) // &
1927 tag_ale // tostr(l,10) // &
1937 call genome_file%open_write( csv_file_name,
format_csv )
1938 if ( .not. genome_file%is_success() )
then
1939 if (
present(is_success)) is_success = .false.
1940 call genome_file%close()
1948 record_csv = repeat(
" ", label_length * 2 + 2 * 3 + &
1949 col_len * n_columns + n_columns * 3 )
1954 call csv_record_append( record_csv, &
1955 [
character(len=LABEL_LENGTH) ::
"ID_NUM",
"AGENT_NAME"] )
1960 call csv_record_append( record_csv, colname )
1964 call genome_file%record_write( record_csv )
1965 if ( .not. genome_file%is_success() )
then
1966 if (
present(is_success)) is_success = .false.
1967 call genome_file%close()
1975 record_csv_max_length = label_length * 2 + 2 * 3 + &
1976 len(tostr(allelerange_max)) * n_columns + &
1988 inds:
do i = 1, this%population_size
1990 record_csv = repeat(
" ", record_csv_max_length )
1992 call csv_record_append( record_csv, this%individual(i)%person_number )
1993 call csv_record_append( record_csv, this%individual(i)%genome_label )
1995 genome:
do j=1, n_chromosomes
1996 do k=1, chromosome_ploidy
1997 do l=1, len_chromosomes(j)
1998 do m=1, additive_comps
1999 allele_val_append = this%individual(i)% &
2000 chromosome(j,k)%allele(l)%allele_value(m)
2001 call csv_record_append( record_csv, allele_val_append )
2006 call genome_file%record_write( record_csv )
2007 if ( .not. genome_file%is_success() )
then
2008 if (
present(is_success)) is_success = .false.
2009 call genome_file%close()
2016 call genome_file%close()
2017 if ( .not. genome_file%is_success() )
then
2018 if (
present(is_success)) is_success = .false.
2020 if (
present(is_success)) is_success = .true.
2026 if ( is_zip_outputs )
then
2027 call call_external(command=cmd_zip_output //
" " // csv_file_name, &
2028 suppress_output=.true., &
2029 is_background_task=zip_outputs_background )
2041 pop_number_here, pop_name_here, csv_file_name, missing_random, is_success )
2044 use base_strings,
only : value, parse, split, compact, is_numeric, delall
2048 integer,
intent(in) :: pop_size
2050 integer,
optional,
intent(in) :: pop_number_here
2052 character (len=*),
optional,
intent(in) :: pop_name_here
2054 character(len=*),
intent(in) :: csv_file_name
2059 logical,
optional,
intent(in) :: missing_random
2062 logical,
optional,
intent(out) :: is_success
2065 integer :: pop_number_here_loc
2066 character (len=:),
allocatable :: pop_name_here_loc
2067 logical :: missing_random_loc
2070 character(len=*),
parameter :: &
2071 PROCNAME =
"(population_load_data_all_genomes)"
2075 type(csv_file) :: handle_csv
2079 character(len=:),
allocatable :: line_data_buff
2083 integer :: n_rows_in
2088 integer,
parameter :: N_ROWS_MIN = 10
2092 integer,
parameter :: MIN_FILE_INP_LEN = label_length + &
2093 n_chromosomes * chromosome_ploidy * 2 * additive_comps * 2
2096 logical :: success_flag, is_new_population, is_pop_id_reset
2099 character,
parameter :: TAB =achar(9)
2100 character,
parameter :: DQT =achar(34)
2101 character,
parameter :: SQT =achar(39)
2102 character(len=*),
parameter :: SDELIM =
" ," // tab
2106 integer,
parameter :: LEN_CSV_FIELD = label_length * 2
2108 integer,
parameter :: MIN_FIELD = 1
2112 character(len=LEN_CSV_FIELD),
dimension(:),
allocatable :: &
2113 line_data_substrings
2116 integer :: icase, nvars, jfield, ivalue, error_iflag, &
2117 line_data_buff_length, line_data_nflds, n_ignored_lns
2120 integer :: i, j, k, l, m
2124 integer,
allocatable,
dimension(:) :: matrix_row
2129 call log_delimiter(log_level_chapter)
2130 call log_msg( ltag_stage //
"Reading genome data from file " // &
2131 csv_file_name //
", file rows less than " // &
2132 tostr(min_file_inp_len) //
" ignored." )
2134 missing_random_loc = .false.
2135 if (
present(missing_random))
then
2136 if (missing_random .eqv. .true. )
then
2137 missing_random_loc = .true.
2146 n_rows_in = csv_file_lines_count( csv_file_name, numeric_only=.false., &
2147 csv_file_status=success_flag) - 1
2148 if ( n_rows_in < n_rows_min .or. (success_flag .eqv. .false.) )
then
2150 tostr(n_rows_in) //
" or file access error, " // &
2151 " success flag is " // tostr(success_flag) )
2152 call log_msg(ltag_warn //
"Check N_ROWS_MIN (=" // tostr(n_rows_min) // &
2153 ") in " // procname )
2156 call log_msg( ltag_info //
"Genome data " // csv_file_name //
" contain " &
2157 // tostr(n_rows_in) //
" rows" )
2158 if ( n_rows_in < pop_size )
call log_msg( ltag_warn // &
2159 "Number of rows in genome data " // csv_file_name //
"," // &
2160 tostr(n_rows_in) //
" is less than input pop_size " // &
2166 handle_csv%name = csv_file_name
2169 call csv_open_read( handle_csv )
2175 if ( .not. handle_csv%status )
then
2182 if ( readline(handle_csv%unit, line_data_buff, .true.) .eqv. .false. )
then
2184 call csv_close( handle_csv )
2190 have_pop:
if (.not.
allocated(this%individual))
then
2191 is_new_population = .true.
2193 if (
present(pop_number_here))
then
2194 pop_number_here_loc = pop_number_here
2196 pop_number_here_loc = rand_i(1,huge(this%pop_number-1))
2198 if (
present(pop_name_here))
then
2199 pop_name_here_loc = pop_name_here
2201 pop_name_here_loc = tostr(pop_number_here_loc)
2204 call this%init(pop_size,pop_number_here_loc,pop_name_here_loc)
2207 missing_random_loc = .true.
2208 call log_msg( ltag_info //
"Initialised population to POPSIZE " // &
2209 tostr(this%population_size) //
", new population: " // &
2210 tostr(is_new_population) )
2212 is_new_population = .false.
2213 call log_msg( ltag_info //
"Population is already allocated POPSIZE=" &
2214 // tostr(this%population_size) )
2216 is_pop_id_reset = .false.
2217 if (
present(pop_number_here))
then
2218 this%pop_number = pop_number_here
2219 is_pop_id_reset = .true.
2221 if (
present(pop_name_here))
then
2222 this%pop_name = pop_name_here
2223 is_pop_id_reset = .true.
2225 if (is_pop_id_reset) &
2226 call log_msg( ltag_info //
"Reset population identifiers " // &
2227 "from parameters: " // tostr(this%pop_number) // &
2228 ", " // trim(this%pop_name) //
", new population: " // &
2229 tostr(is_new_population) )
2232 call log_msg(ltag_info //
"Start reading genome data for "// &
2233 tostr(this%pop_number) //
", " // trim(this%pop_name) // &
2234 ", population array size " // tostr(
size(this%individual)) )
2240 main_read:
do while ( readline(handle_csv%unit, line_data_buff, .true.) &
2241 .and. icase < this%population_size &
2242 .and. icase < pop_size )
2246 if ( len_trim(line_data_buff) < min_file_inp_len )
then
2247 n_ignored_lns = n_ignored_lns + 1
2248 call log_dbg( ltag_info //
"Ignored line " // tostr(icase) //
": " // &
2249 trim(line_data_buff), procname,
modname )
2256 call delall(line_data_buff, sqt)
2257 call delall(line_data_buff, dqt)
2259 line_data_buff_length = len_trim(line_data_buff)
2266 if ( .not.
allocated(line_data_substrings) ) &
2267 allocate( line_data_substrings(line_data_buff_length/min_field) )
2272 call parse(line_data_buff, sdelim, line_data_substrings, line_data_nflds)
2284 n_gcols:
do j=1, n_chromosomes
2285 do k=1, chromosome_ploidy
2286 do l=1, len_chromosomes(j)
2287 do m=1, additive_comps
2293 if ( line_data_nflds - 2 /= nvars )
then
2294 call log_write_error( ltag_error //
"Number of fields in data file " &
2295 // tostr(line_data_nflds) // &
2296 " is unequal to N of model data: " // tostr(nvars) // &
2297 " for case (row) " // tostr(icase) )
2298 if (
present(is_success)) is_success = .false.
2304 if (.not.
allocated(matrix_row))
allocate(matrix_row(line_data_nflds-2))
2305 matrix_row = unknown
2308 if (is_numeric(line_data_substrings(1)))
then
2309 call value( trim(line_data_substrings(1)), ivalue, error_iflag)
2311 call log_write_error(
"Error reading ID_NUM field, row " // tostr(icase))
2314 this%individual(icase)%person_number = ivalue
2317 this%individual(icase)%genome_label = trim(line_data_substrings(2))
2324 do jfield=3, line_data_nflds
2325 if ( trim(line_data_substrings(jfield))==
"" )
then
2327 call rand_array( matrix_row(jfield-2:line_data_nflds-2), &
2328 allelerange_min, allelerange_max )
2329 call log_msg( ltag_warn //
"Incomplete data in field " // &
2330 tostr(jfield) //
" , row " // tostr(icase) // &
2331 "; set random array: " // &
2332 tostr(matrix_row(jfield-2:line_data_nflds-2)) )
2335 if (is_numeric(line_data_substrings(jfield)))
then
2336 call value(trim(line_data_substrings(jfield)), matrix_row(jfield-2),&
2340 matrix_row(jfield-2) = rand_i(allelerange_min, allelerange_max)
2341 call log_msg( ltag_warn //
"Wrong non-numeric data in row " // &
2342 tostr(jfield) //
" , row " // tostr(icase) // &
2343 ": set random " // tostr(matrix_row(jfield-2)) )
2350 genome:
do j=1, n_chromosomes
2351 do k=1, chromosome_ploidy
2352 do l=1, len_chromosomes(j)
2353 do m=1, additive_comps
2355 this%individual(icase)%chromosome(j,k)%allele(l)%allele_value(m) = matrix_row(jfield)
2360 call log_dbg( ltag_info //
"Read genome data case " // tostr(icase) )
2362 deallocate( line_data_substrings )
2366 call log_msg( ltag_info //
"All " // tostr(icase) // &
2367 " rows read from data file " // handle_csv%name )
2374 fill_extra:
if ( icase < this%population_size .and. &
2375 (is_new_population .eqv. .false.) )
then
2377 call log_msg( ltag_info //
"Processing extra data" )
2378 if ( missing_random_loc .eqv. .true. )
then
2380 do i=icase+1, this%population_size
2382 call this%individual(i)%init()
2386 call this%individual(i)%set_id(i)
2388 call log_msg( ltag_info //
"Initialised random cases from " // &
2389 tostr(icase+1) //
" to " // tostr(this%population_size) )
2391 call log_msg(ltag_info //
"The extra data are left intact" )
2396 call csv_close( handle_csv )
2397 if (
present(is_success)) is_success = .true.
2398 call log_msg( ltag_info //
"Read genome data from " // &
2399 trim(handle_csv%name) //
" completed, file closed. " // &
2400 tostr(n_ignored_lns) //
" rows ignored." )
2401 call log_delimiter(log_level_chapter)
2406 character(len=*),
intent(in) :: message
2408 call log_msg( ltag_error // message //
": " // &
2409 csv_file_name //
", in " // procname )
2410 call log_msg( ltag_error //
"Data file " // csv_file_name // &
2411 " cannot be read in " // procname )
2412 if (
present(is_success)) is_success = .false.
2425 character(len=*),
intent(in) :: csv_file_name
2428 logical,
optional,
intent(out) :: is_success
2431 integer :: i, j, agent
2437 character(len=:),
allocatable :: record_csv
2440 integer :: record_csv_max_length
2447 character(len=LABEL_LENGTH),
dimension(*),
parameter :: &
2448 COLUMNS_PERC = [ character(len=label_length) :: &
2466 character(len=LABEL_LENGTH),
dimension(*),
parameter :: &
2467 COLUMNS_EMOT = [ character(len=label_length) :: &
2479 call memory_file%open_write( csv_file_name,
format_csv )
2480 if ( .not. memory_file%is_success() )
then
2481 if (
present(is_success)) is_success = .false.
2482 call memory_file%close()
2497 record_csv_max_length = 50 + &
2498 label_length * 2 + 2 * 6 + &
2499 (label_length *
size(columns_perc) +
size(columns_perc) * 6) * &
2500 history_size_perception + &
2501 (label_length *
size(columns_emot) +
size(columns_emot) * 6) * &
2502 history_size_motivation
2507 record_csv = repeat(
" ", record_csv_max_length )
2513 call csv_record_append( record_csv, &
2514 [
character(len=LABEL_LENGTH) ::
"ID_NUM",
"AGENT_NAME"] )
2523 do j = 1,
size(columns_perc)
2524 do i = 1, history_size_perception
2525 call csv_record_append( record_csv, &
2526 trim(columns_perc(j)) // &
2527 tostr(i, history_size_perception) )
2538 do j = 1,
size(columns_emot)
2539 do i = 1, history_size_motivation
2540 call csv_record_append( record_csv, &
2541 trim(columns_emot(j)) // &
2542 tostr(i, history_size_motivation) )
2548 call memory_file%record_write( record_csv )
2549 if ( .not. memory_file%is_success() )
then
2550 if (
present(is_success)) is_success = .false.
2551 call memory_file%close()
2565 inds:
do agent=1, this%population_size
2566 record_csv = repeat(
" ", record_csv_max_length )
2567 associate( agent => this%individual(agent) )
2569 call csv_record_append(record_csv,agent%person_number)
2570 call csv_record_append(record_csv,agent%genome_label )
2572 call csv_record_append(record_csv,agent%memory_stack%memory_light )
2573 call csv_record_append(record_csv,agent%memory_stack%memory_depth )
2574 call csv_record_append(record_csv,agent%memory_stack%memory_food )
2575 call csv_record_append(record_csv,agent%memory_stack%memory_foodsiz)
2576 call csv_record_append(record_csv,agent%memory_stack%memory_foodist)
2577 call csv_record_append(record_csv,agent%memory_stack%memory_consp )
2578 call csv_record_append(record_csv,agent%memory_stack%memory_pred )
2579 call csv_record_append(record_csv,agent%memory_stack%memory_stom )
2580 call csv_record_append(record_csv,agent%memory_stack%memory_bdmass )
2581 call csv_record_append(record_csv,agent%memory_stack%memory_energ )
2582 call csv_record_append(record_csv,agent%memory_stack%memory_reprfac)
2584 call csv_record_append(record_csv, &
2585 agent%memory_motivations%hunger)
2586 call csv_record_append(record_csv, &
2587 agent%memory_motivations%defence_fear)
2588 call csv_record_append(record_csv, &
2589 agent%memory_motivations%reproduction)
2593 call csv_record_append(record_csv, &
2594 agent%memory_motivations%gos_main)
2595 call csv_record_append(record_csv, &
2596 agent%memory_motivations%gos_arousal)
2597 call csv_record_append(record_csv, &
2598 agent%memory_motivations%gos_repeated)
2602 call memory_file%record_write( record_csv )
2603 if ( .not. memory_file%is_success() )
then
2604 if (
present(is_success)) is_success = .false.
2605 call memory_file%close()
2612 call memory_file%close()
2613 if ( .not. memory_file%is_success() )
then
2614 if (
present(is_success)) is_success = .false.
2616 if (
present(is_success)) is_success = .true.
2622 if ( is_zip_outputs )
then
2623 call call_external(command=cmd_zip_output //
" " // csv_file_name, &
2624 suppress_output=.true., &
2625 is_background_task=zip_outputs_background )
2639 character(len=*),
intent(in) :: csv_file_name
2642 logical,
optional,
intent(out) :: is_success
2651 character(len=:),
allocatable :: record_csv
2654 integer :: record_csv_max_length
2662 record_csv_max_length = history_size_spatial * label_length * 3 + &
2663 history_size_spatial * 3 * 3 + &
2664 label_length * 2 + 2 * 3
2667 call history_file%open_write( csv_file_name,
format_csv )
2668 if ( .not. history_file%is_success() )
then
2669 if (
present(is_success)) is_success = .false.
2670 call history_file%close()
2678 record_csv = repeat(
" ", record_csv_max_length )
2686 call csv_record_append( record_csv, &
2687 [
character(len=LABEL_LENGTH) ::
"ID_NUM",
"AGENT_NAME"] )
2692 do i=1, history_size_spatial
2693 call csv_record_append( record_csv, &
2694 "X_" // tostr(i, history_size_spatial), &
2695 "Y_" // tostr(i, history_size_spatial), &
2696 "D_" // tostr(i, history_size_spatial) )
2700 call history_file%record_write( record_csv )
2701 if ( .not. history_file%is_success() )
then
2702 if (
present(is_success)) is_success = .false.
2703 call history_file%close()
2710 inds:
do agent=1, this%population_size
2713 record_csv = repeat(
" ", record_csv_max_length )
2715 associate( agent => this%individual(agent) )
2717 call csv_record_append( record_csv, agent%person_number )
2718 call csv_record_append( record_csv, agent%genome_label )
2722 do i = 1, history_size_spatial
2723 call csv_record_append( record_csv, agent%history(i)%x , &
2724 agent%history(i)%y , &
2725 agent%history(i)%depth )
2730 call history_file%record_write( record_csv )
2731 if ( .not. history_file%is_success() )
then
2732 if (
present(is_success)) is_success = .false.
2733 call history_file%close()
2740 call history_file%close()
2741 if ( .not. history_file%is_success() )
then
2742 if (
present(is_success)) is_success = .false.
2744 if (
present(is_success)) is_success = .true.
2750 if ( is_zip_outputs )
then
2751 call call_external(command=cmd_zip_output //
" " // csv_file_name, &
2752 suppress_output=.true., &
2753 is_background_task=zip_outputs_background )
2766 character(len=*),
intent(in) :: csv_file_name
2769 logical,
optional,
intent(out) :: is_success
2778 character(len=:),
allocatable :: record_csv
2781 integer :: record_csv_max_length
2789 record_csv_max_length = history_size_behaviours * label_length + &
2790 history_size_behaviours * 3 + &
2791 label_length * 2 + 2 * 3
2794 call history_file%open_write( csv_file_name,
format_csv )
2795 if ( .not. history_file%is_success() )
then
2796 if (
present(is_success)) is_success = .false.
2797 call history_file%close()
2805 record_csv = repeat(
" ", record_csv_max_length )
2813 call csv_record_append( record_csv, &
2814 [
character(len=LABEL_LENGTH) ::
"ID_NUM",
"AGENT_NAME"] )
2818 do i=1, history_size_behaviours
2819 call csv_record_append( record_csv, &
2820 "BEHAV_" // tostr(i, history_size_behaviours) )
2824 call history_file%record_write( record_csv )
2825 if ( .not. history_file%is_success() )
then
2826 if (
present(is_success)) is_success = .false.
2827 call history_file%close()
2834 inds:
do agent=1, this%population_size
2837 record_csv = repeat(
" ", record_csv_max_length )
2839 associate( agent => this%individual(agent) )
2841 call csv_record_append( record_csv, agent%person_number )
2842 call csv_record_append( record_csv, agent%genome_label )
2845 do i = 1, history_size_behaviours
2846 call csv_record_append( record_csv, agent%history_behave(i) )
2851 call history_file%record_write( record_csv )
2852 if ( .not. history_file%is_success() )
then
2853 if (
present(is_success)) is_success = .false.
2854 call history_file%close()
2861 call history_file%close()
2862 if ( .not. history_file%is_success() )
then
2863 if (
present(is_success)) is_success = .false.
2865 if (
present(is_success)) is_success = .true.
2871 if ( is_zip_outputs )
then
2872 call call_external(command=cmd_zip_output //
" " // csv_file_name, &
2873 suppress_output=.true., &
2874 is_background_task=zip_outputs_background )
2891 call this%individual%fitness_calc()
2908 integer,
parameter :: min_fitness = ga_fitness_select
2916 integer,
parameter :: min_ga_reproduce = &
2917 max( ga_reproduce_n_min, nint(ga_reproduce_min_prop*popsize) )
2922 val_out = within( count( this%individual%fitness < min_fitness &
2923 .and. this%individual%fitness >= 0 ), &
2924 min_ga_reproduce, ga_reproduce_n )
2928 n_alive = count(this%individual%alive)
2929 if ( val_out > n_alive ) val_out = max( min_ga_reproduce, n_alive )
2937 result(mutat_rate_out)
2940 real(srp),
intent(in) :: baseline
2942 real(srp),
optional,
intent(in) :: maxvalue
2944 real(srp) :: mutat_rate_out
2952 real(srp) :: mutationrate_max
2956 real(srp),
parameter :: mutationrate_max_def = 0.4_srp
2963 integer :: n_base_point
2967 real(srp),
dimension(3) :: mutation_grid_abscissa, mutation_grid_ordinate
2973 integer,
parameter :: min_growing = 4
2979 real(srp),
parameter :: non_grow_increment = 1.3_srp
2981 if (
present(maxvalue))
then
2982 mutationrate_max = maxvalue
2984 mutationrate_max = mutationrate_max_def
3000 n_base_point = count( this%individual%is_alive() )
3004 step = ( mutationrate_max - baseline ) / 4.0_srp
3013 mutation_grid_abscissa = [ 0.0_srp, popsize/2.0_srp, real(popsize, srp) ]
3029 mutation_grid_ordinate = [ mutationrate_max, baseline + step, baseline ]
3045 mutat_rate_out = within( ddpinterpol( &
3046 mutation_grid_abscissa, &
3047 mutation_grid_ordinate, &
3048 real(n_base_point, srp) ), &
3056 if ( count( this%individual%get_mass() > &
3057 this%individual%get_mass_birth() ) < min_growing )
then
3058 mutat_rate_out = within( mutat_rate_out * non_grow_increment, &
3059 baseline, mutationrate_max )
3067 call debug_interpolate_plot_save( &
3068 grid_xx=mutation_grid_abscissa, grid_yy=mutation_grid_ordinate, &
3069 ipol_value=real(n_base_point, srp), algstr=
"DDPINTERPOL", &
3070 output_file=
"plot_debug_adaptive_mutation_rate_" // mmdd //
"_g_" &
3071 // tostr(global_generation_number_current) // ps )
Calculate an average of an array excluding missing code values.
Force a value within the range set by the vmin and vmax dummy parameter values.
recursive pure subroutine qsort(A)
qsort and qs_partition_ are the two parts of the recursive sort algorithm qsort is the recursive fron...
pure subroutine qs_partition_fitness(A, marker)
partition is a pivot backend for fitness
subroutine log_write_error(message)
This subroutine writes error message to the main log file.
COMMONDATA – definitions of global constants and procedures.
logical, public, protected is_debug
Sets the model in the debug mode if TRUE. The Debug mode generates huge additional outputs and logs....
character(len= *), parameter, private modname
MODNAME always refers to the name of the current module for use by the LOGGER function LOG_DBG....
integer, public global_generation_number_current
The current global generation number. This is a global non fixed-parameter variable that is updated i...
character(len= *), parameter, public ltag_error
logical, parameter, public init_agents_depth_is_fixed
This parameter determines if the agents are initialised at a fixed depth at the initialisation....
character(len= *), parameter, public ps
Standard file extension for debug and other PostScript plots.
logical, parameter, public init_agents_depth_is_gauss
This parameter determines if the agents are initialised at a fixed depth at the initialisation....
elemental real(srp) function cv2variance(cv, mean)
Calculate the variance from the coefficient of variation.
integer, parameter, public unknown
Numerical code for invalid or missing integer counts.
real(srp), parameter, public init_agents_depth_cv
This parameter sets the Coefficient of Variation for the Gaussian depth initialisation of the agents ...
integer, parameter, public label_length
The length of standard character string labels. We use labels for various objects,...
integer, parameter, public popsize
Maximum population size.
subroutine log_dbg(message_string, procname, modname)
LOG_DBG: debug message to the log. The message goes to the logger only when running in the DEBUG mode...
integer, parameter, public predator_risk_group_select_index_partial
Sets the limit for partial indexing and ranking of prey agents in the visual range of the predator....
real(srp), parameter, public init_agents_depth
The fixed depth at which the agents are initialised at the start of the simulation....
integer, parameter, public history_size_agent_prop
History stack size for the agent's basic properties, such as body length and body mass....
logical, parameter, public true
Safety parameter avoid errors in logical values, so we can now refer to standard Fortran ....
integer, parameter, public label_cen
real(srp), public global_rescale_maximum_motivation
Global maximum sensory information that is updated for the whole population of agents.
character(len=:), allocatable, public, protected mmdd
MMDD tag, year, month and day, used in file names and outputs. The value of the tag should be obtaine...
real(srp) function std_dev(array_in, missing_code, undef_ret_null)
Calculate standard deviation using trivial formula:
subroutine debug_interpolate_plot_save(grid_xx, grid_yy, ipol_value, algstr, output_file, enable_non_debug)
Produce a debug plot of the interpolation data using an external program htinterp from the HEDTOOLS t...
integer, parameter, public label_cst
This parameter defines the range of characters that is used for generating random labels,...
integer, public global_time_step_model_current
The current global time step of the model. This is a global non fixed-parameter variable that is upda...
integer, parameter, public history_size_motivation
Sets the size of the emotional state memory stack.
logical, parameter, public false
character(len= *), parameter, public ltag_info
Definition of high level file objects.
An umbrella module that collects all the components of the individual agent.
Define the population of agents object, its properties and functions.
subroutine population_lifecycle_step_eatonly_preevol(this)
This procedure performs a single step of the life cycle of the whole population, the agents for the s...
character(len=label_length) function population_get_pop_name(this)
Accessor get-function for the population character label ID.
subroutine population_save_data_movements(this, csv_file_name, is_success)
Save the latest movement history of all agents. This method makes use of the the_environment::spatial...
subroutine population_destroy_deallocate_objects(this)
Destroys this population and deallocates the array of individual member objects.
integer function population_get_popsize(this)
Accessor get-function for the size of this population.
elemental subroutine sort_population_by_fitness(this)
This subroutine sorts the population individual object by their %fitness components.
subroutine population_save_data_all_genomes(this, csv_file_name, is_success)
Save the genome data of all agents in this population to a CSV file.
real(srp) function population_ga_mutation_rate_adaptive(this, baseline, maxvalue)
This function implements adaptive mutation rate that increases as the population size reduces.
integer function get_individual_id(this)
Get integer ID number to individual member of the population object.
subroutine population_rwalk3d_all_agents_step(this, dist_array, cv_array, dist_all, cv_all, environment_limits, n_walks)
Perform one or several steps of random walk by all agents.
subroutine population_birth_mortality_init(this, energy_mean, energy_sd)
Impose selective mortality at birth on the agents. Selective mortality sets a fixed limit on uncontro...
integer function population_get_pop_number(this)
Accessor get-function for the population number ID.
subroutine population_rwalk25d_all_agents_step(this, dist_array_xy, cv_array_xy, dist_array_depth, cv_array_depth, dist_all_xy, cv_all_xy, dist_all_depth, cv_all_depth, environment_limits, n_walks)
Perform one or several steps of random walk by all agents.
pure subroutine population_preevol_fitness_calc(this)
Calculate fitness for the pre-evolution phase of the genetic algorithm. Pre-evolution is based on sel...
pure integer function population_ga_reproduce_max(this)
Determine the number of parents that have fitness higher than the minimum acceptable value....
subroutine position_individuals_uniform(this, environ)
Position each member of the population randomly within a bounding environment.
subroutine population_subject_individual_risk_mortality(this)
Subject all members of this population to their individual mortality risks.
subroutine population_subject_predator_attack(this, this_predator, time_step_model)
Subject the population to an attack by a specific predator. The predator acts on agents in its proxim...
subroutine population_save_data_behaviours(this, csv_file_name, is_success)
Save the behaviours history stack the_neurobio::behaviour::history_behave for all agents.
integer, public global_ind_n_eaten_by_predators
Global indicator variable that keeps the number of agents that have died as a consequence of predator...
subroutine population_save_data_all_agents_csv(this, csv_file_name, save_header, is_logging, is_success)
Save data for all agents within the population into a CSV file.
subroutine population_subject_other_risks(this)
Subject the population to mortality caused by habitat-specific mortality risk. Each agent is affected...
subroutine set_individual_id(this, idnumber)
Set integer ID number to individual member of the population object.
subroutine individ_posit_in_environ_uniform(this, environ)
Places the individual agent, a member of the population, within a specific environment at random with...
subroutine population_lifecycle_step_preevol(this)
This procedure performs a single step of the life cycle of the whole population, the agents for the s...
subroutine population_save_data_memory(this, csv_file_name, is_success)
Save the perceptual and emotional memory stack data of all agents in this population to a CSV file.
subroutine init_population_random(this, pop_size, pop_number_here, pop_name_here)
Initialise the population object.
character(len= *), parameter, private modname
subroutine genome_individual_set_dead_non_pure(this, non_debug_log)
Set the individual to be dead. Note that this function does not deallocate the individual agent objec...
subroutine sex_initialise_from_genome(this)
Determine the sex for each member of the population.
subroutine reset_population_id_random(this, pop_number_here, pop_name_here)
Reset individual IDs of the population members.
subroutine population_load_data_all_genomes(this, pop_size, pop_number_here, pop_name_here, csv_file_name, missing_random, is_success)
Load the genome data of all agents in this population from a CSV file. Note that the procedure implem...
FILE_HANDLE is the basic file handle object. It provides an unitary object oriented interface for ope...
This type describes parameters of the individual agent.
Definition of individual member of a population.
Definition of the population object.