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

Multi-scale landscape in Netlogo (small patches and larger patch groupings)

我试图表示一个多尺度环境,其中我有代表景观中高价值区域的大块和具有本地信息的小块。例如。我想要 1km^2 比例的雪数据,但我也想要更大的补丁 (9km^2) 来总结大规模信息。我的每个大补丁都有一个与其邻居不同的变量值,但变量值可能会在其他补丁的整个景观中重复。我正在为我的海龟寻找最直接的方法来识别大型斑块之间的差异。我曾想过创建补丁集,但我不确定如何解决变量值在不同补丁中重复的问题。非常感谢任何帮助。

编辑:我创建了一个与大比例尺栅格具有相同补丁结构的栅格,并使用它分配 "patch-id's",这样世界上就不再有变量重复了。我仍在努力让海龟将这些较大的补丁识别为分组实体。

这可能不是最好的方法,但我认为它会奏效。您可以让区域拥有多个变量,例如 "large-region-unique-id" 和 "small-region-unique-id",并在设置所有这些变量的地方进行一次传递。那么乌龟只需要看一个补丁就可以知道它属于哪个大小区域。

如果您还制作了一种名为 "regions" 的代理(比方说),您可以拥有区域自有变量和唯一区域 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
   ...
]

然后一只海龟可以向补丁请求相关的 who 信息,并使用它从更大的 "patches".

中查找数据

这可能是这样的

  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 "

你评论了我的第一个回答

My main issue is that I need to run a "find max-one-of neigboring-large-patches [large-scale-variable]" so I need my turtles to understand what the neighboring large-patches are and be able to read them as units, if that makes sense. I can't quite figure out how to incorporate that into your answer, any thoughts?

这是如何做到这一点。这段代码又快又草率,但它说明了这一点。

让大区域具有创建期间生成的 x 和 y 值。基本上,这些存储覆盖视口的大区域网格的列号和行号。

breed [ large-regions large-region ]
large-regions-own [
   terrain
   region-color
   population
   x
   y
]

然后,从概念上讲,一个区域的相邻区域的 x 和 y 值将在该区域的 x 和 y 值的 +/- 1 范围内,因此您可以这样识别它们。

为了以 space 为代价简化编码,当我生成区域时,我还将该区域的唯一标识符 (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