【发布时间】:2021-05-11 10:24:39
【问题描述】:
我使用以下方法将模拟数据保存为 csv 文件:文件>导出>导出世界,适用于 1 次迭代。我想运行我的模型进行 1000 次模拟(甚至更多),并在每次迭代时保存数据。因为在每次运行时,输出都是不同的。我在 BehaviourSpace 中完成了一个示例,但我的输出数据并不像我使用 File>Export>Export World 得到的那样详细。我还尝试了 csv 示例,并且所有海龟自己的输出(感染?、感染 2?、感染 3?、易感?)都是相同的。
在 BehaviourSpace 中,在 Measure runs using these reports 选项下,我想统计海龟的数量——像被感染?,被感染1?但是当我这样做时,我得到了一个错误; 实验因语法错误而中止:您不能使用 INFECTED?在观察者的情况下,因为感染了?仅限海龟。
我的问题是如何将感染者、感染者 2 和感染者 3 的数量作为 csv 文件进行多次迭代,而无需手动进行(附件是我的代码)。非常感谢任何帮助。谢谢。
globals
[
sink-patches
time1
time2
signs
timeA
prob1
prob2
]
breed [popns popn] ;;T defines the name of a single member of the breed.
breed [ppls ppl]
popns-own
[
infected?
infected2?
infected3?
susceptible?
infected-time
infection2-time
]
;; setup procedures
to setup
clear-all
setup-patches
setup-globals
setup-people
reset-ticks ; Resets the tick counter to zero, sets up all plots, then updates all plots.
end
to setup-globals
set signs 13
set timeA signs + time1
set prob1 25
set prob2 50
end
to setup-patches ; Create a patch ; Enlarge this patch to increase BU stage 1 infections.
clear-all
let sink-patch-radius 2 ;increase the size of the patch here
let sink-centre patch 0 0 ;centre of the patch
set sink-patches [patches in-radius sink-patch-radius] of sink-centre ; neighbouring patches
;set sink-patches with [abs pxcor <= 8 and abs pycor <= 8]
ask sink-patches [ set pcolor gray ] ;set the patch to color gray
end
to setup-people
create-popns start-people ;setting up people
[
setxy random-xcor random-ycor
set infected? false
set infected2? false
set infected3? false
set susceptible? true
set shape "circle"
set color brown
set infected-time 0
set infection2-time 0
]
create-ppls start-otherPeople ; other population
[
setxy random-xcor random-ycor
set shape "circle"
set color white
]
end
to assign-color ;; turtle procedure
if infected?
[ set color red ]
if infected2?
[ set color blue ]
if infected3?
[ set color yellow ]
end
;; Go procedures
to go
ask popns[ assign-color]
ask popns[ infect_start]
ask popns with [ infected? ]
[ infect_two ]
ask popns with [ infected2? ]
[ infect_three ]
ask popns [count-update] ;
ask turtles [move]
tick
end
;; People move about at random.
to move ;; turtle procedure
rt random-float 360 ;the turtle turns right by 360 degrees.
fd 1
end
to infect_start ;stage one;;
let healthy (popns-on sink-patches) with [ susceptible? ]
if (random-float 100 < Infection-Rate)
[
ask healthy
[
set infected? true
set susceptible? false
]
]
end
to infect_two ;Infect stage two = green
if infected-time > timeA
[set infected? false
set infected2? true
]
end
to infect_three ;Infect stage three= yellow
if infection2-time > time2
[
set infected2? false
set infected3? true
]
end
to count-update ; This updates the count of time in the various stages of infection or treatments
if (infected? or infected2? or infected3?) [set infected-time infected-time + 1 ]
if infected2? [set infection2-time infection2-time + 1 ]
end
【问题讨论】:
标签: iteration export-to-csv netlogo