1. Simple SIR model
This model represents susceptible, infected and recovered people as agents. People move through the environment, and infected agents can infect susceptible agents nearby. The SIR Analysis project in the GAMA Models Library contains this model as SIR.gaml.

Define people and infection behavior​
Each person has an infection status and a timer. An infected person tests nearby susceptible people against infection_rate, then recovers when its timer reaches zero.
species person skills: [moving] {
string status <- "susceptible";
int infection_timer <- 0;
float speed <- 1.0;
reflex move {
do wander();
}
reflex infect when: status = "infected" {
ask (person at_distance infection_distance) where (each.status = "susceptible") {
if flip(infection_rate) {
status <- "infected";
infection_timer <- recovery_time;
}
}
infection_timer <- infection_timer - 1;
if infection_timer <= 0 {
status <- "recovered";
}
}
aspect base {
draw circle(1) at: location color:
(status = "infected") ? #red : ((status = "recovered") ? #blue : #green);
}
}
Initialize the population and count outcomes​
The global variables define the model parameters and the susceptible, infected and recovered counts. The init block creates people and selects the initial infected group. A global reflex updates the counts.
global {
int nb_agents <- 200 min: 50 max: 500;
int nb_infected_init <- 5 min: 1 max: 50;
float infection_rate <- 0.5 min: 0.0 max: 1.0;
int infection_distance <- 5 min: 1 max: 20;
int recovery_time <- 50 min: 10 max: 200;
int nb_susceptible <- 0;
int nb_infected <- 0;
int nb_recovered <- 0;
init {
create person number: nb_agents;
ask nb_infected_init among (person as list) {
status <- "infected";
infection_timer <- recovery_time;
}
}
reflex update_counts {
nb_susceptible <- person count (each.status = "susceptible");
nb_infected <- person count (each.status = "infected");
nb_recovered <- person count (each.status = "recovered");
}
reflex stop when: cycle >= 1000 or nb_infected = 0 {
experiment.pause();
}
}
Display the model​
The GUI experiment exposes the five parameters, draws agents by status and plots the three population counts over time.
experiment SIR_simulation mode: gui {
parameter "Number of agents" var: nb_agents;
parameter "Initially infected" var: nb_infected_init;
parameter "Infection rate" var: infection_rate;
parameter "Infection distance" var: infection_distance unit: "m";
parameter "Recovery time" var: recovery_time unit: "cycles";
output {
display "Population" renderer: 2d {
species person aspect: base;
}
display "SIR Chart" renderer: 2d {
chart "SIR dynamics" kind: series {
data "Susceptible" value: nb_susceptible color: #green;
data "Infected" value: nb_infected color: #red;
data "Recovered" value: nb_recovered color: #blue;
}
}
monitor "Susceptible" value: nb_susceptible;
monitor "Infected" value: nb_infected;
monitor "Recovered" value: nb_recovered;
monitor "Cycle" value: cycle;
}
}
See the complete SIR model source in the SIR Analysis project.