Skip to main content
Version: 🚧 Alpha 🚧

4. Constrain movement to the road network

This step builds a graph from the road agents and uses it to guide people between buildings. When a person has no destination, the stay reflex may choose a random location in a building; the move reflex follows the graph to reach it.

Result of the Luneray Flu model 4.

Build the road graph​

The as_edge_graph operator builds the road network graph after the road agents have been created.

global {
int nb_people <- 2147;
int nb_infected_init <- 5;
float step <- 5 #mn;
file roads_shapefile <- file("../includes/roads.shp");
file buildings_shapefile <- file("../includes/buildings.shp");
geometry shape <- envelope(roads_shapefile);
graph road_network;

init {
create road from: roads_shapefile;
road_network <- as_edge_graph(road);
create building from: buildings_shapefile;
create people number: nb_people {
location <- any_location_in(one_of(building));
}
ask nb_infected_init among people {
is_infected <- true;
}
}
}

Choose destinations and travel​

The target attribute stores the destination. goto uses road_network as the movement topology; reaching the destination clears it.

species people skills: [moving] {
float speed <- (2 + rnd(3)) #km/#h;
bool is_infected <- false;
point target;

reflex stay when: target = nil {
if flip(0.05) {
target <- any_location_in(one_of(building));
}
}

reflex move when: target != nil {
do goto(target: target, on: road_network);
if (location = target) {
target <- nil;
}
}

reflex infect when: is_infected {
ask people at_distance 10 #m {
if flip(0.05) {
is_infected <- true;
}
}
}

aspect circle {
draw circle(10) color: is_infected ? #red : #green;
}
}

See the complete Luneray Flu model 4 for the GIS layers, statistics and experiment output.