当前位置:文档之家› -系统工程课内实验报告

-系统工程课内实验报告

to infect
ask turtles with [sick?]
[ ask other turtles-here with [ not immune? ]
[ if (random-float 100) < infectiousness
[ get-sick ]感染其他变量通过同样的途径
免疫的变量不会得病
感染
询问变量带有[病毒?]
[询问这里其他变量带有[没有免疫?]
[如果(随机量-浮动100)小于被感染体
[感染病毒] ] ]
结束
;; Once the turtle has been sick long enough, it
;; either recovers (and becomes immune) or it dies.
set-current-plot-pen "sick"
plot count turtles with [sick?]
set-current-plot-pen "immune"
plot count turtles with [immune?]
set-current-plot-pen "healthy"
[
设置被感染的百分比(基础变量数目带有[感染病毒])/(基础变量数目)*100
设置免疫的百分比(基础变量数目带有[免疫的])/(基础变量数目)*100
]
结束
;;Turtle counting variables are advanced.
to get-older
ask turtles
[
set age age + 1
设置
清除所有
设置常量
设置变量
更新情节
更新全局变量
结束
;; We create a variable number of turtles of which 10 are infectious,
;; and distribute them randomly
to setup-turtles
set-default-shape turtles "person"
to recover
ask turtles with [sick?]
[ if (random sick-count) > (lifespan * (duration / 100)) ;; If the turtle has survived past the virus' duration, then
绘制变量数量带有[免疫?]
设置当前绘图笔“健康”
绘制变量数量带有[没有感染病毒?并且没有免疫力?]
设置当前绘图笔“总量”
绘制当前变量
结束
2)基本算法流程分析:
第一步:设置初始情节,一百五十人中有十人是感染病毒的。其余人群都是易被感染的。感染率为65%,回复几率为50%,二十周为一个时间段。
第二步:点击开始模拟。时间经过了两年半,感染率达到60.7%,免疫率是21.4%。
结束
to go
get-older
move
infect
recover
reproduce
update-global-variables
tick
update-plot
end
运行
变得更老
移动
感染
恢复健康
繁衍
更新全局变量
记号
更新情节
结束
to update-global-variables
if count turtles > 0
set sick? true
set immune? false
set color red
end
设置得病基础变量进程
设置感染病毒正确
设置免疫的错误
设置颜色红色
结束
to get-healthy ;; turtle procedure
set sick? false
set immune? false
set sick-count 0
]
end
基础计数变量是进化的
变得更老
询问基础变量
[
设置时间时间+1
如果感染病毒
[设置感染病毒人数(得病人数+1)]
当基础变量的寿命等同于生命长度(在这个模型中设置1500)
如果寿命大于生命长度
[死亡]
]
结束
;;Turtles move about at random.
to move
ask turtles
%immune ;; what % of the population is immune
lifespan ;; the average lifespan of a turtle
average-offspring ;; the average number of offspring a turtle could have
end
变成免疫变量进程
设置感染病毒错误
设置感染病毒人数0
设置免疫正确
设置颜色灰色
结束
to setup-constants
set lifespan 100
set carrying-capacity 750
set average-offspring 4
end
设置常量
设置生命长度100
设置运输能力750
设置平均后代4
and (random lifespan) < average-offspring
[ hatch 1
[ set age 1
lt 45 fd 1
get-healthy ] ] ]
end
如果变量比运输能力还要少
然后变量可以繁衍
繁衍能力由每个生命的后代的平均数量决定
在这个模型中是每个生命4个后代(例如.每一百周4个)
[ rt random 100
lt random 100
fd 1 ]
end
基础变量随意移动
移动
询问基础变量
[右边随机值100
左边随机值100
每次1步]
结束
;; If a turtle is sick, it infects other turtles on the same patch.
;; Immune turtles don't get sick.
;; reproduce at any given turn is 0.04 (if the population
;; is below carrying-capacity).
to reproduce
ask turtles with [not sick?]
[ if (count turtles) < carrying-capacity
因此,在任何假设的转换中每个变量繁衍的机会是0.04(如果人口是在运输能力之下)
繁衍
询问变量带有[没有感染病毒?]
[如果(变量数量)<运输能力
并且(生命长度随机值)<平均值-后代
[孵化1
[设置时间1
左边值45每次前进1步
设置健康] ] ]
结束
to update-plot
set-current-plot "Populations"
crt people
[ setxy random-xcor random-ycor
set age random lifespan
set sick-count 0
set immune? false
set size 1.5 ;; easier to see
get-healthy ]
ask n-of 10 turtles
[
set %infected (count turtles with [sick?]) / (count turtles) * 100
set %immune (count turtles with [immune?]) / (count turtles) * 100
]
end
更新全局变量
如果基础变量数量大于0
运输的能力曾经在世界上的变量的数量
]
;; The setup is divided into three subroutines
to setup
clear-all
setup-constants
setup-turtles
update-plot
update-global-variables
end
设置被分为三个子程序
plot count turtles with [not sick? and not immune?]
set-current-plot-pen "total"
plot count turtles
end
更新情节
设置当前绘图“人口”
设置当前绘图笔“感染病毒”
绘制变量数量带有[感染病毒?]
设置当前绘图笔“免疫”
[ ifelse ((random-float 100) < chance-recover) ;; either recover or die
[ become-immune ]
[ die ] ] ]
end
一旦变量已经感染足够长的时间,他要么恢复(并且变成免疫)或者他死亡
恢复
询问变量带有[病毒?]
[如果(感染病毒人数随机量)大于(生命长度*(持续的时间/100))
;; The probability of reproduction depends on average number
相关主题