在 NetLogo 中限制海龟移动到边界

Restrict Turtle Movement to Boundary in NetLogo

在 NetLogo 中,我正在寻找

目前,我让它们在质心处萌芽,但很快它们就散布在整个地图上。如何将 shapefile 合并到乌龟的运动中?理想情况下,它们会略微超出边界,但我确信在我限制它们之后这很容易操纵。海龟需要能够跨越边界与彼此互动,而不是穿越整个地图。

参考这张图片: MSOA File

一个单独的解决方案可能是将它们限制在它们发芽的半径范围内,但也不确定该怎么做。

我考虑过:

你要做的是给补丁两个变量:

  1. 标识它们属于哪个区域的一个(我假设这已经存在于您的代码中,假设您导入了一个 shapefile);
  2. 另一个标识补丁自己的区域 + 足够接近以至于来自其他区域的海龟可能会移动到那里的区域。

我将调用第一个变量 region,它将是一个整数,第二个变量 allowed,它将是一个整数列表。

这个想法是,每只海龟都有自己的 my-region 值,基于它的起源地,它们将查看 allowed 补丁变量(而不是 region) 看看他们可以移动到哪里。这样,每只海龟将能够移动到属于它自己区域的任何补丁+到那些足够接近它的区域的补丁(根据你指定的值,我在这里称之为buffer-range)。

逻辑是这样的

下面的代码实现了它,相关部分是 to create-buffers - 我在代码中对此进行了评论。 然后,to go 使用这个新信息来确定乌龟可以移动的潜在补丁,包括那些在其区域之外但足够接近的补丁(你没有分享你的乌龟是如何移动的,但应用相同的条件应该很容易无论您正在实施什么程序)。

; Untick the 'World wraps horizontally' box in Interface > Settings.

globals [
 buffer-range
]

patches-own [
 region
 allowed
]

turtles-own [
 my-region 
]

to setup
  clear-all
  create-regions
  create-buffers
  populate-world
end

to create-regions
  ask patches [
   ifelse (pxcor < 0)
    [set region 1
     set allowed (list region)
     set pcolor 43]
    [set region 2
     set allowed (list region)
     set pcolor 63]
  ]
end

to create-buffers
  set buffer-range 3
  
; First, each patch targets the patches that belong to another region which is near enough according to
; the buffer value, and it also creates a local empty list that will be used by those patches.
; Then the patch ask those target patches, if any, to check if their region has not been recorded already
; as a region allowed for movement or as such a candidate. If that's the case, that region is added to
; the allowed-candidates list.
  ask patches [
    let target-patches (patches with [region != [region] of myself] in-radius buffer-range)
    let allowed-candidates (list)
    
    if (any? target-patches) [
      ask target-patches [
       if (not member? region [allowed] of myself) and (not member? region allowed-candidates) [
         set allowed-candidates (lput region allowed-candidates)
        ]
      ]
    ]
    
; Now, each element of the allowed-candidates list is added to the allowed list.
    foreach allowed-candidates [x -> set allowed (lput x allowed)]
  ]
end
  
to populate-world
  create-turtles 10 [
    setxy random-xcor random-ycor
    set my-region region
    set color pcolor + 2
  ]
end

to go
  ask turtles [
    move-to one-of patches with [member? [my-region] of myself allowed]
  ]
end

对于以后的问题,请分享你所拥有的/你所做的(勾选here and here)! 理想情况下,您应该提供一个问题示例,就像我回答的代码部分一样:您可以将其复制粘贴到 NetLogo 中,并且您有一个可行的示例。