问题描述
此模型的目的是显示被狼特工占据的斑块,并显示狼在哪里成功杀死(猎物)。数据由CSV文件提供,该CSV文件列出了在某个时间访问过狼以及是否成功杀人的所有补丁坐标。 CSV文件的格式为:刻度号,补丁程序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
CSV文件格式为:
我试图通过使用以下命令来实现“ 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文件的patch-id与.nlogo pxcor pycor相关联。任何帮助或建议,将不胜感激!
解决方法
有一种非常简单的方法可以将这种CSV数据加载到Sect中的NetLogo中。 5.5的Railsback和Grimm: