我试图代表一个多尺度的环境,其中我有一些大的斑块代表景观中的高价值区域,而一些小的斑块则具有本地信息。例如。我想获得1km ^ 2规模的降雪数据,但我也想拥有较大的补丁(9km ^ 2)来汇总大规模信息。我的每个大补丁都具有与其相邻邻居不同的变量值,但是在其他补丁中,变量值可能会在整个格局中重复出现。我正在寻找让我的海龟最直接的方法来识别大型补丁之间的差异。我曾考虑过创建补丁集,但是我不确定如何解决在不同补丁中重复出现的变量值的问题。非常感谢您的帮助。
编辑:我创建了一个与大型栅格具有相同面片结构的栅格,并使用此栅格分配了“ patch-id's”,因此世界上不再存在变量重复。我仍然在努力让乌龟将这些较大的补丁识别为分组的实体。
答案 0 :(得分:1)
您评论了我的第一个答案
我的主要问题是我需要运行“找到最大一 neigboring-large-patches [large-scale-variable]“,所以我需要乌龟 了解相邻的大补丁是什么,并能够 如果可以的话,将它们作为单位阅读。我不知道怎么 将其纳入您的答案中,有什么想法吗?
这是操作方法。这段代码虽然草率,但是却说明了这一点。
让大区域具有在创建期间生成的x和y值。基本上,它们存储覆盖视口的大区域网格的列数和行数。
breed [ large-regions large-region ]
large-regions-own [
terrain
region-color
population
x
y
]
然后,从概念上讲,区域的邻居的x和y值将在该区域的x和y值的+/- 1之内,因此您可以通过这种方式识别它们。
为简化编码而牺牲空间,在生成区域时,我还在变量lrx和lry中将该区域的唯一标识符(谁)及其x和y值存储到该区域的每个补丁中。
patches-own [
large-region-who
lrx
lry
]
找到您所要求的人口最大值附近的大区域的核心如下。我编写此代码是为了加快调试速度,而不是为了提高优雅度,因此可以对其进行大量清理。完整的源代码包含许多打印语句,可以有效地注释解决请求的搜索的每个步骤。
它环顾四周(补丁0 0),从该补丁中找到大区域的x和y的信息,生成具有附近x和y值的大区域的代理集,并在可以提取人口最多的区域。它还将要求修补程序着色为黑色,将本地大区域着色为蓝色,将最大人口邻居着色为红色。
大多数情况下都起作用-大区域从应有的位置偏移了一个小块-但这说明了这一点。运行安装程序,然后亲自看看。
这是(丑陋的)代码。有趣的问题。您也可以轻松地将其扩展到较小的区域,并使两者同时工作。享受吧!
globals [
large-region-size
]
breed [ large-regions large-region ]
large-regions-own [
terrain
region-color
population
x
y
]
patches-own [
large-region-who
lrx
lry
]
to setup
clear-all
set large-region-size 5
no-display
make-large-regions
ask patches [ set pcolor white ]
display
ask large-regions [ set hidden? true]
print (word " hilly region count: " count large-regions with [terrain = "hilly"] )
;; print (word " deep snow count: " count small-regions with [snow-cover > 75])
reset-ticks
end
to go
ask patches [ set pcolor white]
; ;; lets examine the large-regions
; print " large region xvals "
; let xvals [ ]
; ask large-regions [ set xvals fput x xvals ]
; set xvals remove-duplicates xvals
; show xvals
; print " "
; print " patch lrx values: "
; set xvals [ ]
; ask patches [ set xvals fput lrx xvals ]
; set xvals remove-duplicates xvals
; show xvals
; print "========================================="
print " let's examine large-regions around the patch at 0 0 "
let x-spot 0
let y-spot 0
print ( word " looking for large-regions with max population bordering the following patch " x-spot " " y-spot)
; ask n-of 1 patches [ set x-spot pxcor set y-spot pycor print (word "selected patch " x-spot ", " y-spot )]
let home-who [ large-region-who] of patch x-spot y-spot
print (word "home-region-who is " home-who)
print " "
;; thinking ahead, we have coded the x and y values of the large region around us directly into the patch variables
let home-x [ lrx ] of patch x-spot y-spot
let home-y [ lry ] of patch x-spot y-spot
print (word "this blue home region has x=" home-x " and y=" home-y )
ask patches with [lrx = home-x and lry = home-y] [ set pcolor blue ]
ask patch x-spot y-spot [ set pcolor black ]
let home-neighbor-set large-regions with [
( x >= ( home-x - 1 )) and ( x <= ( home-x + 1) ) and (y >= ( home-y - 1 ) ) and ( y <= ( home-y + 1 ) ) ]
print "count of home-neighbor-set is "
print count large-regions with [
( x >= ( home-x - 1 )) and ( x <= ( home-x + 1) ) and (y >= ( home-y - 1 ) ) and ( y <= ( home-y + 1) ) ]
print " "
print "here is that set "
show home-neighbor-set
print " "
ask home-neighbor-set [ print (word "Large region with who = " who " has population " population )]
let big-boy max-one-of home-neighbor-set [ population]
show big-boy
print ( word " Neighboring red large-region with largest population is " big-boy " with population " [population] of big-boy )
let bbx 0
let bby 0
let bwho 0
ask big-boy [ set bbx x set bby y set bwho who]
ask patches with [lrx = bbx and lry = bby] [ set pcolor red ]
tick
end
to make-large-regions ;; for testing
let px min-pxcor
let py min-pycor
let region-id -1 ;; missing
let mysize large-region-size
let stopper 0
while [px < max-pxcor] [
while [py < max-pycor] [
if stopper > 300 [ stop ] ;; stops making large regions
set stopper stopper + 1
let xcode round ( ( px + 1) / 5)
let ycode round ( ( py + 1) / 5)
;; make a new region
let decolor one-of [ red blue yellow green ]
create-large-regions 1 [
set terrain one-of ["hilly" "flat" "mountain" "water" "swamp"]
set region-id who
set population random 1000
set x xcode
set y ycode
set region-color decolor
]
;; large region is defined, update the patches in that region
ask patches with [ (abs (pxcor - px) < (mysize / 2) )
and (abs (pycor - py) < (mysize / 2) )] [
set pcolor decolor
set large-region-who region-id
set lrx xcode
set lry ycode
]
set py py + mysize
]
if py > max-pycor [
set py min-pycor
set px px + mysize]
]
end
答案 1 :(得分:0)
这可能不是最好的方法,但是我认为它会起作用。您可以让区域拥有多个变量,例如“ large-region-unique-id”和“ small-region-unique-id”,并在设置所有这些变量的地方进行一次传递。然后,乌龟只需要看一下补丁就可以知道它所在的大小区域。
如果您还制作了一个称为“区域”的代理(例如),则可以拥有区域拥有的变量,并拥有唯一的区域ID。 (实际上,座席的电话号码会起作用 为此)
这应该对信息进行编码,以便移动的海龟可以轻松地查找相关信息。
breed [ large-regions large-region ]
large-regions-own [
terrain-type
large-scale-variables
...
(who)
]
breed [ small-regions small-region ]
small-regions-own [
snow-cover
small-scale-variables
...
(who)
]
patches-own [
large-scale-region-who ;; the id (who) of the large-scale-region the patch is in
small-scale-region-who ;; the id (who) of the small-scale-region the patch is in
...
]
然后,乌龟可以向补丁询问相关的谁信息,并使用它从较大的“补丁”中查找数据。
这里可能是这样
print (word " hilly region count: " count large-regions with [terrain = "hilly"] )
print (word " deep snow count: " count small-regions with [snow-cover > 75])
;; how about highlighting patches that are mountainous with deep snow?
no-display
ask patches [
set terrain-type ""
set my-snow-cover -1
set srw small-scale-region-who
if srw > 0 [set my-snow-cover [snow-cover] of (small-region srw)]
set lrw large-scale-region-who
if lrw > 0
[ set terrain-type [terrain] of large-region lrw]
if-else (terrain-type = "mountain") and (my-snow-cover > 75)
[ set pcolor white ]
[ set pcolor black ]
]
display
print " The mountainous terrain with deep snow-cover is shown in white "