嗨,我是新手,没有编程背景,我试图创建一个“邻居”网络,使用地理信息系统扩展,到目前为止,我使用的是in-radius功能,但我不确定它是否是合适的。因为我不明白radius在网络标识中的单位
下面是代码:
to setup
clear-drawing
clear-all
reset-ticks
; zoom to study area
resize-world 00 45 0 20
set-patch-size 20
; upload city boundries
set mosul-data gis:load-dataset"data/MosulBoundries.shp"
gis:set-world-envelope gis:envelope-of mosul-data
gis:apply-coverage mosul-data "Q_NAME_E" neighbor
to Neighbour-network
;; set 7 neighbour agents inside the city
ask turtles [
let target other turtles in-radius 1
if any? target
[ask one-of target [create-link-with myself]]
]
print count links我希望每个邻居neighbor,每个代理是链接到7个近邻。我的猜测是,在if any? target行中,有些东西必须改变,但到目前为止,我的所有尝试都是徒劳的。
提前感谢
发布于 2020-05-08 10:57:44
我不清楚GIS与这个问题有什么关系,而且您还没有提供创建代理的代码,所以我无法给出完整的答案。NetLogo有一个自动内置的坐标系。每个代理在该坐标系上都有一个位置,每个补丁占用1单位平方(以整数坐标为中心)的空间。in-radius和distance原语位于距离单元中。
但是,如果你只想连接到最近的7只海龟,你就不需要这些了,因为NetLogo可以通过找到那些离问海龟有最小距离的海龟来直接找到那些海龟。它使用min-n-of来找到具有相关最小值的给定数目的海龟,并使用distance [myself]将海龟的数量降到最低。整个过程,包括用生成的turtleset创建链接,可以在一行代码中完成。
下面是一个完整的模型,向您展示它的外观:
to testme
clear-all
create-turtles 100 [setxy random-xcor random-ycor]
ask n-of 5 turtles
[ create-links-with min-n-of 7 other turtles [distance myself]
]
end发布于 2020-05-07 17:19:41
莎拉:
1)这帮助我理解了在NetLogo (或radius的单位)中' in -radius‘的用法:当您在补丁上下文中使用' in -radius 1’时,将选择5个补丁(问海龟所在的补丁和四个邻居,而不是所有8个相邻的补丁)。

2)考虑使用“我自己的最小目标距离”而不是“一个目标”。
最低一倍:http://ccl.northwestern.edu/netlogo/docs/dict/min-one-of.html
距离我自己:http://ccl.northwestern.edu/netlogo/docs/dict/distance.html
to Neighbour-network
; set 7 neighbour agents inside the city
ask turtles [
let target other turtles in-radius 1
let counter 0
while [ count target > 0 and counter < 8 ]
[ ask min-one-of target [ distance myself ] [
create-link-with myself
set counter counter + 1
]
]
show my-links
]3)考虑探索Nw扩展:https://ccl.northwestern.edu/netlogo/docs/nw.html
https://stackoverflow.com/questions/61636332
复制相似问题