将海龟分成小组:修改后的合作伙伴示例?

时间:2015-08-18 14:14:06

标签: netlogo

我一直在尝试在NetLogo中编写一个模型,其中我从一定数量的龟开始,随机起始坐标。当我击中时,我希望海龟进入一​​定大小的群体然后继续移动。我知道有一个用于分组的示例模型('分组海龟示例'),但它告诉海龟去某个补丁而不是组合在一起,所以如果它们移动它们就不再分组了。

我一直在修改模型库中的'合作伙伴示例'模型。在这里,海龟被告知找到另一只没有伙伴的海龟,将该海龟设置为其伙伴,然后告诉新的伙伴将其设置为伙伴。这很好,我可以告诉合作伙伴蜂拥而至,在他们继续前进的过程中将他们团结在一起。但我无法弄清楚我是如何得到这样的东西来处理超过一对海龟的。

我以为我可以制作一个“合作伙伴”的代理商,其中包括一只乌龟所拥有的所有伙伴。我还想过在海龟之间使用无向链接并使用'网络'代理集来包括连接到单个海龟的所有海龟。

我无法让这些想法发挥作用。使用链接时,我可以设置乌龟可以拥有的首选链接数,但不能设置整个组中的乌龟总数(包括链接邻居的链接邻居),并且组中的乌龟不共享相同的连接。当我尝试制作合作伙伴的代理集时,它似乎永远不会起作用,因为每个后续的合作伙伴都会超越前一个合作伙伴。我还需要确保一只乌龟与其他群体共享同一个伙伴。我一直在尝试使用'turtle-set'为以前的合作伙伴添加新的合作伙伴,但我遇到了问题。以下是我用于设置合作伙伴的代码:

turtles-own
[next-partner ;a partner to be added to partners   
  group-size  ;includes turtle itself and number of partners in group (count)
  partners]   ;agentset of partners

to setup
  clear-all
  create-turtles num-turtles 
  [ setxy random-xcor random-ycor
    set next-partner nobody ;turtles haven't got any partners to start with
    set group-size 1 ;just itself
   ]
    reset-ticks
end

to go
  let singles turtles with [preferred-size > group-size] ;those turtles where the group it's in isn't big enough

  ask singles
  [ifelse any? other singles
  [set heading towards min-one-of (other turtles with [preferred-size > group-size]) [distance myself]] ;go towards other turtles who need more members in group
  [lt random 40
    rt random 40]
    fd 1
  ]

  ask turtles
   [set partners turtles with [next-partner = myself] ;partners are those turtles who have you in their partners, but I don't this will work because they won't always be a 'next-partner'
    set group-size 1 + count partners  
    if (preferred-size > group-size) and (any? other turtles in-radius 1 with [preferred-size > group-size])

    [set next-partner one-of other turtles in-radius 1 with [preferred-size > group-size]

     ask next-partner 
      [set next-partner myself  ;ask this new partner to set turtle as its partner too
       set partners (turtle-set partners next-partner)]  ;add the turtle as a partner to the partners agentset
       set partners (turtle-set partners next-partner) ;turtle does this after partner so that the partner doesn't add itself
      ]
    ask turtles with [preferred-size = group-size] ;turtles in the right group size just move around (I can get them to flock later)
  [lt random 40
    rt random 40
    fd 1]
  ] 
   tick
end

我希望这不会太久而且不清楚。我真的很感激任何帮助,我已经做了好几天了,在以前的问题中找不到这样的东西。

谢谢!

达明

0 个答案:

没有答案