【问题标题】:Restrict Turtle Movement to Boundary in NetLogo在 NetLogo 中限制海龟移动到边界
【发布时间】:2021-09-18 22:34:05
【问题描述】:

在 NetLogo 中,我正在寻找

  • 在导入的 shapefile 上让海龟在其边界内随机发芽,并且
  • 将他们的移动限制在这些边界内

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

请参阅此图片以供参考: MSOA File

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

我考虑过:

  • 创建不同的品种,但考虑到必须有更简单的解决方案,这太乏味了
  • 创建不同的色块并将它们的移动限制在指定的色块内,但这会限制它们的交互(同样太乏味了)

【问题讨论】:

  • 如果你正在导入一个 shapefile,我假设补丁将有一个关于它的补丁自己的变量。然后,这一切都取决于您用来使海龟移动的程序。不管是什么,只要实现一个条件,使得只有海龟区域内的补丁是潜在的移动目标 - 例如move-to one-of patches with [region = my-region]。没有看到你的代码,很难说更多。

标签: gis netlogo shapefile


【解决方案1】:

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

  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 和here)! 理想情况下,您应该提供一个问题示例,就像我的答案的代码部分一样:您可以将其复制粘贴到 NetLogo 中,并且您有一个可行的示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    相关资源
    最近更新 更多