如何在netlogo中同时产生海龟

时间:2015-12-03 15:08:10

标签: netlogo spawning

有没有办法在模拟过程中产生海龟,即使它们已经死亡。在我的模拟中,鱼正在吃浮游生物,所以如果它们遇到浮游生物,浮游生物会死亡/被吃掉。然而,当一条鱼不能再吃浮游生物时,它会死亡,因为它不再通过吃它从浮游生物中获取能量。因此,当所有的鱼都死了,浮游生物应该回来;由于迁移等原因而不断增长。我不确定如何实现这个?创建功能在此处不起作用,仅在设置中。

to plankton-reproduce
  if random-float 100 < reproduce-plankton [
    set energy (energy / 2)
    hatch 1 [setxy random-xcor random-ycor]
  ]
  if count plankton < 10 [
    create-plankton 20
    setxy random-xcor random-ycor
  ]

错误:你不能在乌龟环境中使用create-plankton,因为create-plankton只是观察者

2 个答案:

答案 0 :(得分:2)

我想我可能会理解这个问题。

要有一只乌龟创造海龟使用HATCH。如果您使用

,您的代码将起作用(如果我理解的话)
hatch-plankton 20

而不是

 create-plankton 20

我做对了吗?海龟hatch,补丁spawn和观察者create。 孵出的海龟与孵化海龟相同,并且都会被称为hatch。假设你不想那样。 使用

hatch-plankton 20 [setxy random-xcor random-ycor]

答案 1 :(得分:0)

我已将其纳入代码中,但当浮游生物的数量为零时,将不再有浮游生物重生,这是因为所有浮游生物都已死亡且无法孵化。你是否知道在模拟过程中一般会产生浮游生物或重生龟的另一种方法,即使它们死亡了? 在重现浮游生物的代码下面:

to plankton-reproduce
  while [count plankton != 0 and count plankton < 3000]
    [ if random-float 100 < reproduce-plankton
      [set energy (energy / 2)
       hatch-plankton 1 [setxy random-xcor random-ycor]]]
  if count plankton = 0
  [set energy 1
  hatch-plankton 20 [setxy random-xcor random-ycor]]
end