我试图代表一个多尺度的环境,我有大的斑块,代表景观中的高价值地区,小的斑块,有当地的信息。例如,我想要1km^2尺度的降雪数据,但我也希望有更大的贴片(9km^2)来总结大型信息。我的每个大补丁都有一个与其邻居不同的变量值,但是在其他补丁中,变量值可能会在整个景观中重复。我正在寻找最直截了当的方式,我的海龟,以确定之间的差异,大面积的补丁。我曾经想过要创建补丁集,但我不知道如何绕过在不同补丁中重复出现的变量值的问题。任何帮助都是非常感谢的。
编辑:我已经创建了一个具有相同补丁结构的光栅作为大型光栅,并使用它指定了“修补程序id”,这样世界上就不再有可变的重复。我仍在努力让海龟将这些较大的斑块识别为分组实体。
发布于 2019-11-11 22:53:46
你对我的第一个回答发表了意见
我的主要问题是,我需要运行一个"find max-one-one“--大型补丁--大型变量--这样我就需要我的海龟了解相邻的大型补丁是什么,并且能够以单位的形式读取它们,如果这是有意义的话。我不知道如何把它融入你的回答,有什么想法吗?
以下是如何做到这一点。这段代码既快速又草率,但它说明了这一点。
让大区域具有在创建过程中生成的x和y值。基本上,这些存储覆盖视图端口的大区域的网格的列和行号。
breed [ large-regions large-region ]
large-regions-own [
terrain
region-color
population
x
y
]
然后,从概念上讲,一个区域的邻居将在该区域的x和y值的+/- 1中包含x和y值,这样您就可以这样识别它们。
为了以牺牲空间为代价简化编码,当我生成区域时,我还将该区域的唯一标识符(who)及其x和y值存储到该区域的每个补丁中,即变量lrx和lry中。
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
发布于 2019-11-10 19:09:30
这可能不是最好的办法,但我认为这是可行的。您可以让区域拥有多个变量,例如“大区域-唯一-id”和“小区域-唯一-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 "
https://stackoverflow.com/questions/58793754
复制