Advertisement
rodolpheg

Untitled

Nov 19th, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. // Nom du modèle
  2. model trafic
  3.  
  4. // Méthode globale définissant l'environnement.
  5. global {
  6. file shp_bati <- file("../includes/bati.shp");
  7. file shp_rue <- file("../includes/rues_vm.shp");
  8. geometry shape <- envelope(shp_rue);
  9. graph reseau;
  10.  
  11. int min_deb_trav <- 6;
  12. int max_deb_trav <- 8;
  13.  
  14. float step <- 1 #mn;
  15.  
  16. init {
  17. create bati from: shp_bati;
  18. create rue from: shp_rue;
  19. reseau <- as_edge_graph(shp_rue);
  20.  
  21. create resident number: 100 {
  22. debut_trav <- rnd (min_deb_trav, max_deb_trav);
  23. fin_trav <- debut_trav + rnd(7, 9);
  24. residence <- one_of (list<bati>(bati));
  25. travail <- one_of (list<bati>(bati));
  26. objectif <- "repos";
  27. location <- residence;
  28. }
  29. }
  30. }
  31.  
  32. // Agent "bati"
  33. species bati {
  34. aspect base {
  35. draw shape color: #darkgrey ;
  36. }
  37. }
  38.  
  39. // Agent "rue"
  40. species rue {
  41. rgb color <- #grey ;
  42. aspect base {
  43. draw shape color: color;
  44. }
  45. }
  46.  
  47. // Agents "résidents"
  48. species resident skills: [moving] {
  49. rgb color <- rgb(243, 214, 72);
  50. bati residence <- nil;
  51. bati travail <- nil;
  52. int debut_trav;
  53. int fin_trav;
  54. string objectif;
  55. point target <- nil;
  56.  
  57. // À chaque itération, regarder l'heure et vérifier s'il est temps de partir au travail
  58. reflex au_boulot when: current_date.hour = debut_trav and objectif = "repos" {
  59. // si c'est le cas, donner l'objectif "travailler" à l'agent
  60. objectif <- "travailler";
  61. // et lui donner pour destination "travail" (la destination avant ça était "nil")
  62. target <- any_location_in(travail);
  63. }
  64.  
  65. // À chaque itération, regarder l'heure et vérifier s'il est temps de rentrer
  66. reflex au_repos when: current_date.hour = fin_trav and objectif = "travailler" {
  67. // si c'est le cas, donner l'objectif "travailler" à l'agent
  68. objectif <- "repos";
  69. // et lui donner pour destination "travail" (la destination avant ça était "nil")
  70. target <- any_location_in(residence);
  71. }
  72.  
  73. // À chaque itération, regarder si la variable destination est différente "nil"
  74. reflex move when: target != nil {
  75. // si c'est le cas, c'est qu'une destination est "programmée". Le prgramme enverra donc l'agent en question
  76. // vers sa destination, en passant à travers le réseau
  77. do goto target: target on: reseau;
  78. if target = location {
  79. // une fois arrivé, sa destination devient nil
  80. target <- nil;
  81. }
  82. }
  83.  
  84. aspect base {
  85. draw circle(20) color: color;
  86. }
  87. }
  88.  
  89. // Définition de la simulaiton et de ses affichages
  90. experiment trafic type: gui {
  91. output {
  92. display ville_marie type:opengl background: rgb(50, 50, 50) {
  93. species bati aspect: base ;
  94. species rue aspect: base ;
  95. species resident aspect: base ;
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement