如何创建邻居网络?
How to create a network of neighbors?
嗨,我是 netlogo 的新手,没有编程背景,
我正在尝试使用 GIS 扩展创建 "neighbours" 的网络,
到目前为止,我正在使用 in-radius
函数,但我不确定它是否合适。
因为我不明白 Netlogo
中 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
行中的某些内容必须更改,但到目前为止我的所有尝试都没有用。
提前致谢
莎拉:
1) This helped me understand the usage of 'in-radius' in NetLogo (or the unit of radius): When you use 'in-radius 1' in a patch-context, 5 patches will be selected (补丁提问的海龟所在的位置和四个邻居,不是所有 8 个相邻的补丁)。
2) 考虑使用 'min-one-of target [ distance myself ]' 而不是 'one-of target'。
分钟之一: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
我不清楚 GIS 与这个问题的关系,而且您还没有提供创建代理的代码,所以我无法给出完整的答案。 NetLogo 有一个自动内置的坐标系。每个代理在该坐标系上都有一个位置,每个补丁占据 space 1 单位 x 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
嗨,我是 netlogo 的新手,没有编程背景,
我正在尝试使用 GIS 扩展创建 "neighbours" 的网络,
到目前为止,我正在使用 in-radius
函数,但我不确定它是否合适。
因为我不明白 Netlogo
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
行中的某些内容必须更改,但到目前为止我的所有尝试都没有用。
提前致谢
莎拉:
1) This helped me understand the usage of 'in-radius' in NetLogo (or the unit of radius): When you use 'in-radius 1' in a patch-context, 5 patches will be selected (补丁提问的海龟所在的位置和四个邻居,不是所有 8 个相邻的补丁)。
2) 考虑使用 'min-one-of target [ distance myself ]' 而不是 'one-of target'。
分钟之一: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
我不清楚 GIS 与这个问题的关系,而且您还没有提供创建代理的代码,所以我无法给出完整的答案。 NetLogo 有一个自动内置的坐标系。每个代理在该坐标系上都有一个位置,每个补丁占据 space 1 单位 x 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