The purpose of this model is to display patches that were occupied by wolf-agents and show where the wolves made successful kills (of prey agents). The data is provided by a CSV file which lists all patch coordinates that had wolf-visitation at some point and if there was a successful kill. The format of the CSV file is: tick #, patch-id (pxcor pycor), wolf-pack-id, and kill-count. At the moment, I just want the patches that have pxcor pycor = patch-id to have an "ACTIVE" attribute so I can easily differentiate which patches were visited by wolves and which patches were not visited by wolf agents.
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
]
So far, I have successfully loaded the data into my .nlogo project by having the .CSV read line by line:
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
I tried to implement a "while" loop by having this command:
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 gives a syntax error with the current code, but I am hoping someone can help me implement this wolf-occupation status correctly. Or, if someone could help me understand how to correlate the CSV file's patch-id to the .nlogo pxcor pycor.
