Advertisement
rodolpheg

Untitled

Nov 18th, 2020
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 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: 10 {
  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. reflex au_repos when: current_date.hour = fin_trav and objectif = "travailler" {
  66. // si c'est le cas, donner l'objectif "travailler" à l'agent
  67. objectif <- "repos";
  68. // et lui donner pour destination "travail" (la destination avant ça était "nil")
  69. target <- any_location_in(residence);
  70. }
  71.  
  72. //
  73. // Ajoutez ici un 'reflex" pour faire rentrer les résidents chez eux après le travail
  74. //
  75.  
  76. // À chaque itération, regarder si la variable destination est différente "nil"
  77. reflex move when: target != nil {
  78. // si c'est le cas, c'est qu'une destination est "programmée". Le prgramme enverra donc l'agent en question
  79. // vers sa destination, en passant à travers le réseau
  80. do goto target: target on: reseau;
  81. if target = location {
  82. // une fois arrivé, sa destination devient nil
  83. target <- nil;
  84. }
  85. }
  86.  
  87. aspect base {
  88. draw circle(20) color: color;
  89. }
  90. }
  91.  
  92. // Définition de la simulaiton et de ses affichages
  93. experiment trafic type: gui {
  94. output {
  95. display ville_marie type:opengl background: rgb(50, 50, 50) {
  96. species bati aspect: base ;
  97. species rue aspect: base ;
  98. species resident aspect: base ;
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement