Netlogo - 识别代理集的一个子集

Netlogo - identifying a subset of an agentset

我整个下午都在尝试处理我的部分代码,但我似乎一无所获。基本上,我正在尝试在模型设置上创建一个社交网络。模型中的每个人都从他们附近的一组人开始 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)建立联系,人 B 就会从人 A 的 people-nearby 集合中移除。我在代码的这一部分遇到问题,其中 people-nearby 集通过排除属于 unlink-neighbors 集成员的所有附近的人(即 A 已经连接的人 - 这集合包括人 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 [ ] ]  

由于某种原因,此错误不断弹出: "WITH expected input to be an agentset but got the list [(person 0) (person 1) (person 3) (person 4)] instead." 每当
people-nearby with [ not member? self [ turtle-set unlink-neighbors ] of myself 被调用。

我查了很多 post,但似乎无法正确理解参数的形式,因此它不再显示此错误。

谁能帮我解决这个问题? (哦,这是我的第一个 post 如果我没有正确设置问题,我深表歉意)

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

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

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

如果我没理解错的话,你希望所有人都有一个变量,其中包含他们半径范围内的所有人:"people-nearby"。然后,您希望人们与他们的一只 "neighbor" 海龟组成 link。最后,您希望人们更新他们的 "people-nearby" 变量以排除他们刚刚形成 link 的那个人。下面是一些带有注释的代码,我在其中尝试按照这些步骤进行操作 - 显然您的变量会有所不同,但它可能会让您入门。让我知道是否需要澄清任何内容或是否遗漏了一步。

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