代理人彼此分享他们的名单

问题描述 投票:0回答:1

我正在制作一个NetLogo模型。每个代理都有一个包含5个整数的列表(agent-list)。在每个滴答声中,海龟与另一只乌龟建立链接,并彼此分享他们的列表。

turtles-own [ agent-list ]
.
.
.    
ask turtles [
    create-link-with one-of other turtles
    set agent-list lput agent-list of link-neighbors agent-list
  ]

我知道上面的代码不起作用,我该如何解决?

simulation netlogo
1个回答
1
投票

如您所述,组合列表的最简单方法可能是sentence

turtles-own [ agent-list ]

to setup
  ca
  crt 3 [ 
    set agent-list map [random 10] range 5
  ]
  reset-ticks
end

to link-and-share
  ask turtles [
    let target one-of other turtles
    create-link-with target
    set agent-list sentence agent-list [agent-list] of target
    show agent-list
  ]
end

然而,根据你真正想做的事情,你会做一些调整,因为这意味着在程序后期连接的海龟可能会拉动已经修改过自己的agent-list的海龟的agent-list。因此,如果乌龟0抓住乌龟1的agent-list,那么后来乌龟4抓住乌龟0的agent-list,乌龟4将有15个整数的agent-list,而不是10,类似于下面的输出:

(turtle 1): [6 1 5 4 7 3 9 8 1 1]
(turtle 0): [9 0 3 3 5 3 9 8 1 1]
(turtle 2): [3 9 8 1 1 9 0 3 3 5 3 9 8 1 1]
© www.soinside.com 2019 - 2024. All rights reserved.