【问题标题】:Netlogo: Patches Disappear instantly instead of continualyNetlogo:补丁会立即消失而不是持续消失
【发布时间】:2021-10-03 06:39:23
【问题描述】:

我试图展示森林砍伐与重新造林。为此,我创建了一个滑块来显示正在进行的重新造林和砍伐森林的数量。然而,每次 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),但由于某种原因它只是一次改变了一切。

【问题讨论】:

标签: netlogo patch


【解决方案1】:

您并不是要求随机数量的补丁做某事,而是要求所有 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% 正确,但你明白了)

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 2020-12-07
    • 1970-01-01
    • 2011-06-26
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 2020-02-06
    相关资源
    最近更新 更多