在我的程序中有一只海龟,它的生物量是可变的(海龟自己的生物量)。在世界上有可能有许多不同生物量的海龟。我需要做的是:当一只海龟在同一块中发现另一只海龟时,它们必须将它们的生物量(将所有海龟的生物量相加)转移到生物量较高的海龟上,然后将它们(除了生物量较高的那只海龟之外的所有海龟)的生物量变为零。(有一个命令已经杀死了零生物量的海龟)谢谢你的关注!
嘿!我试着按照你说的做我自己的代码。但是代码只在程序的开始部分起作用。当程序运行时,某些情况下会使程序出错。我不知道这个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发布于 2016-10-20 16:08:29
这里有一个可能的解决方案,它遵循与您的不同的逻辑。它不会主动地将生物量从一只海龟转移到另一只海龟身上,而是一次在同一块土地上处理所有海龟。然而,从你的问题看,如果一块斑块上有超过一只海龟的生物量最大,那么会发生什么情况并不清楚。在这里,我发布了两个解决方案。在第一次尝试中,将随机选择这些最大生物量海龟中的一只,该补丁上的所有其他海龟都将其生物量设置为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
     ]
    ]
  ]
]https://stackoverflow.com/questions/40009931
复制相似问题