如何列出相邻簇的颜色?
How to list the pcolors of neighboring clusters?
我有不同的补丁簇,每个补丁的颜色都不同,并且有一只乌龟充当政府。
我需要让政府知道邻近集群的颜色是什么。
我试图用邻居的颜色 ID 制作一个列表,但到目前为止我只能制作一个包含所有补丁邻居列表的列表
我使用的相关代码是:
governments-own[
list-neighbors
govcolorid
]
to setup
ask governments [
...
set govcolorid pcolor
...]
end
to find-neighbors
foreach sort governments [
ask ? [
let my-patch patches with [ pcolor = [ govcolorid ] of myself ]
set list-neighbors (list [[pcolor] of neighbors] of my-patch)
]]
此代码打印如下所示的列表邻居:
[[[18 92 85 18 92 85 18 18] [85 11 85 85 85 18 85 85] [85 85 85 85 85 18 85 85]]]
但我需要的只是邻近的簇 pcolor 减去 govcolorid(在本例中为 85):
[18 92 11]
我尝试使用map、sentence和remove-duplicates,但到目前为止我无法得出任何结果。如果您想到有用的提示或示例,请分享它们。
编辑:
根据您的意见,我用以下冷调解决了这个问题:
to find-neighbors-patch
foreach sort governments [
ask ? [
let _c [idgov] of ?
let _frnds patches with [pcolor = _c]
let _nmes (patch-set [neighbors] of _frnds) with [pcolor != _c]
set list-neighbors-clusters remove-duplicates [pcolor] of _nmes
]]
end
谢谢
要将您的输出变成您想要的输出,请尝试以下代码:
本质上,将列表列表缩减为单个列表,删除重复项,然后删除您想要的值。
set list-neighbors filter [ ? != 85] remove-duplicates reduce [sentence ?1 ?2] (first list-neighbors)
使用报告程序:
to-report find-nbr-colors [#gvt]
let _c [color] of #gvt
let _frnds patches with [pcolor = _c]
let _nmes (patch-set [neighbors] of _frnds) with [pcolor != _c]
report remove-duplicates [pcolor] of _nmes
end
我有不同的补丁簇,每个补丁的颜色都不同,并且有一只乌龟充当政府。 我需要让政府知道邻近集群的颜色是什么。
我试图用邻居的颜色 ID 制作一个列表,但到目前为止我只能制作一个包含所有补丁邻居列表的列表
我使用的相关代码是:
governments-own[
list-neighbors
govcolorid
]
to setup
ask governments [
...
set govcolorid pcolor
...]
end
to find-neighbors
foreach sort governments [
ask ? [
let my-patch patches with [ pcolor = [ govcolorid ] of myself ]
set list-neighbors (list [[pcolor] of neighbors] of my-patch)
]]
此代码打印如下所示的列表邻居:
[[[18 92 85 18 92 85 18 18] [85 11 85 85 85 18 85 85] [85 85 85 85 85 18 85 85]]]
但我需要的只是邻近的簇 pcolor 减去 govcolorid(在本例中为 85):
[18 92 11]
我尝试使用map、sentence和remove-duplicates,但到目前为止我无法得出任何结果。如果您想到有用的提示或示例,请分享它们。
编辑:
根据您的意见,我用以下冷调解决了这个问题:
to find-neighbors-patch
foreach sort governments [
ask ? [
let _c [idgov] of ?
let _frnds patches with [pcolor = _c]
let _nmes (patch-set [neighbors] of _frnds) with [pcolor != _c]
set list-neighbors-clusters remove-duplicates [pcolor] of _nmes
]]
end
谢谢
要将您的输出变成您想要的输出,请尝试以下代码: 本质上,将列表列表缩减为单个列表,删除重复项,然后删除您想要的值。
set list-neighbors filter [ ? != 85] remove-duplicates reduce [sentence ?1 ?2] (first list-neighbors)
使用报告程序:
to-report find-nbr-colors [#gvt]
let _c [color] of #gvt
let _frnds patches with [pcolor = _c]
let _nmes (patch-set [neighbors] of _frnds) with [pcolor != _c]
report remove-duplicates [pcolor] of _nmes
end