建立从代理到代理集的非定向链接

时间:2018-10-11 14:51:26

标签: netlogo

我正在尝试创建从具有特定属性的座席(在我的情况下为塔)到具有另一组属性的其他塔的链接。他们中只有一部分应该被链接,但是当我问观察者时,它说他们似乎都有链接。

 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 ])

第一个打印语句按预期给出了这些对之间的链接数。第二个应该打印出它们之间有链接的塔的数量,但是它给了我系统中完整的塔的数量。怎么了?我只想要与至少一个其他代理具有塔式通信的一组代理。

1 个答案:

答案 0 :(得分:1)

我认为问题在于您使用链接计算海龟的方式,而不是创建链接的方式。这是一个完整的示例(请注意,我取出了第二个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才能应用于特定的乌龟。