Netlogo 首先根据属性创建指向n个海龟的链接,然后随机创建

Netlogo 首先根据属性创建指向n个海龟的链接,然后随机创建,netlogo,agent-based-modeling,Netlogo,Agent Based Modeling,我有一个海龟群体,我希望他们根据我给他们的“偏差”(从1到5的值)创建一个随机数目的到其他海龟的链接。现在,如果没有足够多的海龟具有相同的“偏见”,那么我希望他们首先创建与具有相同偏见的海龟的链接,然后创建与随机其他海龟的链接 到目前为止,我已经明白了很多 ask people [ set my_friends 1 + random (average-node-degree * 2) create-links-to n-of my_friends other p

我有一个海龟群体,我希望他们根据我给他们的“偏差”(从1到5的值)创建一个随机数目的到其他海龟的链接。现在,如果没有足够多的海龟具有相同的“偏见”,那么我希望他们首先创建与具有相同偏见的海龟的链接,然后创建与随机其他海龟的链接

到目前为止,我已经明白了很多

    ask people [ 
      set my_friends 1 + random (average-node-degree * 2)
      create-links-to n-of my_friends other people with [bias = [bias] of myself]
     ]

但后来我遇到了一个问题,可能没有足够多的海龟像我希望他们那样创建链接。如何让海龟们创建到随机海龟的链接,以及“剩余”数量的我的朋友?

编辑:在评论中加入JenB的建议,答案得到了改进

我愿意

ask people [ 
  set my_friends 1 + random (average-node-degree * 2)
  let target other people with [bias = [bias] of myself] ; This is just for readability.

  ifelse (my_friends <= count target)
    [create-links-to n-of my_friends target]
    [create-links-to target
     let surplus (my_friends - count target)
     let backup-target people with [bias != [bias] of myself]
     create-links-to up-to-n-of surplus backup-target]
]
询问人们[
将我的朋友设置为1+随机(平均节点度*2)
让我们以[bias=[bias]of my己为目标;这只是为了可读性。

ifelse(我的朋友们,这很好,但是你不需要第二个
ifelse
,因为你可以使用
up-to-n-of
,而不是第二个
n-of
allocation@JenB的确!我编辑了我的答案,包括这个,谢谢。