NetLogo 中有没有办法给海龟(不同世代)不同的年龄?

Is there a way in NetLogo to give turtles (of different generations) different ages?

我想模拟森林中不同树种的相互作用。为此,我还必须模拟森林的 growth/spread。 我面临以下两个问题:

  1. 我希望树木达到最低年龄,从这个年龄开始它们每年可以孵化出一棵新树。但我只知道如何让它们每(例如)20 年繁殖一次。
  2. 城镇砍树也有规定的年龄。问题是,当达到这个年龄时,一个品种的所有树木都会被砍伐,即使它们的年龄实际上应该小于它们的收获年龄。

以下是我的代码的相关部分:

to go
 ask oaks [set age ticks]
end

to set-harvest-age 
 ask oaks [set harvest-age 240]
end

to spread 
ask oaks [
if (age mod 30 = 0) and (count oaks > 1) [hatch-oaks 1 [setxy random-xcor random-ycor set age 1]]]
end

to chop-down 
 ask oaks [if (age >= harvest-age) [die]]
end

"spread"中的"set age 1"好像不行。也许你们中有人有想法。 谢谢!

我认为你的主要问题是这里的流程顺序。每次调用 go 时,所有橡树都会将它们的年龄设置为当前的 ticks。这包括您孵化的任何新树苗,因此即使它们在孵化时的年龄为 1,这些树苗也会立即设置为与所有其他橡树相同的年龄(这只是刻度数。相反,您应该使用您的oaks-own(或您想要的任何物种)变量通过在每个滴答声中递增而不是将其设置为滴答声来跟踪每只海龟的年龄。

此外,最好使用 go 或类似命名的过程作为调用所有其他相关过程的调度程序。例如,查看这些设置块:

breed [ oaks oak ]
oaks-own [ age harvest-age ]

to setup
  ca
  spawn-oaks
  reset-ticks
end

to spawn-oaks ; setup procedure
  create-oaks 10 [
    set shape "tree"
    set color green
    setxy random-xcor random-ycor
    ; Set the harvest age
    set harvest-age 100
    ; Randomly choose the age of the first generation
    ; to be somewhere between 50 and 75
    set age 50 + random 25
  ]
end

这会创建 10 棵年龄随机介于 50 到 75 之间的橡树。它还设置了它们的收获年龄。现在,使用一个程序将每棵橡树的个体年龄每刻增加一岁:

to get-older ; Oak procedure
    set age age + 1
end

然后,让他们在成熟时开始培育树苗。我已经包含了一个 if any? other oaks-here 限定符,这样人口规模不会立即爆炸(因为树苗只能在没有成熟橡树的补丁上生存),但你会以任何对你的模型有意义的方式限制增长.

to spread ; Oak procedure
  ; Get living, mature oaks to spead saplings nearby
  ; only some years (to avoid population explosion)
  if age > 30 and random 50 < 5 [
    hatch 1 [
      ; set sapling age to zero, and have it
      ; move away from its parent randomly
      set age 0
      rt random 360
      fd random 5
      if any? other oaks-here [
        die
      ]
    ]
  ]
end

最后,既然 age 问题已经解决,您的 chop-down 程序应该可以正常工作了:

to chop-down ; Oak procedure
  if age >= harvest-age [
    die
  ]
end

现在所需要做的就是使用 go 以正确的顺序调用这些过程:

to go
  ; Use the go procedure to schedule subprocedures
  ask oaks [
    get-older
    spread
    chop-down
  ]
  tick
end

有点愚蠢的例子,但希望能为您指明正确的方向!