6. Breeding
This step adds reproduction for both prey and predators. An agent can reproduce when it has enough energy and passes its reproduction probability check. The parent's energy is divided between the offspring and the parent.
Reproduction parametersβ
The global parameters define the probability, maximum number of offspring and energy threshold for each species.
global {
float prey_proba_reproduce <- 0.01;
int prey_nb_max_offsprings <- 5;
float prey_energy_reproduce <- 0.5;
float predator_proba_reproduce <- 0.01;
int predator_nb_max_offsprings <- 3;
float predator_energy_reproduce <- 0.5;
}
Reproduce in the parent speciesβ
The parent species uses the same reproduction reflex for both child species. species(self) creates agents of the current agent's species. Inside the creation block, myself refers to the parent and supplies its cell and energy.
reflex reproduce when: (energy >= energy_reproduce) and (flip(proba_reproduce)) {
int nb_offsprings <- rnd(1, nb_max_offsprings);
create species(self) number: nb_offsprings {
my_cell <- myself.my_cell;
location <- my_cell.location;
energy <- myself.energy / nb_offsprings;
}
energy <- energy / nb_offsprings;
}
Prey and predators map their global values to the fields used by the inherited reflex.
species prey parent: generic_species {
rgb color <- #blue;
float max_energy <- prey_max_energy;
float max_transfer <- prey_max_transfer;
float energy_consum <- prey_energy_consum;
float proba_reproduce <- prey_proba_reproduce;
int nb_max_offsprings <- prey_nb_max_offsprings;
float energy_reproduce <- prey_energy_reproduce;
}
species predator parent: generic_species {
rgb color <- #red;
float max_energy <- predator_max_energy;
float energy_transfer <- predator_energy_transfer;
float energy_consum <- predator_energy_consum;
float proba_reproduce <- predator_proba_reproduce;
int nb_max_offsprings <- predator_nb_max_offsprings;
float energy_reproduce <- predator_energy_reproduce;
}
The complete PredatorβPrey model 6 contains the shared species, child-specific feeding actions and experiment controls.