gis - 在 NetLogo 中限制海龟移动到边界
问题描述
在 NetLogo 中,我正在寻找
- 让海龟在导入的 shapefile 的边界内随机发芽,并且
- 将他们的活动限制在这些边界内
目前,我让它们在质心处发芽,但很快它们就遍布整个地图。如何将 shapefile 合并到海龟的运动中?理想情况下,它们会稍微超出边界,但我确信在我限制它们之后很容易操纵。海龟需要能够跨越国界相互交互,而不是穿越整个地图。
请参阅此图像以供参考: MSOA 文件
一个单独的解决方案可能是将它们限制在它们发芽的半径范围内,但也不确定如何做到这一点。
我考虑过:
- 创建不同的品种,但考虑到必须有一个更简单的解决方案,这太乏味了
- 创建不同颜色的补丁并将它们的移动限制在指定颜色的补丁上,但这会限制它们的交互(并且再次太乏味)
解决方案
你想要做的是给补丁两个变量:
- 一个标识它们属于哪个区域(假设您导入了 shapefile,我假设这已经存在于您的代码中);
- 另一个标识补丁自己的区域+区域足够近,以至于来自另一个区域的乌龟可能会移动到那里。
我将调用第一个变量region
,它将是一个整数,第二个变量allowed
,它将是一个整数列表。
这个想法是海龟,每一个都有自己的my-region
价值,基于它的起源,将查看allowed
补丁变量(而不是 at 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
对于未来的问题,请分享您拥有的/您所做的(查看此处和此处)!理想情况下,您应该提供一个问题示例,就像我的答案的代码部分一样:您可以将其复制粘贴到 NetLogo 中,并且您有一个可行的示例。
推荐阅读
- java - 如何将此 Java For Each 循环转换为常规 For 循环?
- javascript - 如何在邮递员中遍历以下 xml 响应以使用循环实现所有大陆?
- mysql - 获取mysql中基于3年的调度数据
- python - 即使使用用户代理,Python 也会请求错误 403
- python - 尽管输入了正确的数字,但获得的参数数量无效
- php - 如何使 Laravel 与多个表建立雄辩的关系?
- vb.net - 如何在 WinForms 应用程序中正确构造类和事件
- wpf - 将情节提要的目标设置为 DataTemplate WPF 中的按钮
- python - 我正在尝试复制 html 网站,但每当我尝试时,它只会给我其中的一部分
- android - 如何通过 curl POST 命令发送 logcat