当前位置:网站首页>Simulating Sir disease transmission model with netlogo
Simulating Sir disease transmission model with netlogo
2022-06-25 15:26:00 【BlackPenguin】
Studying recently Netlogo Software , Its language is very different from the programming language I learned before . After reading the code of the model library, I slowly understand . Here are SIR Propagation model code .
Need to create
Button :setup, go
slider :num-nodes, initial-outbreak-size, infect-rate, recover-rate
(’;’ It's a comment )
;SIR Propagation model
turtles-own
[
infected? ; The value is true perhaps false
recover?
explore?
]
globals[ ; Global variables
average-node-degree ; Node average degree
]
;;;;;;;;;;;;;;;;;;;;;;;;
;;; Setup Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;
to setup ; setup Button method
clear-all
set average-node-degree 4 ; Set average to 4
setup-nodes
setup-spatially-clustered-network
ask n-of initial-outbreak-size turtles ; From all turtles Select the initial-outbreak-size individual ( Initial infection node )
[ become-infected ]
ask links [ set color white ]
reset-ticks
end
to setup-nodes ; Initialize node
set-default-shape turtles "circle"
create-turtles num-nodes[
setxy (random-xcor * 0.95) (random-ycor * 0.95)
become-susceptible
set size 2
initial-explored
]
end
to setup-spatially-clustered-network ; Initialize edge connection
let num-links (average-node-degree * num-nodes) / 2
while [count links < num-links ]
[
ask one-of turtles ;; The drawn edges have a layout
[
let choice (min-one-of (other turtles with [not link-neighbor? myself])
[distance myself])
if choice != nobody [ create-link-with choice ]
]
]
; make the network look a little prettier
repeat 10
[
layout-spring turtles links 0.1 (world-width / (sqrt num-nodes)) 1
]
end
;;;;;;;;;;;;;;;;;;;;;;;;
;;; go Procedures ;;;
;;;;;;;;;;;;;;;;;;;;;;;;
to go
if all? turtles [not infected?]
[ stop ]
if all? turtles [recover?]
[ stop ]
spread-virus
recover-virus
tick
end
to spread-virus
ask turtles [ initial-explored ] ;;explore Value initialization , All for false.true Indicates the infected nodes in this round
ask turtles with [infected?]
[
ask link-neighbors with [not recover?]
[
if random-float 1 < infect-rate
[
become-infected
change-explore
]
]
]
end
to recover-virus
ask turtles with [infected? and not explore?]
[
if random-float 1 < recover-rate
[
become-recovery
]
]
end
to initial-explored
set explore? false
end
to change-explore
set explore? true
end
to become-susceptible
set infected? false
set recover? false
set color blue
end
to become-infected
set infected? true
set recover? false
set color red
end
to become-recovery
set infected? false
set recover? true
set color yellow
end

边栏推荐
- One question per day, a classic simulation question
- Breakpad usage and DMP analysis
- Data feature analysis skills - correlation test
- [C language] implementation of magic square array (the most complete)
- System Verilog - data type
- About?: Notes for
- Luogu p5707 [deep foundation 2. example 12] late for school
- Basic knowledge of pointer
- Leetcode122 timing of buying and selling stocks II
- Go language template text/template error unexpected EOF
猜你喜欢

Stack and queue

Websocket (WS) cluster solution

Source code analysis of zeromq lockless queue
![[paper notes] contextual transformer networks for visual recognition](/img/e4/45185983e28664564bbf79023ccbf6.jpg)
[paper notes] contextual transformer networks for visual recognition
![[paper notes] street view change detection with deconvolutional networks](/img/2d/777fd0d85ff4d349516b95923410fd.jpg)
[paper notes] street view change detection with deconvolutional networks

CV pre training model set

One question per day,

Judging the number of leap years from 1 to N years

Image segmentation based on deep learning: network structure design
![[paper notes] poly yolo: higher speed, more precise detection and instance segmentation for yolov3](/img/28/6d58759a4a4b18923a5ed5ed573956.jpg)
[paper notes] poly yolo: higher speed, more precise detection and instance segmentation for yolov3
随机推荐
Leetcode121 timing of buying and selling stocks
Fishing detection software
If multiple signals point to the same slot function, you want to know which signal is triggered.
QT source code online view
Bessie's weight problem [01 backpack]
Qlogsystem log system configuration use
google_ Breakpad crash detection
GDB debugging
Websocket (WS) cluster solution
If a thread overflows heap memory or stack memory, will other threads continue to work
QT article outline
Work of the first week
System Verilog - thread
Arthas source code learning-1
basic_ String mind map
[paper notes] street view change detection with deconvolutional networks
QT pop up open file dialog box QFileDialog
QT pattern prompt box implementation
Go language modifies / removes multiple line breaks in strings
How to package rpm