首页 > 解决方案 > 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),但由于某种原因它只是一次改变了一切。

标签: netlogopatch

解决方案


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


推荐阅读