Skip to main content
Version: 🚧 Alpha 🚧

3. Movement of People

This step builds a graph from road geometries and uses it to route people between their homes and workplaces.

Model Definition​

The excerpts below show the global, people and experiment declarations used in this step; each code block closes its own scope. The complete model is available in the GAMA model library.

Road graph and initialization​

The model creates road agents from the road shapefile, then uses as_edge_graph to build a graph whose edges follow the road geometries. It creates residential and industrial building lists and assigns one of each to every person.

global {
file shape_file_roads <- file("../includes/road.shp");
graph the_graph;

init {
create road from: shape_file_roads;
the_graph <- as_edge_graph(road);
}
}

People and movement​

Each person has a home, workplace, work schedule, and current objective. At the configured start and end hours, the target changes to a random point inside the corresponding building. The movement reflex calls goto with the road graph; when the person reaches the target, it clears the target and stops.

species people skills: [moving] {
rgb color <- #yellow;
building living_place <- nil;
building working_place <- nil;
int start_work;
int end_work;
string objective;
point the_target <- nil;

reflex time_to_work when: current_date.hour = start_work and objective = "resting" {
objective <- "working";
the_target <- any_location_in(working_place);
}

reflex time_to_go_home when: current_date.hour = end_work and objective = "working" {
objective <- "resting";
the_target <- any_location_in(living_place);
}

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

aspect base {
draw circle(10) color: color border: #black;
}
}

Experiment parameters​

The experiment exposes the population size, work-hour ranges and speed ranges as adjustable parameters. Their defaults and limits are defined in the complete model.

experiment road_traffic mode: gui {
parameter "Number of people agents" var: nb_people category: "People";
parameter "Earliest hour to start work" var: min_work_start category: "People" min: 2 max: 8 unit: "h";
parameter "Latest hour to start work" var: max_work_start category: "People" min: 8 max: 12 unit: "h";
parameter "Earliest hour to end work" var: min_work_end category: "People" min: 12 max: 16 unit: "h";
parameter "Latest hour to end work" var: max_work_end category: "People" min: 16 max: 23 unit: "h";
parameter "Minimal speed" var: min_speed category: "People" min: 0.1 #km/#h max: 3.0 #km/#h step: 0.1 #km/#h unit: #km/#h;
parameter "Maximal speed" var: max_speed category: "People" min: 3.0 #km/#h max: 10.0 #km/#h step: 0.1 #km/#h unit: #km/#h;
}

Complete Model​

gama.library/models/Tutorials/Road%20Traffic/models/Model%2003.gaml
loading...