建立从代理到代理集的无向链接

Making undirected links from an agent to an agentset

我正在尝试从具有特定 属性 的代理(在我的例子中是塔)到具有另一组属性的其他塔创建 link。只有他们中的一些应该 linked,但是当我问观察者时,它说他们似乎都有那个 link。

 to setup-links
  print count towers with [ any? tower-communications ]
  ask towers with [ heading = 0 ] [                        ; first consider the communications between different areas
    create-tower-communications-with other towers with [ heading = 0 ]          ; between two towers that are still standing
    in-radius tower-communication-radius                   ; and link towers to each other if they are close enough
    with [ heading = 0 ]                                   
    [set color green]
end
  print count( tower-communications with [ color = green ])
  print count( towers with [ any? tower-communications ])

第一个打印语句按预期给出了这些对之间 link 的数量。第二个应该打印出它们之间有 link 的塔的数量,但它给了我系统中塔的全部数量。出了什么问题?我只想要一组与至少一个其他代理进行塔式通信的代理。

我认为问题在于您计算带链接的海龟的方式,而不是您创建链接的方式。这是一个完整的例子(注意我去掉了第二个 with [heading = 0].

globals [tower-communication-radius]

to setup
  clear-all
  create-turtles 25
  [ setxy random-xcor random-ycor
    set heading 0
  ]
  set tower-communication-radius 5
  setup-links
end  

to setup-links
  print count turtles with [ any? links ]
  ask turtles with [ heading = 0 ]
  [ create-links-with other turtles with [ heading = 0 ]
    in-radius tower-communication-radius
    [set color green]
  ]

  print count turtles
  print count turtles with [ any? links ]
  print count turtles with [ any? my-links ]
end

您的计数是 print count turtles with [ any? links ]。但是,您要测试的是模型中是否有任何链接,而不是乌龟(或塔)是否有任何链接。您需要 my-linkslink-neighbors 才能应用于特定的乌龟。