2. Stop conditions
The SIR models stop when the infection has ended or the simulation reaches cycle 1000. The GUI and batch model files express this in different places: SIR.gaml calls experiment.pause() in a global reflex, while SIR_LHS.gaml has a global stop reflex and an until: condition on its batch experiment.
Stop when the infection ends or the cycle limit is reached​
In the batch model, the global reflex uses the die action when either condition is true:
reflex stop when: cycle >= 1000 or nb_infected = 0 {
do die();
}
The SIR_LHS batch experiment repeats the same condition in its until: facet. This keeps the experiment's stop rule alongside the run configuration.
experiment SIR_LHS mode: batch repeat: 1 keep_seed: false
until: (cycle >= 1000 or nb_infected = 0) {
parameter "Number of agents" var: nb_agents min: 50 max: 500;
parameter "Initially infected" var: nb_infected_init min: 1 max: 50;
parameter "Infection rate" var: infection_rate min: 0.0 max: 1.0;
parameter "Infection distance" var: infection_distance min: 1 max: 20 unit: "m";
parameter "Recovery time" var: recovery_time min: 10 max: 200 unit: "cycles";
method exploration sampling: "latinhypercube" sample: 100;
reflex save_results {
ask simulations {
save [int(self), self.nb_agents, self.nb_infected_init,
self.infection_rate, self.infection_distance, self.recovery_time,
self.nb_recovered, self.cycle]
to: "../results/lhs_results.csv" rewrite: false header: true;
}
}
}
See SIR.gaml for the GUI version and SIR_LHS.gaml for the batch version. Both belong to the SIR Analysis Models Library project.