gis - 你如何让海龟只跟随我从加载到 netlogo 的 shapefile 创建的绿色补丁?
问题描述
到目前为止,这是我的代码。我只希望海龟跟随绿线,但是当我设置模型时,它们只会永远沿着它们所面对的随机方向继续。
代码:
extensions [gis]
breed [observer]
turtles-own [ vision-distance vision-width steps green-steps gray-steps attr-prob]
patches-own [land nearest-patch]
to setup
clear-all
create-turtles 10
set-default-shape turtles "butterfly"
ask turtles [set size 25
if pxcor = min-pxcor [die]]
reset-ticks
let view gis:load-dataset "City_Plan_Boundary.shp"
gis:set-world-envelope gis:envelope-of view
foreach gis:feature-list-of view
[
gis:set-drawing-color green
gis:draw ? 1.0
]
end
to go
ask turtles [
count-steps
pen-down
let green_target turtles
let perceived_patches patches in-cone vision-distance vision-width
let patch-under-me patch-here set green_target perceived_patches with [ (pcolor = green and self != patch-under-me) or (pcolor = black and self != patch-under-me)]
ifelse count green_target != 0 [
let target min-one-of green_target[ distance myself ]
let target_heading towards target
move-to patch-at-heading-and-distance target_heading 1 ]
[ fd 1]
]
end
to count-steps
set steps steps + 1
ifelse land = green [set green-steps green-steps + 1][set gray-steps gray-steps + 1] ;;Does not currently account for CYAN Park squares
end
解决方案
首先,foreach
应用 GIS 层的循环只是在 NetLogo 的绘图层中创建线,而不是实际更改补丁本身。您必须将 shapefile 的某些组件分配给补丁本身,以便海龟能够评估它们 - 查看模型库中的“GIS 一般示例”模型。
其次,寻路可以通过多种方式完成,这实际上取决于您尝试建模的行为。对于一些示例,请查看模型库中的“前瞻”示例,或者查看下面的玩具模型以获得非常简单的方法:
to setup
ca
ask patch min-pxcor 0 [
set pcolor green
sprout 1 [
set color red
pd
]
spread-right
]
reset-ticks
end
to spread-right
if pxcor < max-pxcor [
ask one-of neighbors with [ pxcor = [pxcor] of myself + 1] [
set pcolor green
spread-right
]
]
end
to go
ask turtles [
let target one-of neighbors in-cone 1.5 90 with [ pcolor = green ]
ifelse target != nobody [
face target
move-to target
] [
rt one-of [ 45 -45 ]
]
]
tick
end
推荐阅读
- asp.net-core - 优化 API 的响应时间,涉及 SQL Server
- python - 如何在 Kivy 中编译带有文件夹的 APK?
- java - 发送空搜索规范
- exception - 如何将 LLVM 中的 PointerType 与某些类型名称匹配?
- python - 如何根据单词列表对字符串的单词进行分组?
- c# - 分配对象时如何防止模型属性的延迟加载?
- typescript - 有谁知道如何在 Ionic Storage 中合并 2 个数组?
- spring-boot - Neo4jRepository 从 Kotlin 数据类中保存空节点
- flutter - CrossAxisAlignment 不居中列小部件
- android - 设备上没有反应原生图标来卸载应用程序