Skip to content
Snippets Groups Projects
Unverified Commit aa4af1a0 authored by Nathancoisne's avatar Nathancoisne Committed by GitHub
Browse files

first commit

parents
Branches
Tags
No related merge requests found
/***
* Part of the SWITCH Project
* Author: Nathan Coisne, code inspired from Patrick Taillandier
* Tags: gis, OSM data
***/
model switch_utilities_gis
/*
* Genere les fichiers buildings.shp et roads.shp pour la ville de Marseille
*
* Données requises pour générer les fichiers buildings.shp et roads.shp d'une ville quelconque :
* https://download.geofabrik.de/europe/france.html pour le shp 'initial' des builings
* https://geoservices.ign.fr/documentation/diffusion/telechargement-donnees-libres.html#bd-topo pour le shapefile à partir duquel on extrait les attributs qu'on donne aux buildings initiaux
* Les frontières de la zone considérée
*
*/
global {
string dataset_path <- "../includes/Marseille/";
//define the bounds of the studied area
file data_file <-shape_file(dataset_path + "boundary_Marseille.shp");
//define the initial building shapefile, extracted from OSM database
file shape_file_buildings <- shape_file(dataset_path + "buildings_marseille.shp");
//define the OSM points of interest buildings, for more types
file shape_file_pois <- shape_file("../includes/Marseille/points_of_interest.shp");
//define the building shapefile with many types, extracted from IGN database
file ign_file <- shape_file(dataset_path + "buildings_ign.shp");
//define the initial building shapefile, extracted from OSM database
file shape_file_roads <- shape_file(dataset_path + "roads_marseille.shp");
list<string> shop_places <- ["commercial", "kiosk", "chapel", "church", "service", "Commercial et services", "Religieux", "religious"];
list<string> sport_places <- ["Sportif"];
float min_area_buildings <- 20.0;
int nb_for_building_shapefile_split <- 50000;
int nb_for_road_shapefile_split <- 20000;
list<string> living_places <- ["house", "apartments", "dormitory", "hotel", "residential", "Résidentiel"];
list<string> work_places <- ["industrial", "office", "construction", "garages", "hospital"];
list<string> study_places <- ["university", "college", "school"];
list<string> leisure_places <- ["commercial", "kiosk", "chapel", "church", "service", "Sportif", "Commercial et services", "Religieux", "religious"];
bool parallel <- true;
bool buildings <- true;
bool roads <- false;
geometry shape <- envelope(data_file);
graph the_graph;
map<road,float> road_weights;
init {
write "Start the pre-processing process";
list<int> list_of_id;
if buildings{
create Building from: shape_file_buildings with: [type::get ("type"), id::int(get("osm_id"))]{
if not (self overlaps world) {
do die;
}
list_of_id << id;
if (type != nil and type != ""){
types << type;
}
}
write "Number of buildings created : "+ length(Building);
ask Building where (each.shape.area < min_area_buildings) {
do die;
}
write "Small building removed";
create Building_ign from: ign_file {
if not (self overlaps world) {
do die;
}
}
write "Number of buildings ign created : "+ length(Building_ign);
ask Building parallel: parallel {
list<Building_ign> neigh <- Building_ign overlapping self;
if not empty(neigh) {
Building_ign bestCand;
if (length(neigh) = 1) {
bestCand <- first(neigh);
} else {
bestCand <- neigh with_max_of (each inter self).area;
if (bestCand = nil) {
bestCand <- neigh with_min_of (each.location distance_to location);
}
if (bestCand = nil){
write("aucun building correspondant a ce building ign");
}
}
if (bestCand.USAGE1 != nil and bestCand.USAGE1 != ""){
types << bestCand.USAGE1;
}
else if (bestCand.USAGE2 != nil and bestCand.USAGE2 != ""){
types << bestCand.USAGE2;
}
if (bestCand.HAUTEUR != nil and bestCand.HAUTEUR > 0){
height <- bestCand.HAUTEUR;
}
}
}
create Building from: shape_file_pois with: [id::int(read("osm_id")), type::read("fclass")]{
if not (self overlaps world){
do die;
}
if not (id in list_of_id){
list_of_id << id;
types_str <- type;
types << type;
}
else{ // fclass devient le type du bâtiment déjà existant
Building real_building <- Building first_with (each.id = self.id);
real_building.type <- type;
real_building.types << type;
real_building.types_str <- type + "," + real_building.types_str;
do die;
}
}
ask Building where empty(each.types){
do die;
}
ask Building parallel: parallel {
type <- first(types); //si le building a déjà un type dans le shapefile initial : on le garde en position 1. Sinon on prend celui de building_ign (USAGE1 ou USAGE2)
types_str <- type;
if (length(types) > 1) {
loop i from: 1 to: length(types) - 1 {
types_str <-types_str + "," + types[i] ;
}
}
}
ask Building_ign{
do die;
}
write("All buildings created and typed. Start cleaning roads");
}
if roads{
write("cleaning roads");
list<geometry> clean_lines <- clean_network(shape_file_roads.contents,3.0 , true, true);
write("road shapefile cleaned");
create road from: clean_lines with: [id::int(get("osm_id")), fclass::get("fclass"), maxspeed::int(get("maxspeed"))]{
if not (self overlaps world) {
do die;
}
}
write "Number of roads created : "+ length(road);
}
if buildings{
write("Saving buildings");
save Building to: dataset_path + "buildings.shp" type: shp attributes: ["id"::id,"type"::type, "types_str"::types_str ,"height"::height];
}
if roads{
write("Saving roads");
save road to: dataset_path + "roads.shp" type: shp attributes: ["id"::id,"fclass"::fclass, "maxspeed"::maxspeed];
}
}
}
species Building_ign {
/*nature du bati; valeurs possibles:
* Indifférenciée | Arc de triomphe | Arène ou théâtre antique | Industriel, agricole ou commercial |
Chapelle | Château | Eglise | Fort, blockhaus, casemate | Monument | Serre | Silo | Tour, donjon | Tribune | Moulin à vent
*/
string NATURE;
/*
* Usage du bati; valeurs possibles: Agricole | Annexe | Commercial et services | Industriel | Religieux | Sportif | Résidentiel |
Indifférencié
*/
string USAGE1; //usage principale
string USAGE2; //usage secondaire
int NB_LOGTS; //nombre de logements;
int NB_ETAGES;// nombre d'étages
float HAUTEUR;
}
species Building {
string type;
list<string> types;
string types_str;
float height;
int id;
}
species road {
int id;
int maxspeed;
string fclass;
aspect base {
draw shape color: color width: 2;
}
}
experiment generateGISdata type: gui {
}
/***
* Part of the SWITCH Project
* Author: Patrick Taillandier
* Tags: gis, OSM data
***/
model switch_utilities_gis
/*
* Ajoute un coefficient de vitesse correspondant à un poids dans le graphe des routes (coefficient de vitesse élevé = vitesse élevée à vélo)
* Ajoute la vitesse du cycliste sur chaque portion de route
* Supprime les routes inaccessibles à vélo
*/
global {
string dataset_path <- "../includes/";
//define the bounds of the studied area
file data_file <-shape_file(dataset_path + "Marseille/boudary_Marseille.shp");
file shape_file_roads <- shape_file(dataset_path + "Marseille/roads.shp");
geometry shape <- envelope(data_file);
graph the_graph;
map<road,float> road_weights;
init {
write "Start the pre-processing process";
create road from: shape_file_roads with: [id::int(get("id")), fclass::get("fclass"), maxspeed::int(get("maxspeed"))]{
if fclass = "motorway" or fclass = "motorway_link"{do die;} //routes innacessibles aux vélos
if fclass="trunk" or fclass="primary" or fclass="secondary" or fclass="tertiary" or fclass="bridleway" or fclass="cycleway"
or fclass="trunk_link" or fclass="primary_link" or fclass="secondary_link" {
speed_coeff <- 1.7;
speed <- 17 #km / #h;
}
if fclass="unclassified" or fclass="residential" or fclass="service" or fclass="track" {
speed_coeff <- 1.2;
speed <- 12 #km / #h;
}
if fclass="living_street" or fclass="pedestrian" or fclass="footway" or fclass="path" or fclass="steps" or fclass="unknown" {
speed_coeff <- 0.4;
speed <- 4 #km / #h;
}
}
write "Number of roads created : "+ length(road);
write("Saving roads");
save road to: "../includes/Marseille/roads_cyclists.shp" type: shp attributes: ["id"::id,"fclass"::fclass, "s_coeff"::speed_coeff, "mean_speed"::speed, "maxspeed"::maxspeed];
write("over");
}
}
species road {
int id;
int maxspeed;
string fclass;
float speed_coeff <- 0.33;
float speed <- 5 #km / #h;
aspect base {
draw shape width: 2;
}
}
experiment generateGISdata type: gui {
output {
display map type: opengl draw_env: false{
species road;
}
}
}
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/* Génération d'une population synthétique de cyclistes
* Trois classes sociales sont représentées : travailleurs, étudiants et trajets de loisi
* Sources : Mobiliscope, données 'occupation des résidents par quartier'
* INSEE household surveys
*
*
*/
global {
string city <- "Marseille";
bool test_population <- false; // permet de générer une population test 20 fois moins peuplée que la population réelle
file bound <- shape_file("../includes/" + city + "/boundary_" + city + ".shp");
file shape_file_buildings; // building contenant les data osm, ign, pois
file shape_file_quartiers; // shapefile des quartiers de la ville considérée, importée de Mobiliscope
file residents_csv_file; // fichier contenant le nombre de résidents pour chaque quartier, importé de Mobiliscope
geometry shape <- envelope(bound);
// Etalonnage d'un modèle gravitaire pour fixer les trajets des agents (leur destination): + le coeff est grand + les trajets sont courts
float worker_adaptative_coeff <- 0.00083; // distance moyenne : 2000 m
float student_adaptative_coeff <- 0.00095; // distance moyenne : 1600 m
float leisure_adaptative_coeff <- 0.00083; // distance moyenne : 2000 m
float delivery_adaptative_coeff <- 0.0005; // distance moyenne : 3000 m
int hour_early_leisure_start <- 11;
int hour_late_leisure_start <- 15;
int hour_early_leisure_end <- 14;
int hour_late_leisure_end <- 18;
int hour_early_delivery_midi_start <- 11;
int hour_late_delivery_midi_start <- 13;
int hour_early_delivery_soir_start <- 18;
int hour_late_delivery_soir_start <- 20;
list<string> living_places <- ["house", "apartments", "dormitory", "hotel", "residential", "Résidentiel"];
list<string> work_places <- ["industrial", "office", "construction", "garages", "hospital", "service", "Commercial et services", "commercial",
"bakery", "bank", "bicycle_shop", "bookshop", "butcher", "cafe", "car_dealership", "community_centre", "courthouse",
"dentist", "department_store", "doctors", "fire_station", "florist", "furniture_shop", "greengrocer", "guesthouse",
"hairdresser", "kindergarten", "kiosk", "library", "mall", "optician", "pharmacy", "police", "post_office", "prison",
"public_building", "retail", "supermarket", "town_hall", "travel_agent", "warehouse", "wastewater_plant", "water_works"];
list<string> study_places <- ["university", "college", "school", "library"];
list<string> eating_places <- ["fast_food", "restaurant"];
list<string> leisure_places <- ["commercial", "kiosk", "chapel", "church", "service", "Sportif", "Commercial et services", "Religieux", "religious",
"bar", "buddhist", "cafe", "car_wash", "christian", "christian_catholic", "christian_evangelical", "christian_orthodox", "christian_protestant",
"cinema", "clothes", "convenience", "doityourself", "dog_park", "florist", "fort", "fountain", "garden_centre", "gift_shop", "golf_course", "jewish",
"mall", "museum", "muslim_sunni", "newsagent", "nightclub", "park", "picnic_site", "pitch", "playground", "pub", "sports_centre", "stadium",
"supermarket", "swimming_pool", "theatre" ];
list<string> tourism_places <- ["archaeological", "arts_centre", "artwork", "attraction", "castle", "chapel", "church", "Religieux", "religious", "buddhist",
"christian", "christian_catholic", "christian_evangelical", "christian_orthodox", "christian_protestant", "fort", "fountain", "garden_centre",
"gift_shop", "graveyard", "jewish", "memorial", "monument", "museum", "muslim_sunni", "park", "ruins", "stadium", "theatre", "tourist_info", "tower"];
init{
if city = "Marseille"{
shape_file_buildings <- shape_file("../includes/Marseille/buildings.shp"); // building contenant les data osm, ign, pois
shape_file_quartiers <- shape_file("../includes/Marseille/MARSEILLE_secteurs.shp");
residents_csv_file <- csv_file("../includes/Marseille//occ_nb_marseille.csv",","); //infos de population résidente dans chaque quartier
matrix data <- matrix(residents_csv_file);
create building from: shape_file_buildings with: [id::int(read("id"))] {
types <- types_str split_with ",";
}
create quartier from: shape_file_quartiers with: [ID::int(read("CODE_SEC")), name::read("LIB"), centre::int(read("centre"))]{
if not (self overlaps world) {
do die;
}
active_pop <- int(data[2, ID - 1]); // le nombre de travailleurs logeant dans le quartier = le nombre d'actifs présents dans le quartier à 4am
students_pop <- int(data[3, ID - 1]);
retired_pop <- int(data[5, ID - 1]);
inactive_pop <- int(data[6, ID - 1]);
without_job_pop <- int(data[4, ID - 1]);
float coeff_surface <- (world inter self).area / self.shape.area;
write("id : " + ID + " coeff : " + coeff_surface);
if coeff_surface < 0.98{
active_pop <- int(active_pop * coeff_surface);
students_pop <- int(students_pop * coeff_surface);
retired_pop <- int(retired_pop * coeff_surface);
inactive_pop <- int(inactive_pop * coeff_surface);
without_job_pop <- int(without_job_pop * coeff_surface);
}
if (centre = 1){
centre_ville <- true;
color <- #orange;
}
else{color <- #yellow;}
}
}
if city = "Toulouse"{
shape_file_buildings <- shape_file("../includes/Toulouse/buildings_with_pois.shp"); // building contenant les data osm, ign, pois
shape_file_quartiers <- shape_file("../includes/Toulouse/toulouse_secteurs.shp");
residents_csv_file <- csv_file("../includes/Toulouse/occ_nb_toulouse.csv",",");
matrix data <- matrix(residents_csv_file);
create building from: shape_file_buildings with: [id::int(read("id"))] {
types <- types_str split_with ",";
}
create quartier from: shape_file_quartiers with: [ID::int(read("CODE_SEC")), name::read("LIB"), centre::int(read("centre"))]{
if not (self overlaps world) {
do die;
}
active_pop <- int(data[2, ID - 1]); // le nombre de travailleurs logeant dans le quartier = le nombre d'actifs présents dans le quartier à 4am
students_pop <- int(data[3, ID - 1]);
retired_pop <- int(data[5, ID - 1]);
inactive_pop <- int(data[6, ID - 1]);
without_job_pop <- int(data[4, ID - 1]);
float coeff_surface <- (world inter self).area / self.shape.area;
write("id : " + ID + " area : " + self.shape.area);
write("id : " + ID + " coeff : " + coeff_surface);
if (centre = 1){
centre_ville <- true;
color <- #red;
}
else{color <- #blue;}
}
}
list<building> residential_buildings <- building where (not empty(living_places inter each.types));
list<building> university_buildings <- building where (not empty(study_places inter each.types));
list<building> work_buildings <- building where (not empty(work_places inter each.types));
list<building> leisure_buildings <- building where (not empty(leisure_places inter each.types));
list<building> eat_buildings <- building where (not empty(eating_places inter each.types));
list<building> tourism_buildings <- building where (not empty(tourism_places inter each.types));
// placement des agents par quartier
int normalized_delivery_number;
int number_of_delivery;
if city = "Marseille"{number_of_delivery <- 850;}
if city = "Toulouse"{number_of_delivery <- 570;}
string file_path <- "../results/" + city + "/synthetic_population";
if test_population{file_path <- file_path + "_test";}
//
loop quart over: quartier {
write("population quartier " + quart.ID);
float cyclist_proportion;
// définition de la proportion de cyclistes parmi la population totale
if quart.centre_ville{ // proportion de cyclistes en centre-ville deux fois plus élevée (3.9%) qu'en périphérie (2.2%)
cyclist_proportion <- 0.039;
normalized_delivery_number <- 2 * int(number_of_delivery / (length(quartier) + length(quartier where each.centre_ville)));
}
else{
cyclist_proportion <- 0.022;
normalized_delivery_number <- int(number_of_delivery / (length(quartier) + length(quartier where each.centre_ville)));
}
int number_of_workers;
if city = "Marseille"{number_of_workers <- int(quart.active_pop * 0.013);} // source particulière : INSEE
if city = "Toulouse"{number_of_workers <- int(quart.active_pop * cyclist_proportion);}
int number_of_students <- int(quart.students_pop * cyclist_proportion);
int number_of_leisures <- int((quart.retired_pop + quart.without_job_pop) * cyclist_proportion);
if test_population {
number_of_workers <- int(number_of_workers / 20);
number_of_students <- int(number_of_students / 20);
number_of_leisures <- int(number_of_leisures / 20);
normalized_delivery_number <- int(normalized_delivery_number / 20);
}
create worker number: number_of_workers{
living_place <- one_of (residential_buildings where (each overlaps quart));
location <- any_location_in (living_place);
destination_place <- rnd_choice(gravitational_model(living_place, work_buildings where (each.location distance_to living_place < 15000 #m), worker_adaptative_coeff));
int_go <- int(gauss(120, 50)); // distribution gaussienne de l'heure de départ entre 6am et 10am
go_out_hour <- int(int_go / 60) + 6;
go_out_min <- int((int_go - (go_out_hour - 6) * 60) / 5) * 5;
int_home <- int(gauss(120, 50));
go_home_hour <- int(int_home / 60) + 15;
go_home_min <- int((int_home - (go_home_hour - 15) * 60) / 5) * 5;
save [go_out_hour, go_out_min, go_home_hour, go_home_min, living_place.id, destination_place.id] to: file_path + "/worker.csv" type:"csv" rewrite: false;
}
create student number: number_of_students {
living_place <- one_of (residential_buildings where (each overlaps quart));
location <- any_location_in (living_place);
destination_place <- rnd_choice(gravitational_model(living_place, university_buildings where (each.location distance_to living_place < 15000 #m), student_adaptative_coeff));
int_go <- int(gauss(90, 40));
go_out_hour <- int(int_go / 60) + 6;
go_out_min <- int((int_go - (go_out_hour - 6) * 60) / 5) * 5;
int_home <- int(gauss(90, 40));
go_home_hour <- int(int_home / 60) + 15;
go_home_min <- int((int_home - (go_home_hour - 15) * 60) / 5) * 5;
save [go_out_hour, go_out_min, go_home_hour, go_home_min, living_place.id, destination_place.id] to: file_path + "/student.csv" type:"csv" rewrite: false;
}
create leisure number: number_of_leisures {
living_place <- one_of (residential_buildings where (each overlaps quart));
location <- any_location_in (living_place);
destination_place <- rnd_choice(gravitational_model(living_place, leisure_buildings where (each.location distance_to living_place < 15000 #m), leisure_adaptative_coeff));
go_out_hour <- rnd(9, 12);
go_out_min <- rnd(0, 59, 5);
go_home_hour <- rnd(go_out_hour + 2, 21);
go_home_min <- rnd(0, 59, 5);
save [go_out_hour, go_out_min, go_home_hour, go_home_min, living_place.id, destination_place.id] to: file_path + "/leisure.csv" type:"csv" rewrite: false;
}
create delivery number: normalized_delivery_number {
living_place <- one_of (residential_buildings where (each overlaps quart));
location <- any_location_in (living_place);
if(rnd(1.0) <= 0.40){
midi <- true;
go_out_hour_midi <- rnd(hour_early_delivery_midi_start, hour_late_delivery_midi_start - 1);
go_out_min_midi <- rnd(0, 59, 5);
restaurant_1 <- rnd_choice(gravitational_model(living_place, eat_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
residential_place_1 <- rnd_choice(gravitational_model(restaurant_1, residential_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
restaurant_2 <- rnd_choice(gravitational_model(residential_place_1, eat_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
residential_place_2 <- rnd_choice(gravitational_model(restaurant_2, residential_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
restaurant_3 <- rnd_choice(gravitational_model(residential_place_2, eat_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
residential_place_3 <- rnd_choice(gravitational_model(restaurant_3, residential_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
save [go_out_hour_midi, go_out_min_midi, living_place.id, restaurant_1.id, residential_place_1.id, restaurant_2.id, residential_place_2.id, restaurant_3.id,
residential_place_3.id]
to: file_path + "/delivery_midi.csv" type:"csv" rewrite: false;
}
else {
midi <- false;
go_out_hour_soir <- rnd(hour_early_delivery_soir_start, hour_late_delivery_soir_start - 1);
go_out_min_soir <- rnd(0, 59, 5);
restaurant_1 <- rnd_choice(gravitational_model(living_place, eat_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
residential_place_1 <- rnd_choice(gravitational_model(restaurant_1, residential_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
restaurant_2 <- rnd_choice(gravitational_model(residential_place_1, eat_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
residential_place_2 <- rnd_choice(gravitational_model(restaurant_2, residential_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
restaurant_3 <- rnd_choice(gravitational_model(residential_place_2, eat_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
residential_place_3 <- rnd_choice(gravitational_model(restaurant_3, residential_buildings where (each.location distance_to living_place < 5000 #m), delivery_adaptative_coeff));
save [go_out_hour_soir, go_out_min_soir, living_place.id, restaurant_1.id, residential_place_1.id, restaurant_2.id, residential_place_2.id, restaurant_3.id,
residential_place_3.id]
to: file_path + "/delivery_soir.csv" type:"csv" rewrite: false;
}
}
}
write("Population de cyclistes à " + city + " :");
write("nombre de travailleurs : " + length(worker));
write("nombre d'étudiants : " + length(student));
write("nombre d'agents loisir : " + length(leisure));
write("nombre d'agents livreurs : " + length(delivery));
}
}
species building {
int id;
string type;
string types_str;
list<string> types;
float height;
rgb color <- #gray;
aspect base {
draw shape color: color ;
}
}
species quartier {
int ID;
string name;
int active_pop;
int students_pop;
int retired_pop;
int inactive_pop;
int without_job_pop;
int centre;
bool centre_ville; // si true : proportion de vélos 2x plus importante
rgb color;
aspect base {
draw shape width: 6;
}
}
species people skills: [moving] {
rgb color;
building living_place <- nil;
building destination_place <- nil;
int go_out_hour;
int go_out_min;
int go_home_hour;
int go_home_min;
map<building, float> gravitational_model(building starting_place, list<building> destination_to_choose, float adaptative_coeff){
// À partir d'une location de départ starting_place, choisit une destination parmi la liste destination_to_choose, selon un modèle gravitaire étalonné par adaptative_coeff
list<float> proba_list;
loop build over:destination_to_choose{
proba_list << exp(- adaptative_coeff * (starting_place distance_to build));
}
return create_map(destination_to_choose, proba_list); // retourne une map avec en clé la liste de buildings candidats, et en valeur la probabilité d'affectation du building
}
aspect base{
draw circle(6) color: color border: #black;
}
}
species worker parent: people {
rgb color <- #black;
int int_go min: 0 max: 240;
int int_home min: 0 max: 240;
}
species student parent: people{
rgb color <- #lightgreen;
int int_go min: 0 max: 180;
int int_home min: 0 max: 180;
}
species leisure parent: people{
rgb color <- #pink;
}
species delivery parent: people{
building restaurant_1;
building restaurant_2;
building restaurant_3;
building residential_place_1;
building residential_place_2;
building residential_place_3;
bool midi;
int go_out_hour_midi;
int go_out_min_midi;
int go_out_hour_soir;
int go_out_min_soir;
rgb color <- #red;
}
experiment population_generation type: gui {
parameter "Earliest hour to start leisure" var: hour_early_leisure_start category: "Leisure" min: 8 max: 13;
parameter "Latest hour to start leisure" var: hour_late_leisure_start category: "Leisure" min: 12 max: 18;
parameter "Earliest hour to end leisure" var: hour_early_leisure_end category: "Leisure" min: 11 max: 17;
parameter "Latest hour to end leisure" var: hour_late_leisure_end category: "Leisure" min: 15 max: 21;
output{
display quartiers{
species quartier;
//species building;
}
display travel_distance {
chart "Distribution de la distance de trajet des travailleurs" type: histogram background: #lightgrey size: {0.5, 0.5} position: {0, 0}{
data "0 - 1 km" value: worker count (each.living_place distance_to each.destination_place < 1000 #m) color: #blue;
data "1 - 2 km" value: worker count (each.living_place distance_to each.destination_place >= 1000 #m and each.living_place distance_to each.destination_place < 2000 #m) color: #blue;
data "2 - 3 km" value: worker count (each.living_place distance_to each.destination_place >= 2000 #m and each.living_place distance_to each.destination_place < 3000 #m) color: #blue;
data "3 - 4 km" value: worker count (each.living_place distance_to each.destination_place >= 3000 #m and each.living_place distance_to each.destination_place < 4000 #m) color: #blue;
data "4 - 5 km" value: worker count (each.living_place distance_to each.destination_place >= 4000 #m and each.living_place distance_to each.destination_place < 5000 #m) color: #blue;
data "5 - 6 km" value: worker count (each.living_place distance_to each.destination_place >= 5000 #m and each.living_place distance_to each.destination_place < 6000 #m) color: #blue;
data "6 - 7 km" value: worker count (each.living_place distance_to each.destination_place >= 6000 #m and each.living_place distance_to each.destination_place < 7000 #m) color: #blue;
data "7 - 8 km" value: worker count (each.living_place distance_to each.destination_place >= 7000 #m and each.living_place distance_to each.destination_place < 8000 #m) color: #blue;
data "8 - 9 km" value: worker count (each.living_place distance_to each.destination_place >= 8000 #m and each.living_place distance_to each.destination_place < 9000 #m) color: #blue;
data "9 - 10 km" value: worker count (each.living_place distance_to each.destination_place >= 9000 #m and each.living_place distance_to each.destination_place < 10000 #m) color: #blue;
data "10 - 11 km" value: worker count (each.living_place distance_to each.destination_place >= 10000 #m and each.living_place distance_to each.destination_place < 11000 #m) color: #blue;
data "11 - 12 km" value: worker count (each.living_place distance_to each.destination_place >= 11000 #m and each.living_place distance_to each.destination_place < 12000 #m) color: #blue;
data "12 - 13 km" value: worker count (each.living_place distance_to each.destination_place >= 12000 #m and each.living_place distance_to each.destination_place < 13000 #m) color: #blue;
data "13 - 14 km" value: worker count (each.living_place distance_to each.destination_place >= 13000 #m and each.living_place distance_to each.destination_place < 14000 #m) color: #blue;
data "14 - 15 km" value: worker count (each.living_place distance_to each.destination_place >= 14000 #m and each.living_place distance_to each.destination_place < 15000 #m) color: #blue;
data "15 - 16 km" value: worker count (each.living_place distance_to each.destination_place >= 15000 #m and each.living_place distance_to each.destination_place < 16000 #m) color: #blue;
data "16 - 17 km" value: worker count (each.living_place distance_to each.destination_place >= 16000 #m and each.living_place distance_to each.destination_place < 17000 #m) color: #blue;
data "17 - 18 km" value: worker count (each.living_place distance_to each.destination_place >= 17000 #m and each.living_place distance_to each.destination_place < 18000 #m) color: #blue;
data "18 - 19 km" value: worker count (each.living_place distance_to each.destination_place >= 18000 #m and each.living_place distance_to each.destination_place < 19000 #m) color: #blue;
data "19 - 20 km" value: worker count (each.living_place distance_to each.destination_place >= 19000 #m and each.living_place distance_to each.destination_place < 20000 #m) color: #blue;
}
chart "Distribution de la distance de trajet des étudiants" type: histogram background: #lightgrey size: {0.5, 0.5} position: {0, 0.5}{
data "0 - 1 km" value: student count (each.living_place distance_to each.destination_place < 1000 #m) color: #blue;
data "1 - 2 km" value: student count (each.living_place distance_to each.destination_place >= 1000 #m and each.living_place distance_to each.destination_place < 2000 #m) color: #blue;
data "2 - 3 km" value: student count (each.living_place distance_to each.destination_place >= 2000 #m and each.living_place distance_to each.destination_place < 3000 #m) color: #blue;
data "3 - 4 km" value: student count (each.living_place distance_to each.destination_place >= 3000 #m and each.living_place distance_to each.destination_place < 4000 #m) color: #blue;
data "4 - 5 km" value: student count (each.living_place distance_to each.destination_place >= 4000 #m and each.living_place distance_to each.destination_place < 5000 #m) color: #blue;
data "5 - 6 km" value: student count (each.living_place distance_to each.destination_place >= 5000 #m and each.living_place distance_to each.destination_place < 6000 #m) color: #blue;
data "6 - 7 km" value: student count (each.living_place distance_to each.destination_place >= 6000 #m and each.living_place distance_to each.destination_place < 7000 #m) color: #blue;
data "7 - 8 km" value: student count (each.living_place distance_to each.destination_place >= 7000 #m and each.living_place distance_to each.destination_place < 8000 #m) color: #blue;
data "8 - 9 km" value: student count (each.living_place distance_to each.destination_place >= 8000 #m and each.living_place distance_to each.destination_place < 9000 #m) color: #blue;
data "9 - 10 km" value: student count (each.living_place distance_to each.destination_place >= 9000 #m and each.living_place distance_to each.destination_place < 10000 #m) color: #blue;
data "10 - 11 km" value: student count (each.living_place distance_to each.destination_place >= 10000 #m and each.living_place distance_to each.destination_place < 11000 #m) color: #blue;
data "11 - 12 km" value: student count (each.living_place distance_to each.destination_place >= 11000 #m and each.living_place distance_to each.destination_place < 12000 #m) color: #blue;
data "12 - 13 km" value: student count (each.living_place distance_to each.destination_place >= 12000 #m and each.living_place distance_to each.destination_place < 13000 #m) color: #blue;
data "13 - 14 km" value: student count (each.living_place distance_to each.destination_place >= 13000 #m and each.living_place distance_to each.destination_place < 14000 #m) color: #blue;
data "14 - 15 km" value: student count (each.living_place distance_to each.destination_place >= 14000 #m and each.living_place distance_to each.destination_place < 15000 #m) color: #blue;
data "15 - 16 km" value: student count (each.living_place distance_to each.destination_place >= 15000 #m and each.living_place distance_to each.destination_place < 16000 #m) color: #blue;
data "16 - 17 km" value: student count (each.living_place distance_to each.destination_place >= 16000 #m and each.living_place distance_to each.destination_place < 17000 #m) color: #blue;
data "17 - 18 km" value: student count (each.living_place distance_to each.destination_place >= 17000 #m and each.living_place distance_to each.destination_place < 18000 #m) color: #blue;
data "18 - 19 km" value: student count (each.living_place distance_to each.destination_place >= 18000 #m and each.living_place distance_to each.destination_place < 19000 #m) color: #blue;
data "19 - 20 km" value: student count (each.living_place distance_to each.destination_place >= 19000 #m and each.living_place distance_to each.destination_place < 20000 #m) color: #blue;
}
chart "Distribution de la distance de trajet des leisure" type: histogram background: #lightgrey size: {0.5, 0.5} position: {0.5, 0}{
data "0 - 1 km" value: leisure count (each.living_place distance_to each.destination_place < 1000 #m) color: #blue;
data "1 - 2 km" value: leisure count (each.living_place distance_to each.destination_place >= 1000 #m and each.living_place distance_to each.destination_place < 2000 #m) color: #blue;
data "2 - 3 km" value: leisure count (each.living_place distance_to each.destination_place >= 2000 #m and each.living_place distance_to each.destination_place < 3000 #m) color: #blue;
data "3 - 4 km" value: leisure count (each.living_place distance_to each.destination_place >= 3000 #m and each.living_place distance_to each.destination_place < 4000 #m) color: #blue;
data "4 - 5 km" value: leisure count (each.living_place distance_to each.destination_place >= 4000 #m and each.living_place distance_to each.destination_place < 5000 #m) color: #blue;
data "5 - 6 km" value: leisure count (each.living_place distance_to each.destination_place >= 5000 #m and each.living_place distance_to each.destination_place < 6000 #m) color: #blue;
data "6 - 7 km" value: leisure count (each.living_place distance_to each.destination_place >= 6000 #m and each.living_place distance_to each.destination_place < 7000 #m) color: #blue;
data "7 - 8 km" value: leisure count (each.living_place distance_to each.destination_place >= 7000 #m and each.living_place distance_to each.destination_place < 8000 #m) color: #blue;
data "8 - 9 km" value: leisure count (each.living_place distance_to each.destination_place >= 8000 #m and each.living_place distance_to each.destination_place < 9000 #m) color: #blue;
data "9 - 10 km" value: leisure count (each.living_place distance_to each.destination_place >= 9000 #m and each.living_place distance_to each.destination_place < 10000 #m) color: #blue;
data "10 - 11 km" value: leisure count (each.living_place distance_to each.destination_place >= 10000 #m and each.living_place distance_to each.destination_place < 11000 #m) color: #blue;
data "11 - 12 km" value: leisure count (each.living_place distance_to each.destination_place >= 11000 #m and each.living_place distance_to each.destination_place < 12000 #m) color: #blue;
data "12 - 13 km" value: leisure count (each.living_place distance_to each.destination_place >= 12000 #m and each.living_place distance_to each.destination_place < 13000 #m) color: #blue;
data "13 - 14 km" value: leisure count (each.living_place distance_to each.destination_place >= 13000 #m and each.living_place distance_to each.destination_place < 14000 #m) color: #blue;
data "14 - 15 km" value: leisure count (each.living_place distance_to each.destination_place >= 14000 #m and each.living_place distance_to each.destination_place < 15000 #m) color: #blue;
data "15 - 16 km" value: leisure count (each.living_place distance_to each.destination_place >= 15000 #m and each.living_place distance_to each.destination_place < 16000 #m) color: #blue;
data "16 - 17 km" value: leisure count (each.living_place distance_to each.destination_place >= 16000 #m and each.living_place distance_to each.destination_place < 17000 #m) color: #blue;
data "17 - 18 km" value: leisure count (each.living_place distance_to each.destination_place >= 17000 #m and each.living_place distance_to each.destination_place < 18000 #m) color: #blue;
data "18 - 19 km" value: leisure count (each.living_place distance_to each.destination_place >= 18000 #m and each.living_place distance_to each.destination_place < 19000 #m) color: #blue;
data "19 - 20 km" value: leisure count (each.living_place distance_to each.destination_place >= 19000 #m and each.living_place distance_to each.destination_place < 20000 #m) color: #blue;
}
chart "Distance moyenne des trajets en fonction du motif" type: histogram background: #lightgrey size: {0.5, 0.5} position: {0.5, 0.5} {
list<float> travel_distance;
if(length(worker) != 0){
loop work over: worker{
travel_distance << work.living_place distance_to work.destination_place;
}
data "Travail" value: sum(travel_distance) / length(worker) color: #blue;
}
if(length(student) != 0){
travel_distance <- [];
loop stud over: student{
travel_distance << stud.living_place distance_to stud.destination_place;
}
data "Etude" value: sum(travel_distance) / length(student) color: #blue;
}
if(length(leisure) != 0){
travel_distance <- [];
loop leis over: leisure{
travel_distance << leis.living_place distance_to leis.destination_place;
}
data "Loisir" value: sum(travel_distance) / length(leisure) color: #blue;
}
if (length(delivery) != 0){
travel_distance <- [];
loop deli over: delivery {
travel_distance << deli.living_place distance_to deli.restaurant_1;
}
data "Distance domicile / restaurant 1" value: sum(travel_distance) / length(delivery) color: #blue;
travel_distance <- [];
loop deli over: delivery {
travel_distance << deli.restaurant_1 distance_to deli.residential_place_1;
}
data "Distance resto1 / resi1" value: sum(travel_distance) / length(delivery) color: #blue;
}
}
}
display hour_travel {
chart "Distribution de l'heure de départ des agents worker" type: histogram background: #lightgrey size: {0.5, 0.5} position: {0, 0}{
loop i from: 0 to: 240 step: 5{
int hour_go <- int(i / 60);
data string(i) value: worker count (each.go_out_hour = int(i / 60) + 6 and each.go_out_min = int((i - (each.go_out_hour - 6) * 60) / 5) * 5) color: #blue;
}
}
chart "Distribution de l'heure de départ des agents student" type: histogram background: #lightgrey size: {0.5, 0.5} position: {0.5, 0.5}{
loop i from: 0 to: 180 step: 5{
int hour_go <- int(i / 60);
data string(i) value: student count (each.go_out_hour = int(i / 60) + 6 and each.go_out_min = int((i - (each.go_out_hour - 6) * 60) / 5) * 5) color: #blue;
}
}
}
}
}
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/*
* This model generates the daily trips (non-participatory trip = the shortest path) of a synthetic population of cyclists in Marseille
* The living place, destination place and hour of leaving / coming home are already defined for each agent in the synthetic population
*
*
*/
global {
bool test_population <- false;
file bound <- shape_file("../includes/Marseille/boundary_Marseille.shp");
file shape_file_buildings;
file shape_file_roads;
bool workers <- false;
bool students <- true;
bool leisures <- false;
bool deliveries <- false;
file worker_csv;
file student_csv;
file leisure_csv;
file delivery_midi_csv;
file delivery_soir_csv;
geometry shape <- envelope(bound);
int time_step <- 5; // time step in seconds
float step <- time_step #s;
date starting_date <- date(2021, 5, 27, 5, 30);
float bicycle_speed <- 10 #km / #h;
graph the_graph;
map<road,float> road_weights;
reflex save_trips when: current_date.hour = 23 and current_date.minute = 55{
list<position_agent> list_of_positions_aller_workers;
list<position_agent> list_of_positions_retour_workers;
ask worker {
loop pos over: list_of_positions_aller{
list_of_positions_aller_workers << pos;
}
loop pos over: list_of_positions_retour{
list_of_positions_retour_workers << pos;
}
}
save list_of_positions_aller_workers to: "../results/Marseille/worker/aller_worker/positions_aller_worker.shp" type: shp
attributes: ["time"::date_of_presence, "agent"::name_of_agent] crs: "2154";
save list_of_positions_retour_workers to: "../results/Marseille/worker/retour_worker/positions_retour_worker.shp" type: shp
attributes: ["time"::date_of_presence, "agent"::name_of_agent] crs: "2154";
list<position_agent> list_of_positions_aller_students;
list<position_agent> list_of_positions_retour_students;
ask student {
loop pos over: list_of_positions_aller{
list_of_positions_aller_students << pos;
}
loop pos over: list_of_positions_retour{
list_of_positions_retour_students << pos;
}
}
save list_of_positions_aller_students to: "../results/Marseille/student/aller_student/positions_aller_student.shp" type: shp
attributes: ["time"::date_of_presence, "agent"::name_of_agent] crs: "2154";
save list_of_positions_retour_students to: "../results/Marseille/student/retour_student/positions_retour_student.shp" type: shp
attributes: ["time"::date_of_presence, "agent"::name_of_agent] crs: "2154";
list<position_agent> list_of_positions_aller_leisures;
list<position_agent> list_of_positions_retour_leisures;
ask leisure {
loop pos over: list_of_positions_aller{
list_of_positions_aller_leisures << pos;
}
loop pos over: list_of_positions_retour{
list_of_positions_retour_leisures << pos;
}
}
save list_of_positions_aller_leisures to: "../results/Marseille/leisure/aller_leisure/positions_aller_leisure.shp" type: shp
attributes: ["time"::date_of_presence, "agent"::name_of_agent] crs: "2154";
save list_of_positions_retour_leisures to: "../results/Marseille/leisure/retour_leisure/positions_retour_leisure.shp" type: shp
attributes: ["time"::date_of_presence, "agent"::name_of_agent] crs: "2154";
}
reflex stop_simulation when: current_date.hour = 23 and current_date.minute = 55 {
do pause;
}
init{
shape_file_buildings <- shape_file("../includes/Marseille/buildings.shp"); // building contenant les data osm, ign, pois
shape_file_roads <- shape_file("../includes/Marseille/SHP Marseille/roads_cyclists.shp");
if (test_population){
write("Marseille : population test");
worker_csv <- csv_file( "../results/Marseille/synthetic_population_test/worker.csv",true);
student_csv <- csv_file( "../results/Marseille/synthetic_population_test/student.csv",true);
leisure_csv <- csv_file( "../results/Marseille/synthetic_population_test/leisure.csv",true);
delivery_midi_csv <- csv_file( "../results/Marseille/synthetic_population_test/delivery_midi.csv",true);
delivery_soir_csv <- csv_file( "../results/Marseille/synthetic_population_test/delivery_soir.csv",true);
}
else{
write("Marseille : population reelle");
worker_csv <- csv_file( "../results/Marseille/synthetic_population/worker.csv",true);
student_csv <- csv_file( "../results/Marseille/synthetic_population/student.csv",true);
leisure_csv <- csv_file( "../results/Marseille/synthetic_population/leisure.csv",true);
delivery_midi_csv <- csv_file( "../results/Marseille/synthetic_population/delivery_midi.csv",true);
delivery_soir_csv <- csv_file( "../results/Marseille/synthetic_population/delivery_soir.csv",true);
}
create building from: shape_file_buildings {
types <- types_str split_with ",";
}
create road from: shape_file_roads with: [id::int(get("id")), fclass::read ("fclass"), speed_coeff::float(get("s_coeff")), maxspeed::int(get("maxspeed"))];
road_weights <- road as_map (each::each.shape.perimeter / each.speed_coeff); // speed_coeff depends on the type of road
the_graph <- as_edge_graph(road);
the_graph <- the_graph with_weights road_weights;
map<int,building> building_map <- building as_map (each.id::each);
if workers{
write("instanciate workers");
create worker from: worker_csv with:[go_out_hour::int(get("go_out_hour")), go_out_min::int(get("go_out_min")), go_home_hour::int(get("go_home_hour")), go_home_min::int(get("go_home_min")),
id_living_place::int(get("living_place.id")), id_destination_place::int(get("destination_place.id"))]{
date_of_leaving_home <- date(2021, 5, 27, go_out_hour, go_out_min);
date_of_leaving_dest <- date(2021, 5, 27, go_home_hour, go_home_min);
living_place <- building_map[id_living_place];
location <- any_location_in (living_place);
destination_place <- building_map[id_destination_place];
speed <- bicycle_speed;
objective <- "resting";
is_on_road <- false;
}
}
if students{
write("instanciate students");
create student from: student_csv with:[go_out_hour::int(get("go_out_hour")), go_out_min::int(get("go_out_min")), go_home_hour::int(get("go_home_hour")), go_home_min::int(get("go_home_min")),
id_living_place::int(get("living_place.id")), id_destination_place::int(get("destination_place.id"))]{
date_of_leaving_home <- date(2021, 5, 27, go_out_hour, go_out_min);
date_of_leaving_dest <- date(2021, 5, 27, go_home_hour, go_home_min);
living_place <- building_map[id_living_place];
location <- any_location_in (living_place);
destination_place <- building_map[id_destination_place];
speed <- bicycle_speed;
objective <- "resting";
is_on_road <- false;
}
}
if leisures{
write("instanciate leisures");
create leisure from: leisure_csv with:[go_out_hour::int(get("go_out_hour")), go_out_min::int(get("go_out_min")), go_home_hour::int(get("go_home_hour")), go_home_min::int(get("go_home_min")),
id_living_place::int(get("living_place.id")), id_destination_place::int(get("destination_place.id"))]{
date_of_leaving_home <- date(2021, 5, 27, go_out_hour, go_out_min);
date_of_leaving_dest <- date(2021, 5, 27, go_home_hour, go_home_min);
living_place <- building_map[id_living_place];
location <- any_location_in (living_place);
destination_place <- building_map[id_destination_place];
speed <- bicycle_speed;
objective <- "resting";
is_on_road <- false;
}
}
}
}
species building {
int id;
string type;
string types_str;
list<string> types;
float height;
rgb color <- #gray;
aspect base {
draw shape color: color ;
}
}
species road {
int id;
string fclass;
int maxspeed;
float speed_coeff;
bool starting_road_aller;
bool starting_road_retour;
rgb color <- #orange;
aspect base {
draw shape color: color width: 1;
}
}
species people skills: [moving] {
rgb color;
int id_living_place;
int id_destination_place;
building living_place <- nil;
building destination_place <- nil;
path path_followed;
int go_out_hour;
int go_out_min;
date date_of_leaving_home;
date date_of_arriving_dest;
path path_aller;
list<road> list_of_roads_aller;
list<position_agent> list_of_positions_aller;
int go_home_hour;
int go_home_min;
date date_of_leaving_dest;
date date_of_arriving_home;
path path_retour;
list<position_agent> list_of_positions_retour;
list<road> list_of_roads_retour;
bool is_on_road;
string objective;
point the_target <- nil;
reflex time_to_leave when: current_date.hour = go_out_hour and current_date.minute = go_out_min and objective = "resting"{
objective <- "working";
the_target <- any_location_in (destination_place);
path_aller <- path_between(the_graph, location, the_target);
if path_aller != nil{
loop rd over: path_aller.edges{
list_of_roads_aller << road(int(rd));
}
}
list_of_roads_aller[0].starting_road_aller <- true;
is_on_road <- true;
}
reflex time_to_go_home when: current_date.hour = go_home_hour and current_date.minute = go_home_min and objective = "working"{
objective <- "resting";
the_target <- any_location_in (living_place);
path_retour <- path_between(the_graph, location, the_target);
if path_retour != nil{
loop rd over: path_retour.edges{
list_of_roads_retour << road(int(rd));
}
}
list_of_roads_retour[0].starting_road_retour <- true;
is_on_road <- true;
}
reflex move when: the_target != nil {
point current_location <- location;
create position_agent{
location <- current_location;
date_of_presence <- current_date;
name_of_agent <- string(myself);
}
if objective = "working"{
list_of_positions_aller << last(position_agent);
}
if objective = "resting"{
list_of_positions_retour << last(position_agent);
}
path_followed <- goto(target: the_target, on: the_graph, return_path: true);
if the_target = location {
the_target <- nil;
is_on_road <- false;
if (objective = "working"){
date_of_arriving_dest <- date(2021, 5, 27, current_date.hour, current_date.minute, current_date.second);
}
if (objective = "resting"){
date_of_arriving_home <- date(2021, 5, 27, current_date.hour, current_date.minute, current_date.second);
}
}
}
aspect base{
draw circle(10) color: color border: #black;
}
}
species worker parent: people {
rgb color <- #black;
}
species student parent: people{
rgb color <- #green;
}
species leisure parent: people{
rgb color <- #pink;
}
species position_agent {
date date_of_presence;
string name_of_agent;
}
experiment bike_traffic type: gui {
output{
display city_display type: opengl{
//species building aspect: base;
species road aspect: base;
species worker aspect: base;
species student aspect: base;
species leisure aspect: base;
}
display nb_persons_on_road refresh: every(2#cycles){
chart "Nombre d'agents sur les routes" type: series {
data "Nombre d'agents sur les routes" value: worker count (each.is_on_road = true) + student count (each.is_on_road = true) + leisure count (each.is_on_road = true);
}
}
/*
display pollution type: opengl{
species pollution_cell aspect: pollution transparency: 0;
}
*
display hour_travel {
chart "Distribution de l'heure de départ des agents worker" type: histogram background: #lightgrey{
loop i from: 0 to: 240 step: 5{
int hour_go <- int(i / 60);
data string(i) value: worker count (each.go_out_hour = int(i / 60) + 6 and each.go_out_min = int((i - (each.go_out_hour - 6) * 60) / 5) * 5) color: #blue;
}
}
}
*
*/
monitor "Date" value: current_date ;
}
}
\ No newline at end of file
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/*
* This model generates pollution measures from the trips generated by 'travel agents'. Pollution data are extracted from a hourly pollution model from AtmoSud (date: 27/05/2021)
*
*/
global {
file bound <- shape_file("../includes/Marseille/boundary_Marseille.shp");
bool workers <- false; // une seule population en 'true' à la fois pour le stockage des mesures par type d'agent
bool students <- false;
bool leisures <- true;
bool measure_NO2 <- true;
bool measure_O3 <- true;
bool measure_PM10 <- true;
bool measure_PM25 <- true;
geometry shape <- envelope(bound);
// coordonees des rasters de pollution
float min_x <- 889462.50000;
float min_y <- 6236287.50000;
float max_x <- 905062.50000;
float max_y <- 6254412.50000;
int compteur_ID <- 0;
init{
// mise en mémoire du cube de pollution NO2, O3, PM10, PM25 (24 rasters horaires)
list<matrix<float>> NO2_rasters;
list<matrix<float>> O3_rasters;
list<matrix<float>> PM10_rasters;
list<matrix<float>> PM25_rasters;
if measure_NO2 {
// raster heure 0 manquant pour la journée du 27
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
NO2_rasters << pollution_raster_float;
loop i from: 1 to: 23{
string path_grid;
if (i < 10){
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_NO2_202105270' + i + '_202105270' + i + '.tif';
}
else{
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_NO2_20210527' + i + '_20210527' + i + '.tif';
}
matrix my_data <- grid_file(path_grid) as_matrix({624, 725});
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
loop j from: 0 to: 623{
loop k from: 0 to: 724{
pollution_raster_float[j, k] <- float (my_data[j, k] get("grid_value"));
}
}
write ('raster NO2 ' + i + ' chargé');
write('max: ' + max(pollution_raster_float));
NO2_rasters << pollution_raster_float;
}
}
if measure_O3 {
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
O3_rasters << pollution_raster_float;
loop i from: 1 to: 23{
string path_grid;
if (i < 10){
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_O3_202105270' + i + '_202105270' + i + '.tif';
}
else{
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_O3_20210527' + i + '_20210527' + i + '.tif';
}
matrix my_data <- grid_file(path_grid) as_matrix({624, 725});
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
loop j from: 0 to: 623{
loop k from: 0 to: 724{
pollution_raster_float[j, k] <- float (my_data[j, k] get("grid_value"));
}
}
write ('raster O3 ' + i + ' chargé');
write('max: ' + max(pollution_raster_float));
O3_rasters << pollution_raster_float;
}
}
if measure_PM10 {
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
PM10_rasters << pollution_raster_float;
loop i from: 1 to: 23{
string path_grid;
if (i < 10){
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_PM10_202105270' + i + '_202105270' + i + '.tif';
}
else{
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_PM10_20210527' + i + '_20210527' + i + '.tif';
}
matrix my_data <- grid_file(path_grid) as_matrix({624, 725});
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
loop j from: 0 to: 623{
loop k from: 0 to: 724{
pollution_raster_float[j, k] <- float (my_data[j, k] get("grid_value"));
}
}
write ('raster PM10 ' + i + ' chargé');
write('max: ' + max(pollution_raster_float));
PM10_rasters << pollution_raster_float;
}
}
if measure_PM25 {
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
PM25_rasters << pollution_raster_float;
loop i from: 1 to: 23{
string path_grid;
if (i < 10){
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_PM25_202105270' + i + '_202105270' + i + '.tif';
}
else{
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_PM25_20210527' + i + '_20210527' + i + '.tif';
}
matrix my_data <- grid_file(path_grid) as_matrix({624, 725});
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
loop j from: 0 to: 623{
loop k from: 0 to: 724{
pollution_raster_float[j, k] <- float (my_data[j, k] get("grid_value"));
}
}
write ('raster PM25 ' + i + ' chargé');
write('max: ' + max(pollution_raster_float));
PM25_rasters << pollution_raster_float;
}
}
// generation des donnees de pollution pour chaque type d'agent
if workers{
write("generating workers measures");
create measure from: shape_file("../results/Marseille/worker/aller_worker/positions_aller_worker.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int worker_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(worker_number);
if (worker_number > 3000){do die;} // on calcule les mesures faites pour une majorité d'agent. le reste servira de test aux prédictions faites à partir de ces mesures
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/worker/workers_measures.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
create measure from: shape_file("../results/Marseille/worker/retour_worker/positions_retour_worker.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int worker_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(worker_number);
if (worker_number > 3000){do die;} // on calcule les mesures faites pour une majorité d'agent. le reste servira de test aux prédictions faites à partir de ces mesures
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/worker/workers_measures.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
}
if students{
write("generating students measures");
create measure from: shape_file("../results/Marseille/student/aller_student/positions_aller_student.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int student_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(student_number);
if (student_number > 1800){do die;} // on calcule les mesures faites pour une majorité d'agent. le reste servira de test aux prédictions faites à partir de ces mesures
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/student/students_measures.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
create measure from: shape_file("../results/Marseille/student/retour_student/positions_retour_student.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int student_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(student_number);
if (student_number > 1800){do die;} // on calcule les mesures faites pour une majorité d'agent. le reste servira de test aux prédictions faites à partir de ces mesures
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/student/students_measures.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
}
if leisures{
write("generating leisures measures");
create measure from: shape_file("../results/Marseille/leisure/aller_leisure/positions_aller_leisure.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int leisure_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(leisure_number);
if (leisure_number > 6200){do die;} // on calcule les mesures faites pour une majorité d'agent. le reste servira de test aux prédictions faites à partir de ces mesures
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/leisure/leisures_measures.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
create measure from: shape_file("../results/Marseille/leisure/retour_leisure/positions_retour_leisure.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int leisure_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(leisure_number);
if (leisure_number > 6200){do die;} // on calcule les mesures faites pour une majorité d'agent. le reste servira de test aux prédictions faites à partir de ces mesures
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/leisure/leisures_measures.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
}
}
}
species measure {
int ID;
string name_of_agent;
float longitude min: min_x max: max_x - 0.1;
float latitude min: min_y max: max_y - 0.1;
date time_of_measure;
float NO2_concentration;
float O3_concentration;
float PM10_concentration;
float PM25_concentration;
}
grid pollution_cell file: grid_file('../includes/Marseille/pollution_model/raster_dep13_NO2_2021052701_2021052701.tif'){
}
experiment bike_traffic type: gui {
}
\ No newline at end of file
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/*
* This model generates the environment close to the measures point
*
*/
global {
bool workers <- false;
bool students <- true;
bool leisures <- false;
file measures_workers_csv;
file measures_students_csv;
file measures_leisures_csv;
file bound <- shape_file("../includes/Marseille/boundary_Marseille.shp");
geometry shape <- envelope(bound);
file shape_file_buildings <- shape_file("../includes/Marseille/buildings_ign.shp");
file shape_file_vegetation <- shape_file("../includes/Marseille/environment/ZONE_DE_VEGETATION.shp");
file roads_ign <- shape_file("../includes/Marseille/environment/roads_ign.shp");
file primary_roads <- shape_file("../includes/Marseille/environment/primary_roads.shp");
init{
create building from: shape_file_buildings with: [height::float(read("HAUTEUR"))];
create road from: roads_ign;
list<road> rd_1_voie <- road where (each.NB_VOIES = 1);
list<road> rd_2_voie <- road where (each.NB_VOIES = 2);
list<road> rd_3_voie <- road where (each.NB_VOIES = 3);
list<road> rd_4_voie <- road where (each.NB_VOIES = 4);
list<road> rd_5_voie <- road where (each.NB_VOIES = 5);
list<road> rd_6_voie <- road where (each.NB_VOIES = 6);
list<road> list_rd_0_4_width <- road where (each.LARGEUR <= 4.0);
list<road> list_rd_4_6_width <- road where (each.LARGEUR > 4.0 and each.LARGEUR <= 6.0);
list<road> list_rd_6_8_width <- road where (each.LARGEUR > 6.0 and each.LARGEUR <= 8.0);
list<road> list_rd_8_max_width <- road where (each.LARGEUR > 8.0);
create primary_road from: primary_roads;
create vegetation from: shape_file_vegetation;
list<vegetation> list_bois <- vegetation where (each.NATURE = 'Bois');
list<vegetation> list_foret <- vegetation where (each.NATURE = 'Forêt fermée de conifères' or each.NATURE = 'Forêt fermée de feuillus'
or each.NATURE = 'Forêt fermée mixte' or each.NATURE = 'Forêt ouverte');
list<vegetation> list_haie <- vegetation where (each.NATURE = 'Haie');
if(workers){
measures_workers_csv <- csv_file("../results/Marseille/worker/workers_measures.csv",true);
create measure from: measures_workers_csv{
write(self.ID);
location <- point(to_GAMA_CRS({self.longitude, self.latitude}, 'EPSG:2154'));
geometry disque <- circle(50, location);
create environment {
ID <- myself.ID;
name_of_agent <- myself.name_of_agent;
longitude <- myself.longitude;
latitude <- myself.latitude;
loop build over: building overlapping disque{
float surface_inter <- (build inter disque).area;
buildings_volume <- buildings_volume + build.height * surface_inter;
}
loop rd over: rd_1_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_1 <- voie_1 + perimeter_inter;
}
loop rd over: rd_2_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_2 <- voie_2 + perimeter_inter;
}
loop rd over: rd_3_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_3 <- voie_3 + perimeter_inter;
}
loop rd over: rd_4_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_4 <- voie_4 + perimeter_inter;
}
loop rd over: rd_5_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_5 <- voie_5 + perimeter_inter;
}
loop rd over: rd_6_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_6 <- voie_6 + perimeter_inter;
}
loop rd over: list_rd_0_4_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_0_4_width <- road_0_4_width + perimeter_inter;
}
loop rd over: list_rd_4_6_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_4_6_width <- road_4_6_width + perimeter_inter;
}
loop rd over: list_rd_6_8_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_6_8_width <- road_6_8_width + perimeter_inter;
}
loop rd over: list_rd_8_max_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_8_max_width <- road_8_max_width + perimeter_inter;
}
loop veg over: list_bois overlapping disque{
float area_inter <- (veg inter disque).area;
bois <- bois + area_inter;
}
loop veg over: list_foret overlapping disque{
float area_inter <- (veg inter disque).area;
foret <- foret + area_inter;
}
loop veg over: list_haie overlapping disque{
float area_inter <- (veg inter disque).area;
haie <- haie + area_inter;
}
distance_to_main_road <- myself distance_to (primary_road closest_to myself);
}
}
ask environment {
save [ID, name_of_agent, longitude, latitude, buildings_volume, voie_1, voie_2, voie_3, voie_4, voie_5, voie_6, road_0_4_width, road_4_6_width, road_6_8_width, road_8_max_width, distance_to_main_road, bois, foret, haie]
to: "../results/Marseille/worker/workers_measures_environment.csv" type:"csv" rewrite: false;
}
}
if(students){
measures_students_csv <- csv_file("../results/Marseille/student/students_measures.csv",true);
create measure from: measures_students_csv{
write(self.ID);
location <- point(to_GAMA_CRS({self.longitude, self.latitude}, "EPSG:2154"));
geometry disque <- circle(50, location);
create environment {
ID <- myself.ID;
name_of_agent <- myself.name_of_agent;
longitude <- myself.longitude;
latitude <- myself.latitude;
loop build over: building overlapping disque{
float surface_inter <- (build inter disque).area;
buildings_volume <- buildings_volume + build.height * surface_inter;
}
loop rd over: rd_1_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_1 <- voie_1 + perimeter_inter;
}
loop rd over: rd_2_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_2 <- voie_2 + perimeter_inter;
}
loop rd over: rd_3_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_3 <- voie_3 + perimeter_inter;
}
loop rd over: rd_4_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_4 <- voie_4 + perimeter_inter;
}
loop rd over: rd_5_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_5 <- voie_5 + perimeter_inter;
}
loop rd over: rd_6_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_6 <- voie_6 + perimeter_inter;
}
loop rd over: list_rd_0_4_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_0_4_width <- road_0_4_width + perimeter_inter;
}
loop rd over: list_rd_4_6_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_4_6_width <- road_4_6_width + perimeter_inter;
}
loop rd over: list_rd_6_8_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_6_8_width <- road_6_8_width + perimeter_inter;
}
loop rd over: list_rd_8_max_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_8_max_width <- road_8_max_width + perimeter_inter;
}
loop veg over: list_bois overlapping disque{
float area_inter <- (veg inter disque).area;
bois <- bois + area_inter;
}
loop veg over: list_foret overlapping disque{
float area_inter <- (veg inter disque).area;
foret <- foret + area_inter;
}
loop veg over: list_haie overlapping disque{
float area_inter <- (veg inter disque).area;
haie <- haie + area_inter;
}
distance_to_main_road <- myself distance_to (primary_road closest_to myself);
}
}
ask environment {
save [ID, name_of_agent, longitude, latitude, buildings_volume, voie_1, voie_2, voie_3, voie_4, voie_5, voie_6, road_0_4_width, road_4_6_width, road_6_8_width, road_8_max_width, distance_to_main_road, bois, foret, haie]
to: "../results/Marseille/student/students_measures_environment.csv" type:"csv" rewrite: false;
}
}
if(leisures){
measures_leisures_csv <- csv_file("../results/Marseille/leisure/leisures_measures.csv",true);
create measure from: measures_leisures_csv{
write(self.ID);
location <- point(to_GAMA_CRS({self.longitude, self.latitude}, 'EPSG:2154'));
geometry disque <- circle(50, location);
create environment {
ID <- myself.ID;
name_of_agent <- myself.name_of_agent;
longitude <- myself.longitude;
latitude <- myself.latitude;
loop build over: building overlapping disque{
float surface_inter <- (build inter disque).area;
buildings_volume <- buildings_volume + build.height * surface_inter;
}
loop rd over: rd_1_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_1 <- voie_1 + perimeter_inter;
}
loop rd over: rd_2_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_2 <- voie_2 + perimeter_inter;
}
loop rd over: rd_3_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_3 <- voie_3 + perimeter_inter;
}
loop rd over: rd_4_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_4 <- voie_4 + perimeter_inter;
}
loop rd over: rd_5_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_5 <- voie_5 + perimeter_inter;
}
loop rd over: rd_6_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_6 <- voie_6 + perimeter_inter;
}
loop rd over: list_rd_0_4_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_0_4_width <- road_0_4_width + perimeter_inter;
}
loop rd over: list_rd_4_6_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_4_6_width <- road_4_6_width + perimeter_inter;
}
loop rd over: list_rd_6_8_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_6_8_width <- road_6_8_width + perimeter_inter;
}
loop rd over: list_rd_8_max_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_8_max_width <- road_8_max_width + perimeter_inter;
}
loop veg over: list_bois overlapping disque{
float area_inter <- (veg inter disque).area;
bois <- bois + area_inter;
}
loop veg over: list_foret overlapping disque{
float area_inter <- (veg inter disque).area;
foret <- foret + area_inter;
}
loop veg over: list_haie overlapping disque{
float area_inter <- (veg inter disque).area;
haie <- haie + area_inter;
}
distance_to_main_road <- myself distance_to (primary_road closest_to myself);
}
}
ask environment {
save [ID, name_of_agent, longitude, latitude, buildings_volume, voie_1, voie_2, voie_3, voie_4, voie_5, voie_6, road_0_4_width, road_4_6_width, road_6_8_width, road_8_max_width, distance_to_main_road, bois, foret, haie]
to: "../results/Marseille/leisure/leisures_measures_environment.csv" type:"csv" rewrite: false;
}
}
}
}
species measure { // seulement besoin de la localisation de la mesure, etant donne que l'environnement est suppose stationnaire
int ID;
string name_of_agent;
float longitude;
float latitude;
}
species environment{ // flotants correspondant à l'environnement dans un disque de 50m de rayon centré sur la mesure
int ID; // ID égal à celui de la mesure
string name_of_agent;
float longitude;
float latitude;
float road_0_4_width; // longueur de route dans le disque ayant comme attribut : largeur <= 4
float road_4_6_width; // longueur de route dans le disque ayant comme attribut : 4 < largeur <= 6
float road_6_8_width; // longueur de route dans le disque ayant comme attribut : 6 < largeur <= 8
float road_8_max_width; // longueur de route dans le disque ayant comme attribut : 8 < largeur
float voie_1;
float voie_2;
float voie_3;
float voie_4;
float voie_5;
float voie_6;
float buildings_volume;
float distance_to_main_road;
float bois; //surface de bois dans le disque
float foret;
float haie;
}
species road {
float LARGEUR;
int NB_VOIES;
}
species primary_road{
}
species building {
int id;
string type;
string types_str;
list<string> types;
float height;
}
species vegetation {
string NATURE; //Bois, Forêt fermée de conifères, Forêt fermée de feuillus, Forêt fermée mixte, Forêt ouverte, Haie, Lande ligneuse, Verger, Vigne (types BD TOPO)
}
experiment bike_traffic type: gui {
}
\ No newline at end of file
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/*
* This model generates pollution measures from the last quarter of trips generated by 'travel agents'. Pollution data are extracted from a hourly pollution model from AtmoSud (date: 27/05/2021)
* These measures will be compared to predicted measures
*
*/
global {
file bound <- shape_file("../includes/Marseille/boundary_Marseille.shp");
bool workers <- false; // une seule population en 'true' à la fois pour le stockage des mesures par type d'agent
bool students <- true;
bool leisures <- false;
bool measure_NO2 <- true;
bool measure_O3 <- true;
bool measure_PM10 <- true;
bool measure_PM25 <- true;
geometry shape <- envelope(bound);
// coordonees des rasters de pollution
float min_x <- 889462.50000;
float min_y <- 6236287.50000;
float max_x <- 905062.50000;
float max_y <- 6254412.50000;
int compteur_ID <- 0;
init{
// mise en mémoire du cube de pollution NO2, O3, PM10, PM25 (24 rasters horaires)
list<matrix<float>> NO2_rasters;
list<matrix<float>> O3_rasters;
list<matrix<float>> PM10_rasters;
list<matrix<float>> PM25_rasters;
if measure_NO2 {
// raster heure 0 manquant pour la journée du 27
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
NO2_rasters << pollution_raster_float;
loop i from: 1 to: 23{
string path_grid;
if (i < 10){
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_NO2_202105270' + i + '_202105270' + i + '.tif';
}
else{
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_NO2_20210527' + i + '_20210527' + i + '.tif';
}
matrix my_data <- grid_file(path_grid) as_matrix({624, 725});
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
loop j from: 0 to: 623{
loop k from: 0 to: 724{
pollution_raster_float[j, k] <- float (my_data[j, k] get("grid_value"));
}
}
write ('raster NO2 ' + i + ' chargé');
write('max: ' + max(pollution_raster_float));
NO2_rasters << pollution_raster_float;
}
}
if measure_O3 {
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
O3_rasters << pollution_raster_float;
loop i from: 1 to: 23{
string path_grid;
if (i < 10){
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_O3_202105270' + i + '_202105270' + i + '.tif';
}
else{
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_O3_20210527' + i + '_20210527' + i + '.tif';
}
matrix my_data <- grid_file(path_grid) as_matrix({624, 725});
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
loop j from: 0 to: 623{
loop k from: 0 to: 724{
pollution_raster_float[j, k] <- float (my_data[j, k] get("grid_value"));
}
}
write ('raster O3 ' + i + ' chargé');
write('max: ' + max(pollution_raster_float));
O3_rasters << pollution_raster_float;
}
}
if measure_PM10 {
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
PM10_rasters << pollution_raster_float;
loop i from: 1 to: 23{
string path_grid;
if (i < 10){
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_PM10_202105270' + i + '_202105270' + i + '.tif';
}
else{
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_PM10_20210527' + i + '_20210527' + i + '.tif';
}
matrix my_data <- grid_file(path_grid) as_matrix({624, 725});
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
loop j from: 0 to: 623{
loop k from: 0 to: 724{
pollution_raster_float[j, k] <- float (my_data[j, k] get("grid_value"));
}
}
write ('raster PM10 ' + i + ' chargé');
write('max: ' + max(pollution_raster_float));
PM10_rasters << pollution_raster_float;
}
}
if measure_PM25 {
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
PM25_rasters << pollution_raster_float;
loop i from: 1 to: 23{
string path_grid;
if (i < 10){
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_PM25_202105270' + i + '_202105270' + i + '.tif';
}
else{
path_grid <- '../includes/Marseille/pollution_model/raster_dep13_PM25_20210527' + i + '_20210527' + i + '.tif';
}
matrix my_data <- grid_file(path_grid) as_matrix({624, 725});
matrix<float> pollution_raster_float <- 0.0 as_matrix({624, 725});
loop j from: 0 to: 623{
loop k from: 0 to: 724{
pollution_raster_float[j, k] <- float (my_data[j, k] get("grid_value"));
}
}
write ('raster PM25 ' + i + ' chargé');
write('max: ' + max(pollution_raster_float));
PM25_rasters << pollution_raster_float;
}
}
// generation des donnees de pollution pour chaque type d'agent
if workers{
write("generating workers measures");
create measure from: shape_file("../results/Marseille/worker/aller_worker/positions_aller_worker.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int worker_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(worker_number);
if (worker_number <= 3000){do die;}
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/worker/workers_measures_to_predict.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
create measure from: shape_file("../results/Marseille/worker/retour_worker/positions_retour_worker.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int worker_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(worker_number);
if (worker_number <= 3000){do die;}
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/worker/workers_measures_to_predict.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
}
if students{
write("generating students measures");
create measure from: shape_file("../results/Marseille/student/aller_student/positions_aller_student.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int student_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(student_number);
if (student_number <= 1800){do die;}
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/student/students_measures_to_predict.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
create measure from: shape_file("../results/Marseille/student/retour_student/positions_retour_student.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int student_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(student_number);
if (student_number <= 1800){do die;}
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/student/students_measures_to_predict.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
}
if leisures{
write("generating leisures measures");
create measure from: shape_file("../results/Marseille/leisure/aller_leisure/positions_aller_leisure.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int leisure_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(leisure_number);
if (leisure_number <= 6200){do die;}
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/leisure/leisures_measures_to_predict.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
create measure from: shape_file("../results/Marseille/leisure/retour_leisure/positions_retour_leisure.shp") with: [time_of_measure::(read("time")), name_of_agent::(read('agent'))]{
int leisure_number <- int((((name_of_agent split_with '[')[1]) split_with ']')[0]);
write(leisure_number);
if (leisure_number <= 6200){do die;}
ID <- compteur_ID;
compteur_ID <- compteur_ID + 1;
geometry CRS_2154 <- location CRS_transform("EPSG:2154");
list<string> coord <- string(CRS_2154) split_with ",";
latitude <- float(coord[1]);
longitude <- float((coord[0] split_with "{")[0]);
int cell_x <- int((longitude - min_x) / 25);
int cell_y <- int((max_y - latitude) / 25);
// obtention de la concentration de polluant : interpolation linéaire entre les deux rasters horaires qui 'encadrent' l'heure de mesure
int hour_before_measure <- time_of_measure.hour;
int hour_after_measure <- hour_before_measure + 1;
int min_measure <- time_of_measure.minute;
int sec_measure <- time_of_measure.second;
if measure_NO2 {
NO2_concentration <- NO2_rasters[hour_before_measure][cell_x,cell_y] +
(NO2_rasters[hour_after_measure][cell_x,cell_y] - NO2_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_O3 {
O3_concentration <- O3_rasters[hour_before_measure][cell_x,cell_y] +
(O3_rasters[hour_after_measure][cell_x,cell_y] - O3_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM10 {
PM10_concentration <- PM10_rasters[hour_before_measure][cell_x,cell_y] +
(PM10_rasters[hour_after_measure][cell_x,cell_y] - PM10_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
if measure_PM25 {
PM25_concentration <- PM25_rasters[hour_before_measure][cell_x,cell_y] +
(PM25_rasters[hour_after_measure][cell_x,cell_y] - PM25_rasters[hour_before_measure][cell_x,cell_y]) * (min_measure * 60 + sec_measure) / 3600;
}
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/leisure/leisures_measures_to_predict.csv" type:"csv" rewrite: false;
}
ask measure{do die;}
}
}
}
species measure {
int ID;
string name_of_agent;
float longitude min: min_x max: max_x - 0.1;
float latitude min: min_y max: max_y - 0.1;
date time_of_measure;
float NO2_concentration;
float O3_concentration;
float PM10_concentration;
float PM25_concentration;
}
experiment bike_traffic type: gui {
}
\ No newline at end of file
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/*
* This model generates the environment close to the point of travel where the pollution level has to be predicted
*
*/
global {
bool workers <- false;
bool students <- true;
bool leisures <- false;
file measures_workers_csv;
file measures_students_csv;
file measures_leisures_csv;
file bound <- shape_file("../includes/Marseille/boundary_Marseille.shp");
geometry shape <- envelope(bound);
file shape_file_buildings <- shape_file("../includes/Marseille/buildings_ign.shp");
file shape_file_vegetation <- shape_file("../includes/Marseille/environment/ZONE_DE_VEGETATION.shp");
file roads_ign <- shape_file("../includes/Marseille/environment/roads_ign.shp");
file primary_roads <- shape_file("../includes/Marseille/environment/primary_roads.shp");
init{
create building from: shape_file_buildings with: [height::float(read("HAUTEUR"))];
create road from: roads_ign;
list<road> rd_1_voie <- road where (each.NB_VOIES = 1);
list<road> rd_2_voie <- road where (each.NB_VOIES = 2);
list<road> rd_3_voie <- road where (each.NB_VOIES = 3);
list<road> rd_4_voie <- road where (each.NB_VOIES = 4);
list<road> rd_5_voie <- road where (each.NB_VOIES = 5);
list<road> rd_6_voie <- road where (each.NB_VOIES = 6);
list<road> list_rd_0_4_width <- road where (each.LARGEUR <= 4.0);
list<road> list_rd_4_6_width <- road where (each.LARGEUR > 4.0 and each.LARGEUR <= 6.0);
list<road> list_rd_6_8_width <- road where (each.LARGEUR > 6.0 and each.LARGEUR <= 8.0);
list<road> list_rd_8_max_width <- road where (each.LARGEUR > 8.0);
create primary_road from: primary_roads;
create vegetation from: shape_file_vegetation;
list<vegetation> list_bois <- vegetation where (each.NATURE = 'Bois');
list<vegetation> list_foret <- vegetation where (each.NATURE = 'Forêt fermée de conifères' or each.NATURE = 'Forêt fermée de feuillus'
or each.NATURE = 'Forêt fermée mixte' or each.NATURE = 'Forêt ouverte');
list<vegetation> list_haie <- vegetation where (each.NATURE = 'Haie');
if(workers){
measures_workers_csv <- csv_file("../results/Marseille/worker/workers_measures_to_predict.csv",true);
create measure from: measures_workers_csv{
write(self.ID);
location <- point(to_GAMA_CRS({self.longitude, self.latitude}, 'EPSG:2154'));
geometry disque <- circle(50, location);
create environment {
ID <- myself.ID;
name_of_agent <- myself.name_of_agent;
longitude <- myself.longitude;
latitude <- myself.latitude;
loop build over: building overlapping disque{
float surface_inter <- (build inter disque).area;
buildings_volume <- buildings_volume + build.height * surface_inter;
}
loop rd over: rd_1_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_1 <- voie_1 + perimeter_inter;
}
loop rd over: rd_2_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_2 <- voie_2 + perimeter_inter;
}
loop rd over: rd_3_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_3 <- voie_3 + perimeter_inter;
}
loop rd over: rd_4_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_4 <- voie_4 + perimeter_inter;
}
loop rd over: rd_5_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_5 <- voie_5 + perimeter_inter;
}
loop rd over: rd_6_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_6 <- voie_6 + perimeter_inter;
}
loop rd over: list_rd_0_4_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_0_4_width <- road_0_4_width + perimeter_inter;
}
loop rd over: list_rd_4_6_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_4_6_width <- road_4_6_width + perimeter_inter;
}
loop rd over: list_rd_6_8_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_6_8_width <- road_6_8_width + perimeter_inter;
}
loop rd over: list_rd_8_max_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_8_max_width <- road_8_max_width + perimeter_inter;
}
loop veg over: list_bois overlapping disque{
float area_inter <- (veg inter disque).area;
bois <- bois + area_inter;
}
loop veg over: list_foret overlapping disque{
float area_inter <- (veg inter disque).area;
foret <- foret + area_inter;
}
loop veg over: list_haie overlapping disque{
float area_inter <- (veg inter disque).area;
haie <- haie + area_inter;
}
distance_to_main_road <- myself distance_to (primary_road closest_to myself);
}
}
ask environment {
save [ID, name_of_agent, longitude, latitude, buildings_volume, voie_1, voie_2, voie_3, voie_4, voie_5, voie_6, road_0_4_width, road_4_6_width, road_6_8_width, road_8_max_width, distance_to_main_road, bois, foret, haie]
to: "../results/Marseille/worker/workers_environment_for_prediction.csv" type:"csv" rewrite: false;
}
}
if(students){
measures_students_csv <- csv_file("../results/Marseille/student/students_measures_to_predict.csv",true);
create measure from: measures_students_csv{
write(self.ID);
location <- point(to_GAMA_CRS({self.longitude, self.latitude}, 'EPSG:2154'));
geometry disque <- circle(50, location);
create environment {
ID <- myself.ID;
name_of_agent <- myself.name_of_agent;
longitude <- myself.longitude;
latitude <- myself.latitude;
loop build over: building overlapping disque{
float surface_inter <- (build inter disque).area;
buildings_volume <- buildings_volume + build.height * surface_inter;
}
loop rd over: rd_1_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_1 <- voie_1 + perimeter_inter;
}
loop rd over: rd_2_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_2 <- voie_2 + perimeter_inter;
}
loop rd over: rd_3_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_3 <- voie_3 + perimeter_inter;
}
loop rd over: rd_4_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_4 <- voie_4 + perimeter_inter;
}
loop rd over: rd_5_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_5 <- voie_5 + perimeter_inter;
}
loop rd over: rd_6_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_6 <- voie_6 + perimeter_inter;
}
loop rd over: list_rd_0_4_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_0_4_width <- road_0_4_width + perimeter_inter;
}
loop rd over: list_rd_4_6_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_4_6_width <- road_4_6_width + perimeter_inter;
}
loop rd over: list_rd_6_8_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_6_8_width <- road_6_8_width + perimeter_inter;
}
loop rd over: list_rd_8_max_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_8_max_width <- road_8_max_width + perimeter_inter;
}
loop veg over: list_bois overlapping disque{
float area_inter <- (veg inter disque).area;
bois <- bois + area_inter;
}
loop veg over: list_foret overlapping disque{
float area_inter <- (veg inter disque).area;
foret <- foret + area_inter;
}
loop veg over: list_haie overlapping disque{
float area_inter <- (veg inter disque).area;
haie <- haie + area_inter;
}
distance_to_main_road <- myself distance_to (primary_road closest_to myself);
}
}
ask environment {
save [ID, name_of_agent, longitude, latitude, buildings_volume, voie_1, voie_2, voie_3, voie_4, voie_5, voie_6, road_0_4_width, road_4_6_width, road_6_8_width, road_8_max_width, distance_to_main_road, bois, foret, haie]
to: "../results/Marseille/student/students_environment_for_prediction.csv" type:"csv" rewrite: false;
}
}
if(leisures){
measures_leisures_csv <- csv_file("../results/Marseille/leisure/leisures_measures_to_predict.csv",true);
create measure from: measures_leisures_csv{
write(self.ID);
location <- point(to_GAMA_CRS({self.longitude, self.latitude}, 'EPSG:2154'));
geometry disque <- circle(50, location);
create environment {
ID <- myself.ID;
name_of_agent <- myself.name_of_agent;
longitude <- myself.longitude;
latitude <- myself.latitude;
loop build over: building overlapping disque{
float surface_inter <- (build inter disque).area;
buildings_volume <- buildings_volume + build.height * surface_inter;
}
loop rd over: rd_1_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_1 <- voie_1 + perimeter_inter;
}
loop rd over: rd_2_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_2 <- voie_2 + perimeter_inter;
}
loop rd over: rd_3_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_3 <- voie_3 + perimeter_inter;
}
loop rd over: rd_4_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_4 <- voie_4 + perimeter_inter;
}
loop rd over: rd_5_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_5 <- voie_5 + perimeter_inter;
}
loop rd over: rd_6_voie overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
voie_6 <- voie_6 + perimeter_inter;
}
loop rd over: list_rd_0_4_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_0_4_width <- road_0_4_width + perimeter_inter;
}
loop rd over: list_rd_4_6_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_4_6_width <- road_4_6_width + perimeter_inter;
}
loop rd over: list_rd_6_8_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_6_8_width <- road_6_8_width + perimeter_inter;
}
loop rd over: list_rd_8_max_width overlapping disque{
float perimeter_inter <- (rd inter disque).perimeter;
road_8_max_width <- road_8_max_width + perimeter_inter;
}
loop veg over: list_bois overlapping disque{
float area_inter <- (veg inter disque).area;
bois <- bois + area_inter;
}
loop veg over: list_foret overlapping disque{
float area_inter <- (veg inter disque).area;
foret <- foret + area_inter;
}
loop veg over: list_haie overlapping disque{
float area_inter <- (veg inter disque).area;
haie <- haie + area_inter;
}
distance_to_main_road <- myself distance_to (primary_road closest_to myself);
}
}
ask environment {
save [ID, name_of_agent, longitude, latitude, buildings_volume, voie_1, voie_2, voie_3, voie_4, voie_5, voie_6, road_0_4_width, road_4_6_width, road_6_8_width, road_8_max_width, distance_to_main_road, bois, foret, haie]
to: "../results/Marseille/leisure/leisures_environment_for_prediction.csv" type:"csv" rewrite: false;
}
}
}
}
species measure { // seulement besoin de la localisation de la mesure, etant donne que l'environnement est suppose stationnaire
int ID;
string name_of_agent;
float longitude;
float latitude;
}
species environment{ // flotants correspondant à l'environnement dans un disque de 50m de rayon centré sur la mesure
int ID; // ID égal à celui de la mesure
string name_of_agent;
float longitude;
float latitude;
float road_0_4_width; // longueur de route dans le disque ayant comme attribut : largeur <= 4
float road_4_6_width; // longueur de route dans le disque ayant comme attribut : 4 < largeur <= 6
float road_6_8_width; // longueur de route dans le disque ayant comme attribut : 6 < largeur <= 8
float road_8_max_width; // longueur de route dans le disque ayant comme attribut : 8 < largeur
float voie_1;
float voie_2;
float voie_3;
float voie_4;
float voie_5;
float voie_6;
float buildings_volume;
float distance_to_main_road;
float bois; //surface de bois dans le disque
float foret;
float haie;
}
species road {
float LARGEUR;
int NB_VOIES;
}
species primary_road{
}
species building {
int id;
string type;
string types_str;
list<string> types;
float height;
}
species vegetation {
string NATURE; //Bois, Forêt fermée de conifères, Forêt fermée de feuillus, Forêt fermée mixte, Forêt ouverte, Haie, Lande ligneuse, Verger, Vigne (types BD TOPO)
}
experiment bike_traffic type: gui {
}
\ No newline at end of file
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/*
* This model generates a regression between the pollution level given by "Synthetc measures from agents' travels" and the environment indicators generated in "Measures' environment"
*
*/
global {
bool workers <- false;
bool students <- true;
bool leisures <- false;
file measures_workers_csv;
file measures_students_csv;
file measures_leisures_csv;
file environment_workers_csv;
file environment_students_csv;
file environment_leisures_csv;
file measures_to_predict_workers_csv;
file measures_to_predict_students_csv;
file measures_to_predict_leisures_csv;
file environment_for_prediction_workers_csv;
file environment_for_prediction_students_csv;
file environment_for_prediction_leisures_csv;
init{
//matrice de régression routes largeur: DATE, longueur de route 0-4, 4-6, 6-8, 8-max, NO2
//matrice de régression routes voies: DATE, voies 1, 2, 3, 4, 5, 6, NO2
//matrice de régression bâtiments: DATE, buildings_volume, NO2
//matrice de régression végétation: DATE, bois, foret, haie, NO2
if(students){
measures_students_csv <- csv_file("../results/Marseille/student/students_measures.csv",true); //mesures faites par 1800 agents student
environment_students_csv <- csv_file("../results/Marseille/student/students_measures_environment.csv",true);
create measure from: measures_students_csv;
create environment from: environment_students_csv;
list<float> pollution_NO2 ;
list<float> ind_date;
loop m over: measure {
pollution_NO2 << m.NO2_concentration;
string time_m <- (((m.time_of_measure split_with "'(")[1]) split_with ")'")[0];
ind_date << float(date(time_m));
}
//création de la matrice de régression routes voies
list<float> ind_voies_1;
list<float> ind_voies_2;
list<float> ind_voies_3;
list<float> ind_voies_4;
list<float> ind_voies_5;
list<float> ind_voies_6;
loop env over: environment {
ind_voies_1 << env.voie_1;
ind_voies_2 << env.voie_2;
ind_voies_3 << env.voie_3;
ind_voies_4 << env.voie_4;
ind_voies_5 << env.voie_5;
ind_voies_6 << env.voie_6;
}
matrix routes_voies_regression <- matrix(ind_date, ind_voies_1, ind_voies_2, ind_voies_3, ind_voies_4, ind_voies_5, ind_voies_6, pollution_NO2);
regression NO2_voies_student <- build(routes_voies_regression);
write("regression generee. debut de la prediction des trajets restants");
// prediction des trajets non réalisés à partir de l'environnement de ces trajets
measures_to_predict_students_csv <- csv_file("../results/Marseille/student/students_measures_to_predict.csv",true);
environment_for_prediction_students_csv <- csv_file("../results/Marseille/student/students_environment_for_prediction.csv",true);
create measure from: measures_to_predict_students_csv; // mesures à prédire pour les agents student restants
create environment from: environment_for_prediction_students_csv;
loop env over: environment {
measure associated_measure <- measure[int(env)];
string time_m <- (((associated_measure.time_of_measure split_with "'(")[1]) split_with ")'")[0];
float predict_date <- float(date(time_m));
measure[int(env)].predicted_NO2_concentration <- predict(NO2_voies_student, [predict_date, env.voie_1, env.voie_2, env.voie_3, env.voie_4, env.voie_5, env.voie_6]);
}
ask measure{
save [ID, name_of_agent, longitude, latitude, time_of_measure, NO2_concentration, predicted_NO2_concentration, O3_concentration, PM10_concentration, PM25_concentration]
to: "../results/Marseille/student/students_measures_predicted.csv" type:"csv" rewrite: false;
}
}
}
}
species measure {
int ID;
string name_of_agent;
float longitude;
float latitude;
string time_of_measure;
float NO2_concentration;
float O3_concentration;
float PM10_concentration;
float PM25_concentration;
float predicted_NO2_concentration;
float predicted_O3_concentration;
float predicted_PM10_concentration;
float predicted_PM25_concentration;
}
species environment{ // flotants correspondant à l'environnement dans un disque de 50m de rayon centré sur la mesure
int ID; // ID égal à celui de la mesure
string name_of_agent;
float longitude;
float latitude;
float road_0_4_width; // longueur de route dans le disque ayant comme attribut : largeur <= 4
float road_4_6_width; // longueur de route dans le disque ayant comme attribut : 4 < largeur <= 6
float road_6_8_width; // longueur de route dans le disque ayant comme attribut : 6 < largeur <= 8
float road_8_max_width; // longueur de route dans le disque ayant comme attribut : 8 < largeur
float voie_1;
float voie_2;
float voie_3;
float voie_4;
float voie_5;
float voie_6;
float buildings_volume;
float distance_to_main_road;
float bois; //surface de bois dans le disque
float foret;
float haie;
}
species position_travel {
}
experiment regression_prediction type: gui {
output{
display city_display type: opengl{
species measure;
}
}
}
\ No newline at end of file
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/*
* This model calculates every population's exposition to each pollutant, thanks to measures generated in 'synthetic measures from agents' travels'
*
*/
global {
file measures_csv;
bool workers <- false; // une seule population en 'true' à la fois pour le stockage des mesures par type d'agent
bool students <- true;
bool leisures <- false;
init{
if workers{
write("loading workers measures");
measures_csv <- csv_file("../results/Marseille/worker/workers_measures.csv",true);
create measure from: measures_csv{
if(self.ID = 100000 or self.ID = 200000 or self.ID = 300000 or self.ID = 400000 or self.ID = 500000) {write(self.ID);}
}
write("calcul exposition of workers");
loop i from: 0 to: 3600{
write(i);
list<measure> list_of_measures <- measure where (each.name_of_agent = 'worker[' + i + ']');
list<float> list_of_NO2;
list<float> list_of_O3;
list<float> list_of_PM10;
list<float> list_of_PM25;
loop m over: list_of_measures{
if (m.NO2_concentration > 0) {list_of_NO2 << m.NO2_concentration;}
if (m.O3_concentration > 0) {list_of_O3 << m.O3_concentration;}
if (m.PM10_concentration > 0) {list_of_PM10 << m.PM10_concentration;}
if (m.PM25_concentration > 0) {list_of_PM25 << m.PM25_concentration;}
}
create worker{
name_of_agent <- 'worker[' + i + ']';
NO2_mean_exposition <- mean (list_of_NO2);
O3_mean_exposition <- mean (list_of_O3);
PM10_mean_exposition <- mean (list_of_PM10);
PM25_mean_exposition <- mean (list_of_PM25);
NO2_max <- max (list_of_NO2);
O3_max <- max (list_of_O3);
PM10_max <- max (list_of_PM10);
PM25_max <- max (list_of_PM25);
}
}
ask worker {
save [name_of_agent, NO2_mean_exposition, NO2_max, O3_mean_exposition, O3_max, PM10_mean_exposition, PM10_max, PM25_mean_exposition, PM25_max]
to: "../results/Marseille/worker/workers_exposition.csv" type:"csv" rewrite: false;
}
}
if students{
write("loading students measures");
measures_csv <- csv_file("../results/Marseille/student/students_measures.csv",true);
create measure from: measures_csv{
if(self.ID = 100000 or self.ID = 200000 or self.ID = 300000 or self.ID = 400000 or self.ID = 500000) {write(self.ID);}
}
write("calcul exposition of students");
loop i from: 0 to: 2236{
write(i);
list<measure> list_of_measures <- measure where (each.name_of_agent = 'student[' + i + ']');
list<float> list_of_NO2;
list<float> list_of_O3;
list<float> list_of_PM10;
list<float> list_of_PM25;
loop m over: list_of_measures{
if (m.NO2_concentration > 0) {list_of_NO2 << m.NO2_concentration;}
if (m.O3_concentration > 0) {list_of_O3 << m.O3_concentration;}
if (m.PM10_concentration > 0) {list_of_PM10 << m.PM10_concentration;}
if (m.PM25_concentration > 0) {list_of_PM25 << m.PM25_concentration;}
}
create student{
name_of_agent <- 'student[' + i + ']';
NO2_mean_exposition <- mean (list_of_NO2);
O3_mean_exposition <- mean (list_of_O3);
PM10_mean_exposition <- mean (list_of_PM10);
PM25_mean_exposition <- mean (list_of_PM25);
NO2_max <- max (list_of_NO2);
O3_max <- max (list_of_O3);
PM10_max <- max (list_of_PM10);
PM25_max <- max (list_of_PM25);
}
}
ask student {
save [name_of_agent, NO2_mean_exposition, NO2_max, O3_mean_exposition, O3_max, PM10_mean_exposition, PM10_max, PM25_mean_exposition, PM25_max]
to: "../results/Marseille/student/students_exposition.csv" type:"csv" rewrite: false;
}
}
if leisures{
write("loading leisures measures");
measures_csv <- csv_file("../results/Marseille/worker/leisures_measures.csv",true);
create measure from: measures_csv{
if(self.ID = 100000 or self.ID = 200000 or self.ID = 300000 or self.ID = 400000 or self.ID = 500000) {write(self.ID);}
}
write("calcul exposition of leisures");
loop i from: 0 to: 7527{
write(i);
list<measure> list_of_measures <- measure where (each.name_of_agent = 'leisure[' + i + ']');
list<float> list_of_NO2;
list<float> list_of_O3;
list<float> list_of_PM10;
list<float> list_of_PM25;
loop m over: list_of_measures{
if (m.NO2_concentration > 0) {list_of_NO2 << m.NO2_concentration;}
if (m.O3_concentration > 0) {list_of_O3 << m.O3_concentration;}
if (m.PM10_concentration > 0) {list_of_PM10 << m.PM10_concentration;}
if (m.PM25_concentration > 0) {list_of_PM25 << m.PM25_concentration;}
}
create leisure{
name_of_agent <- 'leisure[' + i + ']';
NO2_mean_exposition <- mean (list_of_NO2);
O3_mean_exposition <- mean (list_of_O3);
PM10_mean_exposition <- mean (list_of_PM10);
PM25_mean_exposition <- mean (list_of_PM25);
NO2_max <- max (list_of_NO2);
O3_max <- max (list_of_O3);
PM10_max <- max (list_of_PM10);
PM25_max <- max (list_of_PM25);
}
}
ask leisure {
save [name_of_agent, NO2_mean_exposition, NO2_max, O3_mean_exposition, O3_max, PM10_mean_exposition, PM10_max, PM25_mean_exposition, PM25_max]
to: "../results/Marseille/leisure/leisures_exposition.csv" type:"csv" rewrite: false;
}
}
}
}
species measure { // seulement besoin de la localisation de la mesure, etant donne que l'environnement est suppose stationnaire
string name_of_agent;
int ID;
float NO2_concentration;
float O3_concentration;
float PM10_concentration;
float PM25_concentration;
}
species people {
string name_of_agent;
float NO2_mean_exposition;
float O3_mean_exposition;
float PM10_mean_exposition;
float PM25_mean_exposition;
float NO2_max;
float O3_max;
float PM10_max;
float PM25_max;
}
species worker parent: people{
}
species student parent: people{
}
species leisure parent: people{
}
experiment bike_traffic type: gui {
output{
display exposition {
chart "Exposition moyenne des étudiants" type: histogram background: #lightgrey{
data "0 - 40 um/m3" value: student count (each.NO2_mean_exposition < 40) ;
data "40 - 80 um/m3" value: student count (each.NO2_mean_exposition >= 40 and each.NO2_mean_exposition < 80);
data "80 - 120 um/m3" value: student count (each.NO2_mean_exposition >= 80 and each.NO2_mean_exposition < 120);
data "120 - 160 um/m3" value: student count (each.NO2_mean_exposition >= 120 and each.NO2_mean_exposition < 160);
data "160 - 200 um/m3" value: student count (each.NO2_mean_exposition >= 160 and each.NO2_mean_exposition < 200);
}
}
}
}
\ No newline at end of file
/***
* Part of the SWITCH Project
* Author: Patrick Taillandier
* Tags: gis, OSM data
***/
model switch_utilities_gis
/*
* Bases de données requises :
* https://download.geofabrik.de/europe/france.html
* https://geoservices.ign.fr/documentation/diffusion/telechargement-donnees-libres.html#bd-topo
*
*/
global {
string dataset_path <- "../includes/";
file shape_file_roads <- shape_file("../includes/SHP Marseille/roads.shp");
file elevation_data <- grid_file('../includes/DEM_Marseille.tif');
geometry shape <- envelope(elevation_data);
graph the_graph;
int nb_for_road_shapefile_split <- 20000;
init {
float max_value <- elevation_cell max_of (each.grid_value);
float min_value <- elevation_cell min_of (each.grid_value);
ask elevation_cell {
normalized_elevation <- (grid_value) / (max_value);
if grid_value < -1{
color <- #black;
}
else{
color <- rgb(int(255 * normalized_elevation), int(255 * (normalized_elevation)), int(255 * (normalized_elevation)));
}
}
write "Start the pre-processing process";
create road from: shape_file_roads with: [id::int(get("id")), fclass::get("fclass"), speed_coeff::float(get("s_coeff")),maxspeed::int(get("maxspeed"))]{
point first <- first(shape.points);
point last <- last(shape.points);
if (not (first overlaps world)) or (not (last overlaps world)) {
do die;
}
if length(shape.points) > 1{
float altitude_first <- (elevation_cell where (first overlaps each))[0].grid_value; //(distance_to (first, each.location))).grid_value;
float altitude_last <- (elevation_cell where (last overlaps each))[0].grid_value; //(distance_to (last, each.location))).grid_value;
if (altitude_last > -3 and altitude_first > -3 and shape.perimeter > 0){
slope <- sin((altitude_last - altitude_first) / shape.perimeter) * 180 / #pi;
}
}
}
write "Number of roads created : "+ length(road);
write("Saving roads");
save road to:"../includes/SHP Marseille/roads_slope.shp" type: shp attributes: ["id"::id,"fclass"::fclass, "s_coeff"::speed_coeff, "maxspeed"::maxspeed, "slope"::slope];
write("over");
}
}
grid elevation_cell file: elevation_data {
float normalized_elevation min:0.0 max: 1.0;
}
species road {
int id;
int maxspeed;
string fclass;
float speed_coeff;
float slope;
rgb color <- #red;
aspect base {
draw shape color: color width: 2;
}
}
experiment generateGISdata type: gui {
output {
display map type: opengl draw_env: false{
species elevation_cell;
species road;
}
}
}
\ No newline at end of file
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/* Modélisation du déplacement d'une flotte de cyclistes équipés de capteurs de pollution
* Sortie : une carte des zones mesurées est générée toutes les heures
* Sortie : un compte rendu du trajet de chaque cycliste, avec des points de rendez-vous
*
*/
global {
string city <- "Marseille";
bool test_population <- false;
file bound <- shape_file("../includes/" + city + "/boundary_" + city + ".shp");
file shape_file_buildings;
file shape_file_roads;
bool workers <- false;
bool students <- true;
bool leisures <- false;
bool deliveries <- false;
bool home_location <- true;
file worker_csv;
file student_csv;
file leisure_csv;
file delivery_midi_csv;
file delivery_soir_csv;
geometry shape <- envelope(bound);
graph the_graph;
list<string> study_places <- ["university", "college", "school", "library"];
init{
if city = "Marseille"{
shape_file_buildings <- shape_file("../includes/Marseille/SHP Marseille/buildings_v2.shp"); // building contenant les data osm, ign, pois
shape_file_roads <- shape_file("../includes/Marseille/SHP Marseille/roads.shp");
if (test_population){
write("Marseille : population test");
worker_csv <- csv_file( "../results/Marseille/synthetic_population_test/worker.csv",true);
student_csv <- csv_file( "../results/Marseille/synthetic_population_test/student.csv",true);
leisure_csv <- csv_file( "../results/Marseille/synthetic_population_test/leisure.csv",true);
delivery_midi_csv <- csv_file( "../results/Marseille/synthetic_population_test/delivery_midi.csv",true);
delivery_soir_csv <- csv_file( "../results/Marseille/synthetic_population_test/delivery_soir.csv",true);
}
else{
write("Marseille : population reelle");
worker_csv <- csv_file( "../results/Marseille/synthetic_population/worker.csv",true);
student_csv <- csv_file( "../results/Marseille/synthetic_population/student.csv",true);
leisure_csv <- csv_file( "../results/Marseille/synthetic_population/leisure.csv",true);
delivery_midi_csv <- csv_file( "../results/Marseille/synthetic_population/delivery_midi.csv",true);
delivery_soir_csv <- csv_file( "../results/Marseille/synthetic_population/delivery_soir.csv",true);
}
}
if city = "Toulouse"{
shape_file_buildings <- shape_file("../includes/Toulouse/buildings_with_pois.shp"); // building contenant les data osm, ign, pois
shape_file_roads <- shape_file("../includes/Toulouse/roads.shp");
if (test_population){
write("Toulouse : population test");
worker_csv <- csv_file( "../results/Toulouse/synthetic_population_test/worker.csv",true);
student_csv <- csv_file( "../results/Toulouse/synthetic_population_test/student.csv",true);
leisure_csv <- csv_file( "../results/Toulouse/synthetic_population_test/leisure.csv",true);
delivery_midi_csv <- csv_file( "../results/Toulouse/synthetic_population_test/delivery_midi.csv",true);
delivery_soir_csv <- csv_file( "../results/Toulouse/synthetic_population_test/delivery_soir.csv",true);
}
else{
write("Toulouse : population reelle");
worker_csv <- csv_file( "../results/Toulouse/synthetic_population/worker.csv",true);
student_csv <- csv_file( "../results/Toulouse/synthetic_population/student.csv",true);
leisure_csv <- csv_file( "../results/Toulouse/synthetic_population/leisure.csv",true);
delivery_midi_csv <- csv_file( "../results/Toulouse/synthetic_population/delivery_midi.csv",true);
delivery_soir_csv <- csv_file( "../results/Toulouse/synthetic_population/delivery_soir.csv",true);
}
}
create building from: shape_file_buildings {
types <- types_str split_with ",";
}
//list<building> university_buildings <- building where (not empty(study_places inter each.types));
create road from: shape_file_roads with: [id::int(get("id")), fclass::read ("fclass"), speed_coeff::float(get("s_coeff")), maxspeed::int(get("maxspeed"))];
the_graph <- as_edge_graph(road);
the_graph <- the_graph;
map<int,building> building_map <- building as_map (each.id::each);
if workers{
write("instanciate workers");
create worker from: worker_csv with:[id_living_place::int(get("living_place.id")), id_destination_place::int(get("destination_place.id"))]{
if home_location{
living_place <- building_map[id_living_place];
location <- any_location_in (living_place);
}
else {
destination_place <- building_map[id_destination_place];
location <- any_location_in (destination_place);
}
}
}
if students{
write("instanciate students");
create student from: student_csv with:[id_living_place::int(get("living_place.id")), id_destination_place::int(get("destination_place.id"))]{
if home_location{
living_place <- building_map[id_living_place];
location <- any_location_in (living_place);
}
else {
destination_place <- building_map[id_destination_place];
location <- any_location_in (destination_place);
}
}
}
if leisures{
write("instanciate leisures");
create leisure from: leisure_csv with:[id_living_place::int(get("living_place.id")), id_destination_place::int(get("destination_place.id"))]{
if home_location{
living_place <- building_map[id_living_place];
location <- any_location_in (living_place);
}
else {
destination_place <- building_map[id_destination_place];
location <- any_location_in (destination_place);
}
}
}
if deliveries {
write("instanciate deliveries");
create delivery from: delivery_midi_csv with: [id_living_place::int(get("living_place.id"))]{
living_place <- building_map[id_living_place];
location <- any_location_in (living_place);
}
create delivery from: delivery_soir_csv with: [id_living_place::int(get("living_place.id"))]{
living_place <- building_map[id_living_place];
location <- any_location_in (living_place);
}
}
/*
float min_dist <- university_buildings min_of (each distance_to student[0]);
float max_dist <- university_buildings max_of (each distance_to student[0]);
ask building {
if not (self in university_buildings){
do die;
}
float coeff_dist <- (self distance_to student[0] - min_dist) / (max_dist - min_dist);
color <- rgb(int(255 * coeff_dist), int(255 * (1 - coeff_dist)), 0);
}
*
*/
}
}
species building {
int id;
string type;
string types_str;
list<string> types;
float height;
rgb color <- #gray;
aspect base {
draw shape color: color ;
}
}
species road {
int id;
string fclass;
int maxspeed;
float speed_coeff;
rgb color <- #orange;
aspect base {
draw shape color: color width: 1;
}
}
species people skills: [moving] {
rgb color;
int id_living_place;
int id_destination_place;
building living_place;
building destination_place;
aspect base{
draw circle(60) color: color border: #black;
}
}
species worker parent: people {
rgb color <- #black;
}
species student parent: people{
rgb color <- #green;
}
species leisure parent: people{
rgb color <- #blue;
}
species delivery skills: [moving]{
rgb color <- #red;
int id_living_place;
building living_place <- nil;
aspect base{
draw circle(10) color: color border: #black;
}
}
experiment bike_traffic type: gui {
output{
display city_display type: opengl{
species building aspect: base;
//species road aspect: base;
species worker aspect: base;
species student aspect: base;
species leisure aspect: base;
species delivery aspect: base;
}
display caract_road {
chart "Distribution de la distance de trajet des travailleurs" type: histogram background: #lightgrey size: {0.5, 0.5} position: {0, 0}{
data "0 - 50 m" value: road count (each.shape.perimeter < 50 #m) color: #blue;
data "50 - 100" value: road count (each.shape.perimeter > 50 #m and each.shape.perimeter < 100 #m) color: #blue;
data "100 - 150" value: road count (each.shape.perimeter > 100 #m and each.shape.perimeter < 150 #m) color: #blue;
data "150 - 200" value: road count (each.shape.perimeter > 150 #m and each.shape.perimeter < 200 #m) color: #blue;
}
chart "Distance moyenne des routes" type: histogram background: #lightgrey size: {0.5, 0.5} position: {0.5, 0.5} {
list<float> size;
loop rd over: road{
size << rd.shape.perimeter;
}
data "Travail" value: sum(size) / length(road) color: #blue;
}
}
}
}
\ No newline at end of file
/**
* Name: Deplacementdevelos
* Based on the internal empty template.
* Author: nathancoisne
* Tags:
*/
model Deplacementdevelos
/*
* This model generates travels' characteristics (duration and length for comparison with real world data
*
*/
global {
file bound <- shape_file("../includes/Marseille/boundary_Marseille.shp");
bool workers <- true;
bool students <- false; // une seule population à la fois
bool leisures <- false;
init{
if workers{
write("workers travels");
loop i from: 0 to: 3600 {
write(i);
list<position> list_of_positions_aller <- [];
create travel{
create position from: shape_file("../results/Marseille/worker/aller_worker/positions/aller_worker[" + i + "].shp") with: [time_of_measure::(read("time"))]{
list_of_positions_aller << self;
}
float milliseconds <- first(list_of_positions_aller).time_of_measure milliseconds_between last(list_of_positions_aller).time_of_measure;
duration <- int(milliseconds / 1000);
distance_vol_oiseau <- int(distance_to(first(list_of_positions_aller), last(list_of_positions_aller)));
float dist;
create road from: shape_file("../results/Marseille/worker/aller_worker/trajets/aller_worker[" + i + "].shp"){
dist <- dist + self.shape.perimeter;
}
distance <- int(dist);
}
list<position> list_of_positions_retour <- [];
create travel{
create position from: shape_file("../results/Marseille/worker/retour_worker/positions/retour_worker[" + i + "].shp") with: [time_of_measure::(read("time"))]{
list_of_positions_retour << self;
}
float milliseconds <- first(list_of_positions_retour).time_of_measure milliseconds_between last(list_of_positions_retour).time_of_measure;
duration <- int(milliseconds / 1000);
distance_vol_oiseau <- int(distance_to(first(list_of_positions_retour), last(list_of_positions_retour)));
float dist;
create road from: shape_file("../results/Marseille/worker/retour_worker/trajets/retour_worker[" + i + "].shp"){
dist <- dist + self.shape.perimeter;
}
distance <- int(dist);
}
}
ask travel{
save [distance_vol_oiseau, distance, duration] to: "../results/Marseille/worker/workers_travel_time.csv" type:"csv" rewrite: false;
}
}
if students{
write("students travels");
loop i from: 0 to: 2236 {
write(i);
list<position> list_of_positions_aller <- [];
create travel{
create position from: shape_file("../results/Marseille/student/aller_student/positions/aller_student[" + i + "].shp") with: [time_of_measure::(read("time"))]{
list_of_positions_aller << self;
}
float milliseconds <- first(list_of_positions_aller).time_of_measure milliseconds_between last(list_of_positions_aller).time_of_measure;
duration <- int(milliseconds / 1000);
distance_vol_oiseau <- int(distance_to(first(list_of_positions_aller), last(list_of_positions_aller)));
float dist;
create road from: shape_file("../results/Marseille/student/aller_student/trajets/aller_student[" + i + "].shp"){
dist <- dist + self.shape.perimeter;
}
distance <- int(dist);
}
list<position> list_of_positions_retour <- [];
create travel{
create position from: shape_file("../results/Marseille/student/retour_student/positions/retour_student[" + i + "].shp") with: [time_of_measure::(read("time"))]{
list_of_positions_retour << self;
}
float milliseconds <- first(list_of_positions_retour).time_of_measure milliseconds_between last(list_of_positions_retour).time_of_measure;
duration <- int(milliseconds / 1000);
distance_vol_oiseau <- int(distance_to(first(list_of_positions_retour), last(list_of_positions_retour)));
float dist;
create road from: shape_file("../results/Marseille/student/aller_student/trajets/aller_student[" + i + "].shp"){
dist <- dist + self.shape.perimeter;
}
distance <- int(dist);
}
}
ask travel{
save [distance_vol_oiseau, distance, duration] to: "../results/Marseille/student/students_travel_time.csv" type:"csv" rewrite: false;
}
}
}
}
species travel {
int duration; //temps de trajet en secondes
int distance_vol_oiseau; //distance du trajet à vol d'oiseau en metres
int distance;
}
species position {
date time_of_measure;
}
species road {
string fclass;
rgb color <- #blue;
}
experiment bike_traffic type: gui {
output{
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment