/**
* dim_traffic_example
* Author: Dimitris
* Description: evolution of a traffic model
*/
model dim_traffic_example
global {
file shape_file_buildings <- file("../includes/batiments2.shp");
file shape_file_roads <- file("../includes/routes.shp");
// file shape_file_bounds <- file('../includes/bounds.shp');
// instead of indicating bounds we give the geometry shape > we use a shapefile to automatically define it by computing its envelope
geometry shape <- envelope(shape_file_roads);
//
// A "reflex" is a sequence of statements that can be executed, at each time step, by the agent
// A "Init" is evaluated only once when the agent is created, after the initialization of its variables
// and before it exectutes any "reflex"
int nb_adults <- 100;
int nb_children <- 60;
int nb_elderly <- 60;
// The value of the day_time variable is automatically computed at each simulation step and is equals to
// "time (the simulation step) modulo 24" (one day is decomposed in 24 simulation steps)Therefore every step is 1 hour.
int day_time update: time mod 24 ;
int min_work_start_a <- 6;
int max_work_start_a <- 10;
int min_work_end_a <- 14;
int max_work_end_a <- 22;
int min_work_start_c <- 9;
int max_work_start_c <- 9;
int min_work_end_c <- 14;
int max_work_end_c <- 14;
// The value of the day_time variable is automatically computed at each simulation step and is equals to
// "time (the simulation step) modulo 144" (one day is decomposed in 144 simulation steps).
// int day_time update: time mod 144 ;
// int min_work_start <- 36;
// int max_work_start <- 60;
// int min_work_end <- 84;
// int max_work_end <- 132;
float min_speed <- 50.0;
float max_speed <- 100.0;
graph the_graph;
init {
create building from: shape_file_buildings with: [type::string(read ('NATURE'))] {
if type='Industrial' {
color <- rgb('pink') ;
}
if type='School' {
color <- rgb('black') ;
}
}
create road from: shape_file_roads ;
map<road,float> weights_map <- road as_map (each:: (shape.perimeter));
the_graph <- as_edge_graph(road) with_weights weights_map;
list<building> residential_buildings <- building where (each.type='Residential');
list<building> industrial_buildings <- building where (each.type='Industrial') ;
list<building> school_buildings <- building where (each.type='School') ;
create adults number: nb_adults {
speed <- min_speed + rnd (max_speed - min_speed) ;
start_work <- min_work_start_a + rnd (max_work_start_a - min_work_start_a) ;
end_work <- min_work_end_a + rnd (max_work_end_a - min_work_end_a) ;
living_place <- one_of(residential_buildings) ;
working_place <- one_of(industrial_buildings) ;
location <- any_location_in (living_place);
}
create children number: nb_children {
speed <- min_speed + rnd (max_speed - min_speed) ;
start_work <- min_work_start_c + rnd (max_work_start_c - min_work_start_c) ;
end_work <- min_work_end_c + rnd (max_work_end_c - min_work_end_c) ;
living_place <- one_of(residential_buildings) ;
working_place <- one_of(school_buildings) ;
location <- any_location_in (living_place);
}
create elderly number: nb_elderly {
living_place <- one_of(residential_buildings) ;
location <- any_location_in (living_place);
}
}
reflex update_graph{
map<road,float> weights_map <- road as_map (each:: (each.shape.perimeter));
the_graph <- the_graph with_weights weights_map;
}
}
entities {
species building {
string type;
rgb color <- rgb('blue') ;
aspect base {
draw shape color: color ;
}
}
species road {
rgb color <- rgb('black') ;
aspect geom {
draw shape color: color ;
}
}
species adults skills: [moving]{
rgb color <- rgb('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: day_time = start_work {
objective <- 'working' ;
the_target <- any_location_in (working_place);
}
reflex time_to_go_home when: day_time = end_work {
objective <- 'go home' ;
the_target <- any_location_in (living_place);
}
reflex move when: the_target != nil {
path path_followed <- self goto [target::the_target, on::the_graph, return_path:: true];
list<geometry> segments <- path_followed.segments;
loop line over: segments {
float dist <- line.perimeter;
road ag <- road(path_followed agent_from_geometry line);
}
switch the_target {
match location { the_target <- nil ;}
}
}
aspect base {
draw circle(7) color: color;
}
}
species children skills: [moving]{
rgb color <- rgb('red') ;
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: day_time = start_work {
objective <- 'working' ;
the_target <- any_location_in (working_place);
}
reflex time_to_go_home when: day_time = end_work {
objective <- 'go home' ;
the_target <- any_location_in (living_place);
}
reflex move when: the_target != nil {
path path_followed <- self goto [target::the_target, on::the_graph, return_path:: true];
list<geometry> segments <- path_followed.segments;
loop line over: segments {
float dist <- line.perimeter;
road ag <- road(path_followed agent_from_geometry line);
}
switch the_target {
match location { the_target <- nil ;}
}
}
aspect base {
draw circle(5) color: color;
}
}
species elderly {
rgb color <- rgb('green') ;
building living_place <- nil ;
string objective ;
point the_target <- nil ;
aspect base {
draw circle(5) color: color;
}
}
}
experiment dim_traffic_example type: gui {
parameter 'Shapefile for the buildings:' var: shape_file_buildings category: 'GIS' ;
parameter 'Shapefile for the roads:' var: shape_file_roads category: 'GIS' ;
// parameter 'Shapefile for the bounds:' var: shape_file_bounds category: 'GIS' ;
parameter 'Number of adults agents' var: nb_adults category: 'adults' ;
parameter 'Number of children agents' var: nb_children category: 'children' ;
parameter 'Number of elderly agents' var: nb_elderly category: 'elderly' ;
parameter 'Earliest hour to start work' var: min_work_start_a category: 'adults' ;
parameter 'Latest hour to start work' var: max_work_start_a category: 'adults' ;
parameter 'Earliest hour to end work' var: min_work_end_a category: 'adults' ;
parameter 'Latest hour to end work' var: max_work_end_a category: 'adults' ;
parameter 'minimal speed' var: min_speed category: 'adults' ;
parameter 'maximal speed' var: max_speed category: 'adults' ;
parameter 'Earliest hour to start work' var: min_work_start_c category: 'children' ;
parameter 'Latest hour to start work' var: max_work_start_c category: 'children' ;
parameter 'Earliest hour to end work' var: min_work_end_c category: 'children' ;
parameter 'Latest hour to end work' var: max_work_end_c category: 'children' ;
parameter 'minimal speed' var: min_speed category: 'adults' ;
parameter 'maximal speed' var: max_speed category: 'adults' ;
output {
display dim_traffic_example refresh_every: 1 {
species building aspect: base ;
species road aspect: geom ;
species adults aspect: base ;
species children aspect: base ;
species elderly aspect: base ;
}
display chart_display refresh_every: 10 {
chart name: 'adults Objectif' type: pie background: rgb('lightGray') style: exploded size: {1, 1} position: {0, 0} {
data name:'Working' value: adults count (each.objective='working') color: rgb('green') ;
data name:'Staying home' value: adults count (each.objective='go home') color: rgb('blue') ;
}
chart name: 'children Objectif' type: pie background: rgb('lightGray') style: exploded size: {1, 1} position: {0, 0} {
data name:'Working' value: adults count (each.objective='working') color: rgb('green') ;
data name:'Staying home' value: adults count (each.objective='go home') color: rgb('blue') ;
}
}
}
}
--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.
...
float step <- 10 #mn;
Based on your code, "cycle_to_save" was set to 50 cycles. That means that we capture the agent trajectory for a total time of 50 hours (since time = cycle * step = 50 * 1h), right?
Opening the exported shapefile in ArcMap, I was expecting something like 50 entries per agent, with the agent's set of coordinates recorded for every step. It looks like I got this wrong since different agents had different number of "recording" entries. I probably missed something..
Dear Patrick, thank you so much!
This is really really helpful indeed. Your quick help encourages me to keep playing with a concept that I have in mind.
I'd like to ask one thing (and please bear with me)
What is the frequency with which an agent's set of coordinates is being captured?
Let me explain.. in my example time is set to a modulo 24 cycle, that means that the step is set to 1h, right? (please do correct me if I'm wrong, I'm new at this : ) )
Based on your code, "cycle_to_save" was set to 50 cycles. That means that we capture the agent trajectory for a total time of 50 hours (since time = cycle * step = 50 * 1h), right?
Opening the exported shapefile in ArcMap, I was expecting something like 50 entries per agent, with the agent's set of coordinates recorded for every step. It looks like I got this wrong since different agents had different number of "recording" entries. I probably missed something..
Now ideally what I want is to capture the agent's location in every simulation step (user defined, in this case every 1h) so when I open the shapefile's attribute table, I'd have columns in dbf such as:
- agent_name (e.g adult#1) - we have that already thanks to your help
- Coordinates (or polygon) - we have that already thanks to your help
- Cycle (0,1,2,3... till we reach the number of cycles as indicated in "cycle_to_save" variable) - could you please help me with that so that I have an estimation of time for every location..
- Place (whether the agent is at a residential/industrial/school place or moving in the road)
By now you're probably tired with all these descriptions, I'm sorry.
Any hint would mean a lot.
--
I am a bit lost with your model and the duration of a simulation step.
float step <- 10 #mn;
int cycle_to_save <- 144;
reflex end_simulation when: cycle = 1440 {
do pause;
}
//int day_time update: time mod 24;
int current_hour update: (time /#h) mod 24;
int min_work_start_a <- 6;
int max_work_start_a <- 10;
int min_work_end_a <- 14;
int max_work_end_a <- 22;
int min_work_start_c <- 9;
int max_work_start_c <- 9;
int min_work_end_c <- 14;
int max_work_end_c <- 14;
float min_speed <- 50.0 #km/#h;
float max_speed <- 100.0 #km/#h;
Not exactly as I store in the trajectories of my agents the segments and for each segment (I can have several segments per simulation steps), I create one trajectory agents : so I can have more than 50 geometries for one agents. In the same way, if the path between the origin and the destination is very short, the number of simulation step (and segments) to reach the destination can be lower than 50.
I have some ideas of how to do that, but also some questions to be sure to give you good advices ;) :- when an agent stay at home for 3 simulation cycles, do want you?-> nothing, only movements interest you-> one point geometry with for cycle, the first "cycle" of its staying-> 3 points
...
--
...