首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >报告来自第一个刻度NetLogo的值的数组

报告来自第一个刻度NetLogo的值的数组
EN

Stack Overflow用户
提问于 2018-03-04 03:50:37
回答 1查看 54关注 0票数 0

我正在写一些代码,在流感流行的人群中为个人接种疫苗。该代码有两种疫苗,分别名为HOV和HEV。HOV给出了与我想要目标人群比例相同的疫苗毒株。HEV为这一比例提供了不同的疫苗株(随机确定)。

我想要一行代码,在每个模拟的第一个滴答声中报告每只海龟的免疫状态。在这个模型中,免疫状态用一个整数来表示,因此不同的海龟将有不同的免疫标签,这取决于它们是否接种了疫苗。我希望在最终的BehaviourSpace .csv输出中得到一个列,其中包含所有海龟在第一个节拍中的免疫标签数组。

我的代码如下:

代码语言:javascript
复制
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

任何建议都将不胜感激!谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-03-04 04:17:25

转念一想--我想我找到了答案!我基本上创建了一个列表列表,一旦setup命令完成,它就会存储免疫标签。我的更新代码如下:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49088540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档