... | ... | @@ -188,165 +188,13 @@ to fin-maladie |
|
|
end
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```code
|
|
|
; Le variables globales
|
|
|
; max-infectes : on compte le nombre de malade
|
|
|
;
|
|
|
globals [
|
|
|
initialisation?
|
|
|
max-infectes
|
|
|
cumul-contacts
|
|
|
]
|
|
|
|
|
|
|
|
|
;======================================
|
|
|
; Initialisation de nos pauvres tortues
|
|
|
;======================================
|
|
|
|
|
|
turtles-own[
|
|
|
futur-etat
|
|
|
duree-maladie
|
|
|
]
|
|
|
|
|
|
;
|
|
|
; Initialisation des tortues
|
|
|
; - la couleur code l'état blanche = S, rouge = I, vert = R
|
|
|
; - position aléatoire
|
|
|
; - non infectée (blanche)
|
|
|
to initialisation-tortues
|
|
|
create-turtles population-initiale [
|
|
|
set futur-etat white
|
|
|
set size 0.5
|
|
|
set duree-maladie 0
|
|
|
setxy random-pxcor random-pycor
|
|
|
]
|
|
|
end
|
|
|
|
|
|
;
|
|
|
; On tire au hasard nb-premiere-infectee tortues.
|
|
|
; Leur état change donc.
|
|
|
;
|
|
|
to souche-infection
|
|
|
ask n-of nb-premiere-infectee turtles [
|
|
|
set futur-etat red
|
|
|
]
|
|
|
end
|
|
|
|
|
|
to initialisation
|
|
|
ca
|
|
|
if (alea-fixe) [random-seed 19]
|
|
|
set max-infectes 0
|
|
|
initialisation-tortues
|
|
|
souche-infection
|
|
|
maj-etat
|
|
|
set initialisation? true
|
|
|
reset-ticks
|
|
|
end
|
|
|
|
|
|
to reset
|
|
|
ask turtles [die]
|
|
|
set max-infectes 0
|
|
|
set cumul-contacts 0
|
|
|
initialisation-tortues
|
|
|
souche-infection
|
|
|
maj-etat
|
|
|
reset-ticks
|
|
|
end
|
|
|
|
|
|
|
|
|
;=============================
|
|
|
; La simulation, le modèle SIR
|
|
|
;=============================
|
|
|
|
|
|
;
|
|
|
; Déplacement des tortues. On pourrait avoir un déplacement plus sophistiqué.
|
|
|
;
|
|
|
to bouge
|
|
|
ask turtles [
|
|
|
right random 360
|
|
|
forward pas
|
|
|
]
|
|
|
end
|
|
|
|
|
|
;
|
|
|
; Contamination S -> I
|
|
|
; On compte le nombre de voisines infectées en fonction de la distance
|
|
|
; La contamination se fait en fonction d'une probabilité
|
|
|
;
|
|
|
to infection-des-saines
|
|
|
ask turtles with [color = white] [
|
|
|
let nombre-de-voisines-infectees (count other turtles with [color = red] in-radius distance-non-sociale)
|
|
|
if (random-float 1 < 1 - (((1 - proba-de-transmission) ^ nombre-de-voisines-infectees)))
|
|
|
[set futur-etat red]
|
|
|
]
|
|
|
end
|
|
|
|
|
|
;
|
|
|
; Les infectées sortent de la maladie, elles deviennent remise I -> R
|
|
|
;
|
|
|
to fin-maladie
|
|
|
ask turtles with [color = red]
|
|
|
[
|
|
|
if (duree-maladie > duree-contagion) [ set futur-etat green]
|
|
|
]
|
|
|
end
|
|
|
|
|
|
|
|
|
;=============================
|
|
|
; Informations sur l'évolution
|
|
|
;=============================
|
|
|
Nous avons donc notre modèle, il nous reste à mettre à jour à chaque pas de simulation l'état de nos tortues.
|
|
|
```
|
|
|
to maj-etat
|
|
|
ask turtles [
|
|
|
set color futur-etat
|
|
|
if (color = red) [set duree-maladie duree-maladie + 1]
|
|
|
]
|
|
|
end
|
|
|
|
|
|
to maj-nb-contacts
|
|
|
let cumul 0
|
|
|
ask turtles with [color = red]
|
|
|
[
|
|
|
set cumul cumul + count turtles with [color = white] in-radius distance-non-sociale
|
|
|
]
|
|
|
set cumul-contacts cumul
|
|
|
end
|
|
|
|
|
|
to-report prop-max-infecte
|
|
|
report max-infectes * 100 / population-initiale
|
|
|
end
|
|
|
|
|
|
to-report en-bonne-sante
|
|
|
report (count turtles with [color = white or color = green]) * 100 / population-initiale
|
|
|
end
|
|
|
|
|
|
to-report nb-contacts-moyen-par-tick
|
|
|
let n count turtles with [color = red]
|
|
|
if-else (n = 0)
|
|
|
[ report 0 ]
|
|
|
[ report cumul-contacts / n]
|
|
|
end
|
|
|
|
|
|
|
|
|
to-report R0
|
|
|
report nb-contacts-moyen-par-tick * proba-de-transmission * duree-contagion
|
|
|
end
|
|
|
|
|
|
;
|
|
|
; Lancement de la simulation
|
|
|
;
|
|
|
to execute
|
|
|
let n count turtles with [color = red]
|
|
|
if (n = 0) or (n = population-initiale) [stop]
|
|
|
infection-des-saines
|
|
|
fin-maladie
|
|
|
maj-etat
|
|
|
let nb-infectes (count turtles with [color = red])
|
|
|
if (nb-infectes > max-infectes) [set max-infectes nb-infectes]
|
|
|
maj-nb-contacts
|
|
|
bouge
|
|
|
tick
|
|
|
end
|
|
|
```
|
|
|
|