Netlogo:如何将属于邻居的列表传输到矩阵?
Netlogo: How to transfer lists belonging to neighbours to a matrix?
名为ownList2 的列表包含两个参数。 Flockmates 是邻居给定半径内的所有邻居。我在 6.0 版中尝试了这段代码。但它不起作用。
基本上,我想将一个等维列表放入一个矩阵中。我做错了什么吗?或者有人可以改进代码片段?
ask turtles[set ownList2 (list who sensed)]
;sensed is sensor value of a turtle with respect to the patch.
;ownList2 is like a message of two bytes,
;first byte mentioning the identity of the itself
;second byte mentioning the value of the sensor.
ask turtles[
foreach (list flockmates)
[
i -> set m45 matrix:to-column-list ( list [ownList2] of i )
]
]
结果:
对于邻居为 1、2、3 的 turtle-0:
ownList2 ~ [1 200]
[2 400]
[3 900]
turtle-0 的 m43 应该看起来像
[[1 200][2 400][3 900]]
感谢您添加该信息。这是一个玩具示例,可以满足您的需要:
extensions [ matrix ]
turtles-own [ ownlist2 sensed m45 ]
to setup
ca
; Setup example turtles as per question
foreach [ 100 200 400 900 ] [
n ->
crt 1 [
while [ any? other turtles-here ] [
move-to one-of neighbors4
]
set sensed n
set ownlist2 ( list who sensed )
]
]
; Get the turtles to create matrices from the ownlists of
; sorted other turtles
ask turtles [
set m45 matrix:from-column-list map [ i -> [ ownlist2] of i ] sort other turtles
]
; Example output:
ask turtle 0 [
print "Turtle 0's m45:"
print matrix:pretty-print-text m45
]
reset-ticks
end
输出示例:
Turtle 0's m45:
[[ 1 2 3 ]
[ 200 400 900 ]]
名为ownList2 的列表包含两个参数。 Flockmates 是邻居给定半径内的所有邻居。我在 6.0 版中尝试了这段代码。但它不起作用。 基本上,我想将一个等维列表放入一个矩阵中。我做错了什么吗?或者有人可以改进代码片段?
ask turtles[set ownList2 (list who sensed)]
;sensed is sensor value of a turtle with respect to the patch.
;ownList2 is like a message of two bytes,
;first byte mentioning the identity of the itself
;second byte mentioning the value of the sensor.
ask turtles[
foreach (list flockmates)
[
i -> set m45 matrix:to-column-list ( list [ownList2] of i )
]
]
结果: 对于邻居为 1、2、3 的 turtle-0: ownList2 ~ [1 200] [2 400] [3 900] turtle-0 的 m43 应该看起来像 [[1 200][2 400][3 900]]
感谢您添加该信息。这是一个玩具示例,可以满足您的需要:
extensions [ matrix ]
turtles-own [ ownlist2 sensed m45 ]
to setup
ca
; Setup example turtles as per question
foreach [ 100 200 400 900 ] [
n ->
crt 1 [
while [ any? other turtles-here ] [
move-to one-of neighbors4
]
set sensed n
set ownlist2 ( list who sensed )
]
]
; Get the turtles to create matrices from the ownlists of
; sorted other turtles
ask turtles [
set m45 matrix:from-column-list map [ i -> [ ownlist2] of i ] sort other turtles
]
; Example output:
ask turtle 0 [
print "Turtle 0's m45:"
print matrix:pretty-print-text m45
]
reset-ticks
end
输出示例:
Turtle 0's m45:
[[ 1 2 3 ]
[ 200 400 900 ]]