Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Nom du modèle
- model trafic
- // Méthode globale définissant l'environnement.
- global {
- file shp_bati <- file("../includes/bati.shp");
- file shp_rue <- file("../includes/rues_vm.shp");
- geometry shape <- envelope(shp_rue);
- graph reseau;
- int min_deb_trav <- 6;
- int max_deb_trav <- 8;
- float step <- 1 #mn;
- init {
- create bati from: shp_bati;
- create rue from: shp_rue;
- reseau <- as_edge_graph(shp_rue);
- create resident number: 100 {
- debut_trav <- rnd (min_deb_trav, max_deb_trav);
- fin_trav <- debut_trav + rnd(7, 9);
- residence <- one_of (list<bati>(bati));
- travail <- one_of (list<bati>(bati));
- objectif <- "repos";
- location <- residence;
- }
- }
- }
- // Agent "bati"
- species bati {
- aspect base {
- draw shape color: #darkgrey ;
- }
- }
- // Agent "rue"
- species rue {
- rgb color <- #grey ;
- aspect base {
- draw shape color: color;
- }
- }
- // Agents "résidents"
- species resident skills: [moving] {
- rgb color <- rgb(243, 214, 72);
- bati residence <- nil;
- bati travail <- nil;
- int debut_trav;
- int fin_trav;
- string objectif;
- point target <- nil;
- // À chaque itération, regarder l'heure et vérifier s'il est temps de partir au travail
- reflex au_boulot when: current_date.hour = debut_trav and objectif = "repos" {
- // si c'est le cas, donner l'objectif "travailler" à l'agent
- objectif <- "travailler";
- // et lui donner pour destination "travail" (la destination avant ça était "nil")
- target <- any_location_in(travail);
- }
- // À chaque itération, regarder l'heure et vérifier s'il est temps de rentrer
- reflex au_repos when: current_date.hour = fin_trav and objectif = "travailler" {
- // si c'est le cas, donner l'objectif "travailler" à l'agent
- objectif <- "repos";
- // et lui donner pour destination "travail" (la destination avant ça était "nil")
- target <- any_location_in(residence);
- }
- // À chaque itération, regarder si la variable destination est différente "nil"
- reflex move when: target != nil {
- // si c'est le cas, c'est qu'une destination est "programmée". Le prgramme enverra donc l'agent en question
- // vers sa destination, en passant à travers le réseau
- do goto target: target on: reseau;
- if target = location {
- // une fois arrivé, sa destination devient nil
- target <- nil;
- }
- }
- aspect base {
- draw circle(20) color: color;
- }
- }
- // Définition de la simulaiton et de ses affichages
- experiment trafic type: gui {
- output {
- display ville_marie type:opengl background: rgb(50, 50, 50) {
- species bati aspect: base ;
- species rue aspect: base ;
- species resident aspect: base ;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement