首页 > 解决方案 > 从 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

CSV 文件格式为: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 文件的补丁 ID 与 .nlogo pxcor pycor 相关联。

标签: csvcoordinatesnetlogopatch

解决方案


推荐阅读