4. Movement on a graph
This step creates a graph from the road agents and uses it to constrain people's movement. Agents wait in buildings for varying lengths of time, with a higher chance of leaving near 9:00, 12:00 and 18:00.

Build the road graph​
as_edge_graph uses the road agents as graph edges and joins their endpoints. The road_network graph is then used as the topology for movement.
global {
int nb_people <- 500;
float agent_speed <- 5.0 #km/#h;
float step <- 1 #minutes;
float infection_distance <- 2.0 #m;
float proba_infection <- 0.05;
int nb_infected_init <- 5;
file roads_shapefile <- file("../includes/road.shp");
file buildings_shapefile <- file("../includes/building.shp");
geometry shape <- envelope(roads_shapefile);
graph road_network;
float staying_coeff update: 10.0 ^ (1 + min([abs(current_date.hour - 9), abs(current_date.hour - 12), abs(current_date.hour - 18)]));
int nb_people_infected <- nb_infected_init update: people count (each.is_infected);
int nb_people_not_infected <- nb_people - nb_infected_init update: nb_people - nb_people_infected;
float infected_rate update: nb_people_infected / nb_people;
init {
create road from: roads_shapefile;
road_network <- as_edge_graph(road);
create building from: buildings_shapefile;
create people number: nb_people {
speed <- agent_speed;
location <- any_location_in(one_of(building));
}
ask nb_infected_init among people {
is_infected <- true;
}
}
}
Assign and follow a destination​
Each person tracks a destination and the number of cycles spent at the current location. When there is no destination, staying may choose a point in another building. When a destination exists, move calls goto on the road graph and clears the destination upon arrival.
species people skills: [moving] {
bool is_infected <- false;
point target;
int staying_counter;
reflex staying when: target = nil {
staying_counter <- staying_counter + 1;
if flip(staying_counter / staying_coeff) {
target <- any_location_in(one_of(building));
}
}
reflex move when: target != nil {
do goto(target: target, on: road_network);
if (location = target) {
target <- nil;
staying_counter <- 0;
}
}
}
The complete Incremental Model 4 source includes the infection behavior, map layers and chart alongside these movement rules.