csv - 从 Excel 数据显示 NetLogo 中的特定补丁
问题描述
该模型的目的是显示被狼特工占据的斑块,并显示狼在哪里成功杀死(猎物特工)。数据由 CSV 文件提供,该文件列出了在某个时间点有狼来访的所有补丁坐标以及是否成功杀死。CSV 文件的格式为:tick #、patch-id (pxcor pycor)、wolf-pack-id 和 kill-count。目前,我只希望具有 pxcor pycor = patch-id 的补丁具有“ACTIVE”属性,以便我可以轻松区分狼访问了哪些补丁,以及狼代理没有访问哪些补丁。
globals [
grass-patches ;; NLCD classifications
forest-patches
urban-patches
agriculture-patches
water-patches
barren-patches
vegetation-dataset ;; DEM data layers
elevation-dataset
slope-dataset
map-data ;;CSV data from wolf model-- wolf dispersal and kmarker location
]
patches-own [
NLCDtype ;; The grouping/classifications of the different NLCD veg-types--these correspond to the global patch types
veg-type ;; NLCD gridcodes for teh vegetation data
veg-amount ;; Resources/biomass available for the prey to consume
elevation ;; DEM
slope ;; DEM
countdown ;; How the vegetation "grow" and die through the model time
hash-id ;; The UNIQUE ID (xy coordinates) for each patch
wolf-occupation ;; How to tell if a wolf agent has been in the patch: ACTIVE shows occupation, INACTIVE has no wolf occupation
]
到目前为止,我已经通过逐行读取 .CSV 成功地将数据加载到我的 .nlogo 项目中:
to setup
clear-all
reset-ticks
setup-gis
load-csv-data
ask patches [ set hash-id (word pxcor " " pycor)]
end
to load-csv-data
ifelse ( file-exists? "ph-memory_TEST.csv" )
[
file-open "Ph-memory_TEST.csv"
while [ not file-at-end? ]
[set map-data csv:from-row file-read-line]
user-message "File loading complete!"
]
[user-message "There is an error reading the CSV data"]
end
我尝试通过使用以下命令来实现“while”循环:
to load-wolf-data
cp
ifelse ( is-list? map-data )
[foreach map-data [
ask patches [while (pxcor pycor = position 1 map-data) [set wolf-occupation "ACTIVE"]
] ]]
[user-message "You need to load the map data first!"]
end
NetLogo 给出了当前代码的语法错误,但我希望有人能帮助我正确实现这个狼占领状态。或者,如果有人可以帮助我了解如何将 CSV 文件的补丁 ID 与 .nlogo pxcor pycor 相关联。
解决方案
推荐阅读
- pug - 我如何在 pugjs 中使用 json 文件
- android - 嵌套的 RecyclerView onClick 未触发
- html - 角度 7 变化前图像闪烁
- java - ApiException 需要 Throwable,发现 CustomException
- python - 如果日期在当前索引和上一个索引之间,则将值添加到具有“日期时间”索引的数据框的当前行
- c++ - C 字符串作为模板非类型参数适用于 gcc 6.3,但不适用于 Visual Studio 2017(19.16.27027.1 for x64)
- javascript - 使用 JQuery Find 方法在 HTML 表中查找复选框
- odoo - Odoo 继承字段和功能
- linux - 指定 GCC 输出二进制文件的预期 Linux 版本
- dart - 如何从flutter redux中的void方法调用调度动作