Arrays 报告来自第一个tick NetLogo的值数组
我正在写一些代码,为流感流行的人群中的个人接种疫苗。该代码有两种疫苗,分别命名为HOV和HEV。HOV提供了与我想要针对的人群比例相同的疫苗株。HEV按此比例提供不同的疫苗株(随机确定) 我想要一行代码,在每次模拟的第一个滴答声中报告每只海龟的免疫状态。在这个模型中,免疫状态由一个整数表示,因此不同的海龟将根据是否接种疫苗而具有不同的免疫标签。我希望在最后的BehaviorSpace.csv输出中,在每次运行的第一个滴答声中,以一列包含所有海龟免疫标签的列结束 我的代码如下:Arrays 报告来自第一个tick NetLogo的值数组,arrays,list,netlogo,modeling,Arrays,List,Netlogo,Modeling,我正在写一些代码,为流感流行的人群中的个人接种疫苗。该代码有两种疫苗,分别命名为HOV和HEV。HOV提供了与我想要针对的人群比例相同的疫苗株。HEV按此比例提供不同的疫苗株(随机确定) 我想要一行代码,在每次模拟的第一个滴答声中报告每只海龟的免疫状态。在这个模型中,免疫状态由一个整数表示,因此不同的海龟将根据是否接种疫苗而具有不同的免疫标签。我希望在最后的BehaviorSpace.csv输出中,在每次运行的第一个滴答声中,以一列包含所有海龟免疫标签的列结束 我的代码如下: extension
extensions [csv]
globals [strain_list_list epidemic-threshold cumulative-infections proportion-of-infection currently-infected peak-prevalence vax-strain]
turtles-own [infection-period infection-number tflu-strain immune-label ant-distance cross-immunity]
patches-own [fomite-age pflu-strain]
to setup
clear-all
setup-turtles
reset-ticks
end
to setup-turtles
create-turtles 100
ask turtles [setxy random-xcor random-ycor]
ask turtles [set color white set infection-number 0 set immune-label -999999999999 set tflu-strain -999999999999]
ask one-of turtles [set color red set infection-period 0 set infection-number 1 set immune-label 0 set tflu-strain 0]
if vaccine = "HOV" [
ifelse (one-of [1 2] = 1) [
set vax-strain (random ((2 * drift-size) + 1))]
[set vax-strain (-1 * random ((2 * drift-size) + 1))]
ask n-of prop-vax turtles with [color = white] [set color blue set immune-label vax-strain]
]
if vaccine = "HEV" [
let vax-turtles (list turtles with [color = blue])
ask n-of prop-vax turtles with [color = white] [set color blue]
foreach [vax-turtles] [
ifelse (one-of [1 2] = 1) [
set vax-strain (random ((2 * drift-size) + 1))]
[set vax-strain (-1 * random ((2 * drift-size) + 1))]
]
]
set epidemic-threshold "no"
set cumulative-infections 0
set peak-prevalence 0
end
to go
if ticks = flu-season-length [stop]
move-infecteds
move-uninfecteds
transmit
mutate
update-immunity
track-infecteds
set cumulative-infections (count turtles with [infection-period = 1] + cumulative-infections)
set proportion-of-infection (100 - (count turtles with [immune-label = -999999999999]))
set currently-infected (count turtles with [infection-period = 1])
tick
end
to move-infecteds ;; infected turtles move slower than uninfected ones and always transmit infection to patches before they leave them
ask turtles with [color = red] [
if pcolor = black [
set pcolor red
set fomite-age 0
set pflu-strain tflu-strain]
right random 360
forward 3
]
end
to transmit ;; uninfected turtles are infected by fomites (red patches) with some probability. immune-labelling currently first infection
ask turtles with [color = white or color = blue and pcolor = red] [
if immune-label != pflu-strain [
set ant-distance (abs (immune-label - pflu-strain))
set cross-immunity (natural-immunity * (1 - (ant-distance / antigenic-distance-limit)))
if cross-immunity < 0 [set cross-immunity 0]
if random 100 < (((100 - cross-immunity) / 100) * probability-of-infection)
[set color red set infection-period 0 set infection-number infection-number + 1 set tflu-strain pflu-strain]
]
if immune-label = pflu-strain [
if random 100 < (((100 - natural-immunity) / 100) * probability-of-infection)
[set color red set infection-period 0 set infection-number infection-number + 1 set tflu-strain pflu-strain]
]
]
end
to mutate ;; some probability of mutation (change in strain label) when an individual receives infection from a patch
ifelse in-host [
ask turtles with [color = red] [
if random 100 < probability-of-mutation [
ifelse (one-of [1 2] = 1) [
set tflu-strain (tflu-strain + (random (drift-size + 1)))]
[set tflu-strain (tflu-strain - (random (drift-size + 1)))]
]
]
]
[ask turtles with [color = red and infection-period = 0] [
if random 100 < probability-of-mutation [
ifelse (one-of [1 2] = 1) [
set tflu-strain (tflu-strain + (random (drift-size + 1)))]
[set tflu-strain (tflu-strain - (random (drift-size + 1)))]
]
]
]
end
to update-immunity
ask turtles with [color = red and infection-period = 0] [
ifelse immune-labelling = "first-infection" [
if immune-label = -999999999999 [
set immune-label tflu-strain]]
[set immune-label tflu-strain]
]
end
to track-infecteds ;; turtles with given infection period should become uninfected
ask turtles with [color = red] [
set infection-period infection-period + 1
if infection-period = age-infection-max [
set color white set infection-period 0 set tflu-strain -999999999999
]
]
ask patches with [pcolor = red] [
set fomite-age fomite-age + 1
if fomite-age > max-fomite-persistence [
set pcolor black
]
]
end
extensions [csv]
globals [initial-immunity-array epidemic-threshold cumulative-infections proportion-of-infection currently-infected peak-prevalence vax-strain]
turtles-own [infection-period infection-number tflu-strain immune-label ant-distance cross-immunity]
patches-own [fomite-age pflu-strain]
to setup
clear-all
setup-turtles
set initial-immunity-array (list t-sorted-immunity-list)
print initial-immunity-array
reset-ticks
end
to setup-turtles
create-turtles 100
ask turtles [setxy random-xcor random-ycor]
ask turtles [set color white set infection-number 0 set immune-label -999999999999 set tflu-strain -999999999999 set vax-strain -999999999999]
ask one-of turtles [set color red set infection-period 0 set infection-number 1 set immune-label 0 set tflu-strain 0]
if vaccine = "HEV" [
ask n-of prop-vax turtles with [color = white] [set color blue]
ask turtles with [color = blue] [
ifelse (one-of [1 2] = 1) [
set vax-strain (random ((2 * drift-size) + 1))]
[set vax-strain (-1 * random ((2 * drift-size) + 1))]
set immune-label vax-strain
]
]
if vaccine = "HOV" [
ask n-of prop-vax turtles with [color = white] [set color blue]
ifelse (one-of [1 2] = 1) [
set vax-strain (random ((2 * drift-size) + 1))]
[set vax-strain (-1 * random ((2 * drift-size) + 1))]
ask turtles with [color = blue] [set immune-label vax-strain
]
]
set epidemic-threshold "no"
set cumulative-infections 0
set peak-prevalence 0
end
to-report t-sorted-immunity-list
report map [i -> [immune-label] of i] sort turtles
end
to go
if ticks = flu-season-length [stop]
move-infecteds
move-uninfecteds
transmit
mutate
update-immunity
track-infecteds
show-strains
track-epidemic
set cumulative-infections (count turtles with [infection-period = 1] + cumulative-infections)
set proportion-of-infection (100 - (count turtles with [immune-label = -999999999999]))
set currently-infected (count turtles with [infection-period = 1])
end
extensions[csv]
globals[毒株\列表\列表流行阈值累计感染当前感染的感染比例峰值流行vax毒株]
海龟自身[感染期感染数tflu菌株免疫标签蚂蚁距离交叉免疫]
斑片自身[fomite age pflu株]
设置
清除所有
安置海龟
重置滴答声
终止
安置海龟
创造海龟100
询问海龟[setxy random xcor random ycor]
询问海龟[设置颜色白色设置感染编号0设置免疫标签-9999999999设置tflu菌株-9999999999]
询问一只海龟[设置颜色红色设置感染期0设置感染编号1设置免疫标签0设置tflu菌株0]
如果疫苗=“HOV”[
ifelse(其中一个[12]=1)[
设置vax应变(随机((2*漂移尺寸)+1))]
[设置vax应变(-1*随机((2*漂移大小)+1))]
询问带有[颜色=白色][设置颜色蓝色设置免疫标签vax菌株]
]
如果疫苗=“HEV”[
让vax海龟(用[color=blue]列出海龟)
用[color=white][set color blue]
foreach[vax海龟][
ifelse(其中一个[12]=1)[
设置vax应变(随机((2*漂移尺寸)+1))]
[设置vax应变(-1*随机((2*漂移大小)+1))]
]
]
设置流行病阈值“否”
将累积感染设置为0
将最高流行率设为0
终止
外带
如果滴答声=流感季节长度[停止]
移动感染者
移动未感染者
传输
变异
更新免疫
追踪感染者
设置累积感染(计算[感染期=1]+累积感染的海龟)
设定感染比例(100-(计数带有[免疫标签=-9999999999]的海龟)
设置当前受感染的海龟数量(计数[感染期=1])
打上钩
终止
移动受感染者;;受感染的海龟比未受感染的海龟移动速度慢,在离开之前总是将感染传播到斑块
问海龟[颜色=红色][
如果pcolor=黑色[
设置颜色为红色
将fomite年龄设置为0
设置pflu应变tflu应变]
右随机360
转发3
]
终止
传播;;未受感染的海龟有一定的可能性被叶螨(红色斑点)感染。免疫标记目前是第一次感染
问海龟[颜色=白色或颜色=蓝色,颜色=红色][
如果免疫标签!=pflu菌株[
设置蚂蚁距离(abs(免疫标签-pflu菌株))
设置交叉免疫(自然免疫*(1-(蚂蚁距离/抗原距离限制)))
如果交叉抗扰度<0[设置交叉抗扰度0]
如果随机100<((100-交叉免疫)/100)*感染概率)
[设置颜色红色设置感染期0设置感染号感染号+1设置tflu株pflu株]
]
如果免疫标签=pflu菌株[
如果随机100<((100-自然免疫)/100)*感染概率)
[设置颜色红色设置感染期0设置感染号感染号+1设置tflu株pflu株]
]
]
终止
变异;;当一个个体从一个补丁中受到感染时发生突变的概率(菌株标签的变化)
如果主机中有其他[
问海龟[颜色=红色][
如果随机100<突变概率[
ifelse(其中一个[12]=1)[
设置tflu应变(tflu应变+(随机(漂移大小+1)))]
[设置tflu应变(tflu应变-(随机(漂移大小+1)))]
]
]
]
[询问海龟[颜色=红色,感染期=0][
如果随机100<突变概率[
ifelse(其中一个[12]=1)[
设置tflu应变(tflu应变+(随机(漂移大小+1)))]
[设置tflu应变(tflu应变-(随机(漂移大小+1)))]
]
]
]
终止
更新豁免权
问海龟[颜色=红色,感染期=0][
ifelse免疫标签=“首次感染”[
如果免疫标签=-99999999[
设置免疫标签tflu菌株]]
[设置免疫标签tflu菌株]
]
终止
追踪感染者;;具有特定感染期的海龟应不受感染
问海龟[颜色=红色][
设置感染期感染期+1
如果感染期=年龄感染最大值[
设置颜色白色设置感染期0设置tflu菌株-99999999
]
]
使用[pcolor=红色]询问补丁[
设置fomite年龄fomite年龄+1
如果fomite年龄>最大fomite持续时间[
设置彩色黑色
]
]
终止
任何建议都将不胜感激!谢谢 再想想——我想我找到了答案!基本上,我创建了一个列表,在setup命令完成后存储免疫标签。我的更新代码如下:
extensions [csv]
globals [strain_list_list epidemic-threshold cumulative-infections proportion-of-infection currently-infected peak-prevalence vax-strain]
turtles-own [infection-period infection-number tflu-strain immune-label ant-distance cross-immunity]
patches-own [fomite-age pflu-strain]
to setup
clear-all
setup-turtles
reset-ticks
end
to setup-turtles
create-turtles 100
ask turtles [setxy random-xcor random-ycor]
ask turtles [set color white set infection-number 0 set immune-label -999999999999 set tflu-strain -999999999999]
ask one-of turtles [set color red set infection-period 0 set infection-number 1 set immune-label 0 set tflu-strain 0]
if vaccine = "HOV" [
ifelse (one-of [1 2] = 1) [
set vax-strain (random ((2 * drift-size) + 1))]
[set vax-strain (-1 * random ((2 * drift-size) + 1))]
ask n-of prop-vax turtles with [color = white] [set color blue set immune-label vax-strain]
]
if vaccine = "HEV" [
let vax-turtles (list turtles with [color = blue])
ask n-of prop-vax turtles with [color = white] [set color blue]
foreach [vax-turtles] [
ifelse (one-of [1 2] = 1) [
set vax-strain (random ((2 * drift-size) + 1))]
[set vax-strain (-1 * random ((2 * drift-size) + 1))]
]
]
set epidemic-threshold "no"
set cumulative-infections 0
set peak-prevalence 0
end
to go
if ticks = flu-season-length [stop]
move-infecteds
move-uninfecteds
transmit
mutate
update-immunity
track-infecteds
set cumulative-infections (count turtles with [infection-period = 1] + cumulative-infections)
set proportion-of-infection (100 - (count turtles with [immune-label = -999999999999]))
set currently-infected (count turtles with [infection-period = 1])
tick
end
to move-infecteds ;; infected turtles move slower than uninfected ones and always transmit infection to patches before they leave them
ask turtles with [color = red] [
if pcolor = black [
set pcolor red
set fomite-age 0
set pflu-strain tflu-strain]
right random 360
forward 3
]
end
to transmit ;; uninfected turtles are infected by fomites (red patches) with some probability. immune-labelling currently first infection
ask turtles with [color = white or color = blue and pcolor = red] [
if immune-label != pflu-strain [
set ant-distance (abs (immune-label - pflu-strain))
set cross-immunity (natural-immunity * (1 - (ant-distance / antigenic-distance-limit)))
if cross-immunity < 0 [set cross-immunity 0]
if random 100 < (((100 - cross-immunity) / 100) * probability-of-infection)
[set color red set infection-period 0 set infection-number infection-number + 1 set tflu-strain pflu-strain]
]
if immune-label = pflu-strain [
if random 100 < (((100 - natural-immunity) / 100) * probability-of-infection)
[set color red set infection-period 0 set infection-number infection-number + 1 set tflu-strain pflu-strain]
]
]
end
to mutate ;; some probability of mutation (change in strain label) when an individual receives infection from a patch
ifelse in-host [
ask turtles with [color = red] [
if random 100 < probability-of-mutation [
ifelse (one-of [1 2] = 1) [
set tflu-strain (tflu-strain + (random (drift-size + 1)))]
[set tflu-strain (tflu-strain - (random (drift-size + 1)))]
]
]
]
[ask turtles with [color = red and infection-period = 0] [
if random 100 < probability-of-mutation [
ifelse (one-of [1 2] = 1) [
set tflu-strain (tflu-strain + (random (drift-size + 1)))]
[set tflu-strain (tflu-strain - (random (drift-size + 1)))]
]
]
]
end
to update-immunity
ask turtles with [color = red and infection-period = 0] [
ifelse immune-labelling = "first-infection" [
if immune-label = -999999999999 [
set immune-label tflu-strain]]
[set immune-label tflu-strain]
]
end
to track-infecteds ;; turtles with given infection period should become uninfected
ask turtles with [color = red] [
set infection-period infection-period + 1
if infection-period = age-infection-max [
set color white set infection-period 0 set tflu-strain -999999999999
]
]
ask patches with [pcolor = red] [
set fomite-age fomite-age + 1
if fomite-age > max-fomite-persistence [
set pcolor black
]
]
end
extensions [csv]
globals [initial-immunity-array epidemic-threshold cumulative-infections proportion-of-infection currently-infected peak-prevalence vax-strain]
turtles-own [infection-period infection-number tflu-strain immune-label ant-distance cross-immunity]
patches-own [fomite-age pflu-strain]
to setup
clear-all
setup-turtles
set initial-immunity-array (list t-sorted-immunity-list)
print initial-immunity-array
reset-ticks
end
to setup-turtles
create-turtles 100
ask turtles [setxy random-xcor random-ycor]
ask turtles [set color white set infection-number 0 set immune-label -999999999999 set tflu-strain -999999999999 set vax-strain -999999999999]
ask one-of turtles [set color red set infection-period 0 set infection-number 1 set immune-label 0 set tflu-strain 0]
if vaccine = "HEV" [
ask n-of prop-vax turtles with [color = white] [set color blue]
ask turtles with [color = blue] [
ifelse (one-of [1 2] = 1) [
set vax-strain (random ((2 * drift-size) + 1))]
[set vax-strain (-1 * random ((2 * drift-size) + 1))]
set immune-label vax-strain
]
]
if vaccine = "HOV" [
ask n-of prop-vax turtles with [color = white] [set color blue]
ifelse (one-of [1 2] = 1) [
set vax-strain (random ((2 * drift-size) + 1))]
[set vax-strain (-1 * random ((2 * drift-size) + 1))]
ask turtles with [color = blue] [set immune-label vax-strain
]
]
set epidemic-threshold "no"
set cumulative-infections 0
set peak-prevalence 0
end
to-report t-sorted-immunity-list
report map [i -> [immune-label] of i] sort turtles
end
to go
if ticks = flu-season-length [stop]
move-infecteds
move-uninfecteds
transmit
mutate
update-immunity
track-infecteds
show-strains
track-epidemic
set cumulative-infections (count turtles with [infection-period = 1] + cumulative-infections)
set proportion-of-infection (100 - (count turtles with [immune-label = -999999999999]))
set currently-infected (count turtles with [infection-period = 1])
end