的NetLogo。如何将一只乌龟的变量(乌龟自己)加到另一只乌龟

时间:2016-10-12 23:25:50

标签: netlogo

在我的计划中,有一只具有可变生物量(龟自身生物量)的海龟。在这个词中可能有很多不同生物量的海龟。我需要什么: 当一只乌龟在同一个斑块中发现另一只乌龟时,他们必须将生物量(将所有乌龟的生物量总和)转移到生物量较高的乌龟,然后将它们(除了生物量较高的乌龟之外的所有海龟生物量)转为零。 (有一个命令可以杀死没有生物量的乌龟) 谢谢你的关注!

喂!正如你说我要做的那样,我试着做自己的代码。 但代码只适用于程序的开头。由于该程序将运行一些案例错误的程序。我不知道这个bug来自哪里......变量开始自我总结......这是代码的一部分: 生物量是来自龟的变量>龟自己[生物量]

while [any? Other turtles-here]
[
    Let maximum max[biomass] of turtles-here
    Let auxi  sum[biomass]of turtles-here
    Let higher turtles-here with-max[biomass]
    Let otherhigher count other turtles-here with-max [ biomass]
    If (otherhigher>0)
    [set higher turtles-here with-max[headling] ; (I PUT THIS IN CASE THE TURTLE HAS THE SAME BIOMASS]
     Ask higher [ set biomas (aux) ]
     Let lower turtles-here with [biomass< maximum]  ; (LOWER CAN BE MORE THAN ONE)
     Ask lower [set biomass (0)]
     Ask turtles-here with [biomass<=0] [die]
    ]
    end

1 个答案:

答案 0 :(得分:1)

这是一种可能的解决方案,它遵循不同于您的逻辑。它没有积极地将生物质从一只乌龟转移到另一只乌龟,而是同时处理同一补丁上的所有海龟。然而,从你的问题来看,如果补丁上有多个具有最大生物量的乌龟,则不清楚应该发生什么。在这里我发布两个解决方案在第一次尝试中,将随机选择这些最大生物量龟中的一只,并且该斑块上的所有其他龟将其生物量设定为0.在第二次尝试中,具有最大生物量的所有龟将共享生物量较低的生物量龟的生物量。补丁。

变式1:在具有多个海龟的补丁上只有一名幸存者

ask turtles
[
 ;...
 ;some movement
 ;...

 if (any? other turtles-here)
 [
   ;; Only one turtle with max biomass would be chosen randomly, even if there is more than one
   ask max-one-of turtles-here [biomass]
   [
     set biomass (biomass + sum [biomass] of other turtles-here)

     ask other turtles-here
     [
       set biomass 0
     ]
    ]
  ]
]

变体2:所有具有最大生物量的海龟都能存活并分享资源

ask turtles
[
 ;...
 ;some movement
 ;...

 if (any? other turtles-here)
 [
   ;We create two temporary agentsets, one with the surviving turtles and one with the consumed turtles
   let max-biomass-turtles turtles-here with-max [biomass]
   let low-biomass-turtles turtles-here with [not member? self max-biomass-turtles]

   ;Only if there are turtles to consume, calculate the share each max biomass turtle gets
   if (any? low-biomass-turtles)
   [
     let biomass-share (sum [biomass] of low-biomass-turtles / count max-biomass-turtles)

     ask max-biomass-turtles
     [
       set biomass (biomass + biomass-share)
     ]
     ask low-biomass-turtles
     [
       set biomass 0
     ]
    ]
  ]
]