netlogo - Netlogo:补丁会立即消失而不是持续消失
问题描述
我试图展示森林砍伐与重新造林。为此,我创建了一个滑块来显示正在进行的重新造林和砍伐森林的数量。然而,每次 11 点,整个场景都会被砍伐,我不知道为什么。
patches-own
[reforestar
deforestar]
breed [ potreros potrero ] ; sheep is its own plural, so we use "a-sheep" as the singular
breed [ bordes borde ]
breed [ bosques bosque ]
to setup
clear-all
set-default-shape turtles "frog top"
ask patches
[ifelse pcolor = 44
[ set reforestar tiempo-sin-reforestar ]
[ set reforestar tiempo-sin-reforestar * 0.5];
]
reset-ticks
end
to go
ask patches [ reforestacion ]
ask patches [ deforestacion ]
tick
end
to reforestacion ; patch procedure
; countdown on brown patches: if you reach 0, grow some grass
if pcolor = 35 [
ifelse reforestar <= 0
[ set pcolor 44
set reforestar tiempo-sin-reforestar ]
[ set reforestar reforestar - 1 ]
]
end
to deforestacion
if pcolor = 44 [
ifelse deforestar >= 10
[ set pcolor 35
set deforestar tasa-deforestacion ]
[ set deforestar deforestar + 1 ]
]
end
这个想法是一些随机的棕色(deforestacion)变成黄色(reforestacion),但由于某种原因它只是一次改变了一切。
解决方案
您不是要求随机数量的补丁做某事,而是要求所有 pcolor 44 的补丁在每个滴答声中最多计数 10,当它们达到 10 时,它们会被“砍伐”。
如果您想询问随机数量的补丁来砍伐森林,请尝试类似
ask n-of (random ([count patches with pcolor = 44] * deforestationRate)) patches with pcolor = 44 [set pcolor 35 set deforestar tasa-deforestacion]
deforestationRate 将是从 0 到 1 的滑块中的一个值。这将做的是计算可以被砍伐的斑块的数量,然后选择这些斑块中的随机数量来砍伐森林。如果您只使用计数本身,那么 0 到 100% 的森林之间的每个刻度都会被砍伐,但如果您添加 deforestationRate 滑块值,它可能是您想要的任何最大百分比。(因此,例如,如果您将其设置为 0.1,那么每个刻度只有多达 10% 的森林可以被砍伐)您也可以对重新造林做同样的事情,并为速率使用不同的滑块/值。
(注意:我有一段时间没有使用 NetLogo,所以代码和括号可能不是 100% 正确,但你明白了)
推荐阅读
- python - 如何更改cefpython窗口图标?
- python - 如何创建一个程序,该程序需要用户输入美国时间并使用 python 将其转换为 BG 时间?
- docker - Docker-compose 服务器无法访问
- amazon-web-services - 使用 GPU 在 EC2 实例上训练 Keras 模型很慢
- firebase - Firebase 身份验证 Unity3d。提供的身份验证凭据格式错误或已过期
- javascript - 在 chrome 上查看时 Javascript 源文件不可读
- neural-network - PyTorch 小批量,何时调用 optimizer.zero_grad()
- django - devtools:在新选项卡中打开响应 HTML
- excel - 从 MS Access 打开时,VBA Excel 实例不会关闭 - 后期绑定
- python - 我的 if 语句有问题;没有输出或错误