Netlogo - 识别代理集的子集

时间:2017-03-17 20:28:50

标签: netlogo

我花了整个下午试着用我的部分代码来解决问题而且我似乎没有得到任何结果。基本上,我正在尝试在模型设置上创建社交网络。模型中的每个人都从一组靠近他们的人people-nearby开始。人们从这一组中选择与谁联系:

create-people population-size
[
  set people-nearby turtle-set other people in-radius neighborhood-radius
]

to create-network
  let num-links round (average-node-degree * population-size) / 2  

  while [ count links < num-links and count people with [length sort people-nearby > 0] > 0 ]

  [ ask one-of people
    [ *... initiate probabilistic link creation process...*
     create-unlink-with chosen-friend

一旦A人与某人(即B人)相连,就会从A人people-nearby集中删除B人。通过排除作为people-nearby集合成员的所有附近人员(即,人员A已经连接的人员 - 这个,更新了unlink-neighbors集合的代码的这一部分,我遇到了问题设置包括人B):

        ifelse count turtle-set people-nearby > 1  
        [ let nearby-people-not-linked-to-me  ( turtle-set people-nearby with [ not member? self [ turtle-set unlink-neighbors ] of myself ] ) 
          set people-nearby nearby-people-not-linked-to-me ]
        [ set people-nearby [ ] ]  

出于某种原因,此错误不断弹出:     “预期输入为代理人但是得到了列表[(人0)(人1)(人3)(人4)]。”每当
时 调用people-nearby with [ not member? self [ turtle-set unlink-neighbors ] of myself

我查了很多帖子,但似乎无法获得正确的参数形式,以便它停止显示此错误。

任何人都可以帮我解决这个问题吗? (哦,这是我的第一篇文章,如果我没有正确设置问题,请道歉)

1 个答案:

答案 0 :(得分:1)

当您提交代码时,请尝试提交重新创建问题所需的内容 - 请查看asking help page,特别是有关帮助其他人重现问题的部分。按原样,我认为您的问题来自于使用turtle-set。该原语主要用于组合代理集,而不是查询它们。所以在你的行中:

( turtle-set people-nearby with [ not member? self [ turtle-set unlink-neighbors ] of myself ] )

存在与turtle-set相关的语法问题。错误本身就是说您没有返回代理集,而是返回代理列表,其行为方式不同。

如果我理解正确,你希望所有人都拥有一个包含半径范围内所有人的变量:&#34;附近的人&#34;。然后,你希望人们与他们的一个邻居&#34;海龟。最后,您希望人们更新他们附近的人员#34;变量以排除他们刚刚形成链接的人。下面是一些带有注释的代码,我尝试按照这些步骤进行操作 - 显然你的变量会有所不同,但它可能会让你开始。如果我需要澄清任何内容或者我错过了一步,请告诉我。

breed [ people person ]
turtles-own [ people-nearby ]


to setup 
  ca
  reset-ticks
  create-people 70  [
    setxy (random 30 - 15) (random 30 - 15)
  ]

  ; do this after all turtles have spawned
  ask people [
    set people-nearby other people in-radius 3
  ]

end


to create-links

  let num-links 10

  ;; Create a temporary agentset out of turtles that have people nearby
  let turtles-with-neighbors turtles with [ any? people-nearby ]

  ; ask some number of the temporary agentset:
  ask n-of num-links turtles-with-neighbors [

    ;; This just makes it easy to identify the turtle that causes the link
    ask patches in-radius 3 [
      set pcolor white
    ]

    ; create a link to one of the nearby people
    create-link-to one-of people-nearby
    ; newly set people-nearby to only include turtles in radius
    ; that are not linked-to from the currently acting turtle
    set people-nearby other people in-radius 3 with [ not member? self [ out-link-neighbors ] of myself  ]
    ask people-nearby [ set size 0.5 ]
  ]

end