Netlogo中的多尺度景观(小补丁和大补丁组)

Netlogo中的多尺度景观(小补丁和大补丁组),netlogo,Netlogo,我试图表示一个多尺度的环境,其中我有代表景观中高价值区域的大斑块,以及包含本地信息的小斑块。例如,我希望获得1公里^2范围内的降雪数据,但我也希望获得9公里^2范围内更大的补丁,以汇总大规模信息。我的每个大斑块都有一个不同于其相邻斑块的可变值,但该可变值可能会在其他斑块的整个景观中重复。我正在为我的海龟们寻找一种最直接的方法来识别大规模斑块之间的差异。我曾想过创建补丁集,但我不知道如何解决变量值在不同补丁中重复的问题。非常感谢您的帮助 编辑:我已经创建了一个具有与大规模光栅相同的面片结构的光栅,

我试图表示一个多尺度的环境,其中我有代表景观中高价值区域的大斑块,以及包含本地信息的小斑块。例如,我希望获得1公里^2范围内的降雪数据,但我也希望获得9公里^2范围内更大的补丁,以汇总大规模信息。我的每个大斑块都有一个不同于其相邻斑块的可变值,但该可变值可能会在其他斑块的整个景观中重复。我正在为我的海龟们寻找一种最直接的方法来识别大规模斑块之间的差异。我曾想过创建补丁集,但我不知道如何解决变量值在不同补丁中重复的问题。非常感谢您的帮助


编辑:我已经创建了一个具有与大规模光栅相同的面片结构的光栅,并指定了面片id,以便在世界上不再有可变重复。我仍在努力让海龟们将这些较大的补丁识别为分组实体。

这可能不是最好的方法,但我认为它会起作用。您可以让区域拥有多个变量,例如大区域唯一id和小区域唯一id,并在设置所有这些变量的地方进行一次传递。然后海龟只需看一块补丁就可以知道它所处的区域大小

如果你还制作了一种称为regions的代理,比如说,你可以有regions自己的变量和一个惟一的region-id。实际上,代理的who号码可以工作 为此

这将对信息进行编码,以便移动的海龟可以轻松地查找相关信息

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 "

你对我的第一个答案发表了评论

我的主要问题是我需要运行一个find max one 邻接大补丁[大规模变量],所以我需要我的海龟 了解相邻的大斑块是什么,并能够 如果有意义的话,把它们作为单位来读。我不太明白怎么做 要把它纳入你的答案,有什么想法吗

下面是如何做到这一点。这段代码速度快且草率,但它说明了这一点

让大区域具有在创建过程中生成的x和y值。基本上,它们存储覆盖视口的大区域栅格的列号和行号

breed [ large-regions large-region ]
large-regions-own [
   terrain
   region-color
   population
   x
   y
]
然后,从概念上讲,区域的相邻区域的x和y值在区域x和y值的+/-1范围内,因此您可以通过这种方式识别它们

为了以牺牲空间为代价简化编码,在生成区域时,我还将该区域的唯一标识符及其x和y值存储到该区域的每个面片中,即变量lrx和lry中

patches-own [
   large-region-who
   lrx
   lry
]
按照您的要求,查找人口最大值的相邻大区域的核心如下。我编写这个代码是为了调试的速度,而不是为了美观,所以可以对它进行大幅度的清理。完整的源代码有许多print语句,可以有效地注释解决请求的搜索的每个步骤

这将查找修补程序0,从该修补程序中查找关于大区域x和y的信息,生成一个具有附近x和y值的大区域代理集,在该集上执行max[population]搜索以提取人口最多的区域。它还将询问区域涂成黑色,局部大区域涂成蓝色,最大人口邻居涂成红色

它基本上是有效的——大的区域被一个补丁从它们应该在的地方偏移——但这说明了这一点。运行安装程序并亲自查看

这是一个丑陋的代码。有趣的问题。您可以很容易地将其扩展到小区域,并使两者同时工作。享受吧

  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

嗨,韦德,谢谢你的回答。我的主要问题是,我需要运行find max one of neigboring large patches[大规模变量],因此我需要我的海龟们理解相邻的大型补丁是什么,并能够将它们作为一个单元来读取,如果这有意义的话。我不太明白如何把它纳入你的答案,有什么想法吗?