;********************************************************************************************* ;***Code created for the moose hunting simulation for Nuiqsut on the North Slope of Alaska *** ;********************************************************************************************* extensions [ gis ] globals [ lc-layer river-layer access-layer mdist2000-layer riverdist-layer flows-layer pathdistances-layer basin-layer julian day month year ; Date variabiles file-in-name cell-dimension moose-rel-dens land-cover-ids moose-land-cover AT-VILLAGE NEED-MOOSE-SITE ; Activity codes TRAVEL-MOOSE HUNT-MOOSE NON-HARVESTER GO-HOME WATER ; Code for oceans and water TOWN-LOW TOWN-HIGH ; Low and high density residential from NLCD moose-season base-moose-count ; Beginning animal numbers patches-done dist-of-interest ] breed [ moose a-moose ] breed [ houses house ] breed [ dtemp d-temp ] ; A temporary breed, of no biological importance patches-own [ lc ; Land cover mdist2000 ; Moose distribution layer for the year of 2000, based on the maxent model results from Zhou et al. 2020. access ; Accessibility river ; The patch is river (255) or not (0) riverdist ; The distance from the rivers path-distance-to-town ; The distance to town along the best path on the river. flow-id ; An index of increasing id values as one flows up river. Note that the values may skip as other tributaries were incremented. basin ; A river reach identifier moose-usage moose-hsi ; Moose habitat and usage distance-to-village ; The distance from the patch to the town. Used in selecting hunting locations. The towns are tiny relative to the landscape, so the distance can be to any town cell. temp temp-test ; Temporary variables (could be replaced with local variables if memory is low) ] moose-own [ centroid-x centroid-y ] ; Home range centroid. dtemp-own [ xlist ylist id ] houses-own [ id unique-id ; no need for the rest of the id etc in this simulation. home-x home-y activity site-x site-y ; House location and activity variables x-list y-list ; A paired list of locations that, if followed, will take a hunter to or from a hunting site, depending upon the direction traveled through the list. xy-index ; The current index in the list for the location of the home. moose-hunting-days moose-taken-this-year moose-taken ; Animal hunting and harvesting accumulators activity-days ; A generic measure used to keep track of how long someone is hunting. ] ; *********************************** ; ***** SETUP ; *********************************** to setup clear-all file-close-all ; profiler:start setup-gis setup-parms setup-houses setup-agents reset-ticks end ; *********************************** ; ***** SETUP-GIS ; *********************************** to setup-gis ; BASIC COVER (NLCD 2001) print ( word "Loading the land cover image." ) set lc-layer gis:load-dataset "./Layers/nlcd_aoi.asc" gis:apply-raster lc-layer lc ; Moose print ( word "Loading the moose distribution 2000 image." ) set mdist2000-layer gis:load-dataset "./Layers/mdist2000_10000.asc" gis:apply-raster mdist2000-layer Mdist2000 ; Not a number requires being replaced. Some cells are coming in a not-a-number. These are often at the very edge. The test and fix is ... ask patches [ ifelse mdist2000 <= 0 or mdist2000 > 0 [ ; Do nothing, a valid number ] [ set mdist2000 -1 ] ] ; RIVERS (NLCD 2001) ... only if the layer exists print "Loading river.asc, the river layer." set file-in-name "./Layers/river.asc" set river-layer gis:load-dataset file-in-name gis:apply-raster river-layer river ask patches [ ifelse river <= 0 or river > 0 [ ; Do nothing, a valid number ] [ set river 0 ] ] ; RIVER DISTANCE print "Loading riverdist.asc, the riverdist layer." set file-in-name "./Layers/riverdist.asc" set riverdist-layer gis:load-dataset file-in-name gis:apply-raster riverdist-layer riverdist ask patches [ ifelse riverdist <= 0 or riverdist > 0 [ ; Do nothing, a valid number ] [ set riverdist -1 ] ] ; FLOW IDS print "Loading flow.asc, the flow directon layer." set file-in-name "./Layers/flows.asc" set flows-layer gis:load-dataset file-in-name gis:apply-raster flows-layer flow-id ask patches [ ifelse flow-id <= 0 or flow-id > 0 [ ; Do nothing, a valid number ] [ set flow-id -1 ] ] ; PATH DISTANCES ... a file created fresh only if needed, the gis layer contains the number of pixels between the patch in question and the town. if file-exists? "./Layers/PathDistances.asc" [ print "Loading PathDistances.asc, the distance-to-town layer." ;To simulate the access levels, use different of files for PATH DISTANCE for current and increased set file-in-name "./Layers/PathDistances.asc" ;access levels, which is a simpler way to achieve the goal. set pathdistances-layer gis:load-dataset file-in-name gis:apply-raster pathdistances-layer path-distance-to-town ask patches [ ifelse path-distance-to-town <= 0 or path-distance-to-town > 0 [ ; Do nothing, a valid number ] [ set path-distance-to-town -1 ] ] ] ; BASINS print "Loading basins.asc, the layer identifying river reaches." set file-in-name "./Layers/basins.asc" set basin-layer gis:load-dataset file-in-name gis:apply-raster basin-layer basin ask patches [ ifelse basin <= 0 or basin > 0 [ ; Do nothing, a valid number ] [ set basin -1 ] ] ; ACCESSIBILITY let Max-distance-hunting-from-river 3000 ask patches [ set access river * 100 ] ask patches with [ riverdist <= Max-distance-hunting-from-river ] [ let t ( Max-distance-hunting-from-river - riverdist ) / Max-distance-hunting-from-river set access access + t * 100 ] refresh end ; *** End SETUP-GIS ; ******************************* ; **** GET-DISTANCE-TO-VILLAGE ; ******************************* to get-distance-to-village ; Get distance to village ... using a random location within the town. At the extreme, would use an individual's location, but that would add a great deal of computing for little gain in accuracy let one-patch one-of patches with [ lc = 22 ] let tempx [ pxcor ] of one-patch let tempy [ pycor ] of one-patch ask patches [ set distance-to-village distancexy tempx tempy ] end ; **************************** ; **** GO ; **************************** to go if item julian moose-season >= 0 ; Check to see if the moose season is over and everyone should come home. [ manage-moose-and-moose-hunting move-home ; No harm in attempting to move home, even if there is no one away from home replace-moose ; The number of agents does not vary. They get replaced. ] tick if ticks = 365 [ redistribute-moose ; Redistribute the moose at the end of the year to reflect animal movement. ] increment-times end ; ************************************ ; **** MANAGE-MOOSE-AND-MOOSE-HUNTING ; ************************************ to manage-moose-and-moose-hunting move-moose ifelse item julian moose-season = 0 ; Check to see if the moose season is over and everyone should come home. [ ask houses with [ activity = TRAVEL-MOOSE or activity = HUNT-MOOSE ] [ set activity GO-HOME ] ] [ who-is-moose-hunting select-moose-hunting-site move-moose-hunters hunting-moose ] end ; ***************** ; *** SETUP-HOUSES ; ***************** to setup-houses ; Creating households. Many ways to do this; just one way. repeat Number-of-hunting-groups [ let house-cnt 0 ask one-of patches with [ lc = TOWN-LOW or lc = TOWN-HIGH ] [ sprout-houses 1 [ set house-cnt house-cnt + 1 set hidden? FALSE set id house-cnt set color cyan set size 9.0 set shape "circle" set activity AT-VILLAGE set site-x -999 set site-y -999 set home-x xcor set home-y ycor ] ] ] end ; *********************************** ; * SETUP-PARMS ; *********************************** to setup-parms set julian 0 set day 0 set month 1 set year 0 set cell-dimension 333.3 ; 300 x 300 m ; Set activity codes to improve readability of the code. set AT-VILLAGE 1 set NEED-MOOSE-SITE 2 set TRAVEL-MOOSE 8 set HUNT-MOOSE 14 set NON-HARVESTER 98 set GO-HOME 99 ; Set some useful land cover types set WATER 11 set TOWN-LOW 22 set TOWN-HIGH 23 ;********************************** ; Get MOOSE land use file-open "./Moose_Land_Cover.txt" set land-cover-ids ( list file-read ) set moose-land-cover ( list file-read ) let dummy file-read-line while [ not file-at-end? ] [ set land-cover-ids lput file-read land-cover-ids set moose-land-cover lput file-read moose-land-cover set dummy file-read-line ] file-close type "Echoing land cover identifiers : " print land-cover-ids type "Echoing moose land cover selection: " print moose-land-cover ; Initialize moose usage values ask patches [ set moose-usage 0.01 ] ; Get Seasonal indicators for MOOSE file-open "./Moose_season.txt" set dummy file-read-line set moose-season ( list file-read ) set dummy file-read-line ; A flag showing the season to take moose, by Julian date. Discard the rest of the line. while [ not file-at-end? ] [ set moose-season lput file-read moose-season set dummy file-read-line ] file-close type "Echoing moose season identifiers : " print moose-season end ; *********************************** ; * SETUP-AGENTS ; *********************************** to setup-agents ; let moose-cnt int ( ( ( ( world-width * world-height * ( cell-dimension * cell-dimension ) ) ) / 1000000. ) * Moose-density ) let moose-cnt Moose-in-area set base-moose-count moose-cnt let cnt 0 while [ cnt < moose-cnt ] [ ask one-of patches [ if random-float 10000 < mdist2000 [ sprout-moose 1 [ set centroid-x xcor set centroid-y ycor set shape "circle" set color yellow set size 1.8 ] set cnt cnt + 1 ] ] ] end ; *********************************** ; * MOVE-MOOSE ; *********************************** to move-moose ask moose [ ; The following clause should come into play very rarely after the first cycle while [ xcor = centroid-x and ycor = centroid-y ] [ forward 0.001 ] let ang towardsxy centroid-x centroid-y ; set moose-hsi mdist2000 set moose-hsi 0 ask neighbors [ let hding towards myself let diff-hding abs ( subtract-headings ang hding ) ; Add any elements here to build a component hsi index for moose. ; Here the percent use of the area is combined with a measure of how often a given animal has used a patch ifelse diff-hding > 157.5 ; < 22.5 [ set moose-hsi 0 + Moose-homing-tendency ] [ set moose-hsi 0 ] set moose-hsi moose-hsi + random-float Moose-random-component ] ; Incorporate a correlated component to the random walk if patch-ahead 1 != nobody and patch-ahead 1 != patch-here [ ask patch-ahead 1 [ set moose-hsi moose-hsi + Moose-correlated-movement ] ] ; The following clause to allow for animals to look at the patch ahead and avoid moving there if there are too many animals at that patch already. move-to patch-here ;; go to patch center let p max-one-of neighbors [ moose-hsi ] if [ moose-hsi ] of p > moose-hsi [ face p let c 0 if patch-ahead 1 != nobody [ ask patch-ahead 1 [ set c count moose-here ] if c < Max-moose-per-patch [ move-to p ] ] ] ; Now do bookkeeping that affects animal or hunter behavior, but not the location at this time step set moose-usage moose-usage + 1 let tempx ( xcor - centroid-x ) / 10.0 set centroid-x centroid-x + tempx let tempy ( ycor - centroid-y ) / 10.0 set centroid-y centroid-y + tempy ] end ; *********************************** ; * SELECT-MOOSE-HUNTING-SITE ; *********************************** to select-moose-hunting-site let tx 0 let ty 0 let n 0 if ( julian + 1 ) mod Update-herbivore-usage-frequency = 0 ; Day is coming in a zero initially, so adding one. [ if any? houses with [ activity = NEED-MOOSE-SITE ] [ ; Do the work of building a test surface that combines all elements to be considered when selecting a hunting site let m max [ moose-usage ] of patches ask patches [ set temp-test ( moose-usage / m ) ; Start with a standardized score of moose usage ] ; Add an accessibility penalty set n max [ access ] of patches ask patches [ let ind access / n set temp-test temp-test * ind ] ] ; Add the hunters that are already assigned a location so that others may avoid them. ask houses with [ activity = HUNT-MOOSE and site-x >= -900 ] ; If site-x = -999, no site is assigned. If >= -900, a site has been assigned. [ let sx site-x let sy site-y ask patches with [ distancexy sx sy < ( Hunter-tolerance-of-neighbors / cell-dimension ) ] [ set temp-test 0 ] ; Just zeroing-out, the specifics don't matter, just don't want people to select that area ] ; So if the slider is 0, nothing will change. If the slider is 100, the values in those river stretches will drop to zero. ask patches [ if basin = 1 or basin = 2 or basin = 3 or basin = 9 or basin = 10 or basin = 11 [ set temp-test temp-test * ( ( 100.0 - Favor-Colville-River ) / 100 ) ] ] let m max [ temp-test ] of patches ] ; Only the following clause modifies where people hunt. That is, all the people who are to hunt but don't yet have a site are assigned one here. ; That is why the hunter tolerance adjustment is made here as well as above, to account for the newly assigned hunters. ask houses with [ activity = NEED-MOOSE-SITE ] [ let some-patches patches with [ path-distance-to-town > 0.1 and path-distance-to-town <= ( ( Proximity-of-hunt * 1000 ) / 333.33 ) ] ; The math is to convert from km to patches. NOTE that diagonal distances associated with patches will be ignored. ask max-one-of some-patches [ temp-test ] [ set tx pxcor set ty pycor ask patches with [ distancexy tx ty < ( Hunter-tolerance-of-neighbors / cell-dimension ) ] [ set temp-test 0 ] ; See above ] set site-x tx set site-y ty set activity-days 0 set activity TRAVEL-MOOSE ; Create a list of x-y pairs that allow a hunter to return home from their hunting site. That is the direction that works best with the flow directions calculated. get-path-home set xy-index length x-list - 1 ] end ; *********************************** ; * MOVE-MOOSE-HUNTERS ; *********************************** to move-moose-hunters ask houses with [ activity = TRAVEL-MOOSE and site-x > -900 ] [ let day-moves ( Hunter-travel-speed * 6 * 1000 ) / cell-dimension let dm 1 while [ dm < day-moves ] [ ; By default, given activity code, the household is traveling "up" the indices of positions let xpos item xy-index x-list let ypos item xy-index y-list setxy xpos ypos display wait 0.001 set xy-index xy-index - 1 ifelse xy-index = 0 [ ; Reached the end of the list. The household should be at its hunting site. Bail out of the while loop by setting dm high. set dm day-moves ] [ set dm dm + 1 ] ] set color yellow if ( site-x = xcor and site-y = ycor ) or xy-index = 0 [ set activity HUNT-MOOSE set color orange set xy-index 1 ] ] end ; *********************************** ; * MOVE-HOME ; *********************************** to move-home ask houses with [ activity = GO-HOME ] [ let lastindex length x-list - 1 let day-moves ( Hunter-travel-speed * 6 * 1000 ) / cell-dimension let dm 1 while [ dm < day-moves and xy-index < lastindex ] [ ; By default, given activity code, the household is traveling "up" the indices of positions let xpos item xy-index x-list let ypos item xy-index y-list setxy xpos ypos display wait 0.001 set xy-index xy-index + 1 ifelse xy-index = lastindex [ ; Reached the end of the list. The household should be at its hunting site. Bail out of the while loop by setting dm high. set dm day-moves ] [ set dm dm + 1 ] ] if ( home-x = xcor and home-y = ycor ) or xy-index = lastindex [ setxy home-x home-y set activity AT-VILLAGE set color 138 ] ] end ; *********************************** ; * WHO-IS-MOOSE-HUNTING ; *********************************** to who-is-moose-hunting ; ask n-of n houses with [ activity = AT-VILLAGE and moose-taken-this-year < Moose-bag-limit ] ask houses with [ activity = AT-VILLAGE and moose-taken-this-year < Moose-bag-limit ] [ set activity NEED-MOOSE-SITE ] end ; *********************** ; *** REPLACE-MOOSE ; *********************** to replace-moose while [ count moose < base-moose-count ] [ ask one-of moose [ hatch 1 ] ] end ; *********************** ; *** RECALCULATE-DISTANCES ; *********************** to recalculate-distances if "Yes" = user-one-of "This is only used if something changed the pathways used to hunting locations. Do you wish to continue?" ["Yes" "No"] [ ask patches with [ riverdist < 5000 and mdist2000 > 0 ] ; Caculate for patches that are within 5 km only. This may be VERY slow. [ set pcolor orange ; type pxcor type " " print pycor get-path-distance-only set path-distance-to-town dist-of-interest set pcolor red set patches-done patches-done + 1 ] ; Check for not-a-number patches and fix them. Set them to -1 ask patches [ ifelse path-distance-to-town <= 0 or path-distance-to-town > 0 [ ; Do nothing, a valid number ] [ set path-distance-to-town -1 ] ] let newraster gis:patch-dataset path-distance-to-town gis:store-dataset newraster "PathDistances.asc" ] end ; *********************** ; *** REDISTRIBUTE-MOOSE ; *********************** to redistribute-moose ; Select patches related to the expected density coming from Maxent Model results. Distribute animals in a linear way related to that. let xtemp 0 let ytemp 0 ask moose [ let placed FALSE while [ placed = FALSE ] [ ask one-of patches [ if random-float 10000 < mdist2000 [ set placed TRUE set xtemp pxcor set ytemp pycor ] ] setxy xtemp ytemp ] ] end ; *********************************** ; * HUNTING-MOOSE ; *********************************** to hunting-moose ask houses with [ activity = HUNT-MOOSE ] [ ; If and only if an animal is within range, then a probability comes into play to see if the hunter is successful. let rad Hunting-radius / cell-dimension let mooses moose in-radius rad ifelse count mooses > 0 and random-float 1.0 < Hunt-prob-success [ set moose-taken-this-year moose-taken-this-year + 1 set moose-taken moose-taken + 1 set site-x -999 set site-y -999 set activity GO-HOME set moose-hunting-days 0 ask one-of mooses [ die ] ] [ set moose-hunting-days moose-hunting-days + 1 ; If hunting for some number of days without success, go back home if moose-hunting-days > Moose-max-hunting-duration [ set site-x -999 set site-y -999 set activity GO-HOME set moose-hunting-days 0 ] ] ] end ; **************************** ; **** REFRESH ; **************************** to refresh if Mapped-layer = "Land cover" [ draw-basic-lc ] if Mapped-layer = "Moose distribution index, 2000" [ draw-moose-dist-2000 ] if Mapped-layer = "Accessibility" [ draw-access ] if Mapped-layer = "Rivers" [ draw-river ] if Mapped-layer = "River distance" [ draw-river-dist ] if Mapped-layer = "Path distances" [ draw-path-distance-to-town ] if Mapped-layer = "Flow indices" [ draw-flow-ids ] if Mapped-layer = "Basins" [ draw-basins ] if Mapped-layer = "Moose usage" [ draw-moose-usage ] end ; ****************************** ; **** DRAW-BASIC-LC ; ****************************** to draw-basic-lc ask patches [ ; Check land cover types ... types remain valid? Missing types? if ( lc = 11 ) [ set pcolor blue ] ; Open water if ( lc = 12 ) [ set pcolor grey ] ; Perennial snow or ice if ( lc = 22 ) [ set pcolor red ] ; Developed land, low density if ( lc = 23 ) [ set pcolor red ] ; Developed, medium intensity if ( lc = 31 ) [ set pcolor brown ] ; Barren land if ( lc = 41 ) [ set pcolor lime ] ; Deciduous forest if ( lc = 42 ) [ set pcolor turquoise - 2 ] ; Evergreen forest if ( lc = 43 ) [ set pcolor lime ] ; Mixed forest if ( lc = 51 ) [ set pcolor yellow ] ; Dwarf scrub if ( lc = 52 ) [ set pcolor yellow - 1 ] ; Shrub / Scrub if ( lc = 72 ) [ set pcolor turquoise + 2 ] ; Sedge / Herbaceous if ( lc = 90 ) [ set pcolor violet ] ; Woody wetlands if ( lc = 95 ) [ set pcolor cyan ] ; Emergent herbaceous wetlands ] end ; ****************************** ; **** DRAW-RIVERS ; ****************************** to draw-river ask patches [ ifelse ( river = 1 ) [ set pcolor blue ] ; Open water [ set pcolor black ] ] end ; ****************************** ; **** DRAW-RIVER-DIST ; ****************************** to draw-river-dist let mx max [ riverdist ] of patches ask patches [ ; set pcolor scale-color orange riverdist 0 mx set pcolor ( riverdist / 1000 ) ] end ; ****************************** ; **** DRAW-FLOW-IDS ; ****************************** to draw-flow-ids let mx max [ flow-id ] of patches ask patches [ ; set pcolor scale-color orange flow-id 0 mx set pcolor ( flow-id / 10 ) ] end ; ****************************** ; **** DRAW-PATH-DISTANCE-TO-TOWN ; ****************************** to draw-path-distance-to-town let mx max [ path-distance-to-town ] of patches ask patches [ set pcolor scale-color orange path-distance-to-town 0 mx ; set pcolor ( flow-id / 10 ) ] end ; ****************************** ; **** DRAW-ACCESS ; ****************************** to draw-access let mx max [ access ] of patches ask patches [ set pcolor scale-color lime access 0 mx ] end ; ****************************** ; **** DRAW-BASINS ; ****************************** to draw-basins ask patches [ set pcolor basin * 8 + 1 ] end ; ****************************** ; **** DRAW-MOOSE-USAGE ; ****************************** to draw-moose-usage let m max [ moose-usage ] of patches if m > 0 [ set m log m 10 ask patches [ set pcolor scale-color yellow ( log moose-usage 10 ) 0 m ] ] end ; ****************************** ; **** DRAW-MOOSE-DIST-2000 ; ****************************** to draw-moose-dist-2000 let m max [ Mdist2000 ] of patches if m > 0 [ ask patches [ set pcolor scale-color blue Mdist2000 0 m ] ] end ; ****************************** ; **** INCREMENT-TIMES ; ****************************** to increment-times set day day + 1 set julian julian + 1 if month = 1 and day > 31 ; JANUARY to FEBRUARY [ set month month + 1 set day 1 ] if month = 2 and day > 28 ; FEBRUARY to MARCH ; Ignoring leap years [ set month month + 1 set day 1 ] if month = 3 and day > 31 ; MARCH to APRIL [ set month month + 1 set day 1 ] if month = 4 and day > 30 ; APRIL to MAY [ set month month + 1 set day 1 ] if month = 5 and day > 31 ; MAY to JUNE [ set month month + 1 set day 1 ] if month = 6 and day > 30 ; JUNE to JULY [ set month month + 1 set day 1 ] if month = 7 and day > 31 ; JULY to AUGUST [ set month month + 1 set day 1 ] if month = 8 and day > 31 ; AUGUST to SEPTEMBER [ set month month + 1 set day 1 ] if month = 9 and day > 30 ; SEPTEMBER to OCTOBER [ set month month + 1 set day 1 ] if month = 10 and day > 31 ; OCTOBER to NOVEMBER [ set month month + 1 set day 1 ] if month = 11 and day > 30 ; NOVEMBER to DECEMBER [ set month month + 1 set day 1 ] if month = 12 and day = 31 ; DECEMBER to JANUARY, increment YEAR [ set month 1 set year year + 1 set day 1 set julian 1 ask houses [ set moose-taken-this-year 0 ; NOTE resetting annual takes as well as times ] ] end ; ************************ ; *** GET-PATH-HOME ; ************************ ; Walk a temporary invisible agent down the path from a houses' hunting site back to town, and save the pathway taken. to get-path-home ; Note that this is called from select-moose-hunting-site, with an active house involved in an asking loop let one-patch 0 let c-set 0 type "X Y: " type site-x type " " print site-y ask patch site-x site-y [ sprout-dtemp 1 [ set size 15 set color red set xlist [] ; Create empty lists set ylist [] set id 1 ] ; Get the distance for patches within 25 pixels of the hunting site set c-set patches in-radius 25 with [ flow-id > 0 ] ask c-set [ set temp distance myself ] set one-patch min-one-of c-set [ temp ] ; Find the closest patch that is on the river ; Very occassionally failing, a patch with flow-id is too far away, perhaps, or being placed downriver from the town. If it fails, replace one-patch with a town patch ifelse is-patch? one-patch [ ; Do nothing. Can echo flow-id or what-have-you if helpful. ] [ ; There isn't a patch within N km with flow information. This appears related to Boone's removal of flows nearest to the ocean, which seems reasonable. So, I am going to point the people for these cases toward the town. set one-patch one-of patches with [ lc = 22 ] ] ] display ; If a site is selected that is not right on the water, need to move to the water to have valid flow-id values ask dtemp [ type "FLOW-ID of DTEMP: " print flow-id if flow-id < 0.5 [ while [ flow-id < 0.5 ] [ show xcor show ycor face one-patch forward 0.5 ; Store the location in the list set xlist lput xcor xlist set ylist lput ycor ylist ] ] ] ask dtemp [ while [ flow-id > 1 ] [ ; downhill flow-id ... moves to neighboring zeros and stops, so using replacement for downhill move-to patch-here ;; go to patch center let a-set neighbors with [ flow-id > 0 ] let b-set min-one-of a-set [ flow-id ] face b-set move-to b-set ; Store the location in the list set xlist lput xcor xlist set ylist lput ycor ylist display ] ] ; Copy the list from the temporary agent to the household let l length [ xlist ] of dtemp with [ id = 1 ] let m 0 while [ m < l ] ; Recall lists number starting at 0 [ set x-list item m [ xlist ] of dtemp with [ id = 1 ] set y-list item m [ ylist ] of dtemp with [ id = 1 ] set m m + 1 ] ; type "X-LIST: " print x-list ; type "Y-LIST: " print y-list ask dtemp [ die ] end ; ************************ ; *** GET-PATH-DISTANCE-ONLY ; ************************ ; Walk a temporary invisible agent down the path from a houses' hunting site back to town. Just interested in the final cell count, at this point. to get-path-distance-only let one-patch 0 let c-set 0 ask patch pxcor pycor [ sprout-dtemp 1 [ ; set size 15 ; set color red set xlist [] ; Create empty lists set ylist [] set id 1 ] ; Get the distance for patches within 25 pixels of the hunting site ... NOTE: Using 5 km now, and 333 m cells times 25 cells is more than 8 km, so should be ok. set c-set patches in-radius 25 with [ flow-id > 0 ] ask c-set [ set temp distance myself ] set one-patch min-one-of c-set [ temp ] ; Find the closest patch that is on the river ifelse is-patch? one-patch [ ; Do nothing. Can echo flow-id or what-have-you if helpful. ] [ set one-patch one-of patches with [ lc = 22 ] ] ] ; If a site is selected that is not right on the water, need to move to the water to have valid flow-id values ask dtemp [ ; type "FLOW-ID of DTEMP: " print flow-id if flow-id < 0.5 [ while [ flow-id < 0.5 and patch-here != one-patch ] [ ; type flow-id type " " print "here" face one-patch forward 0.5 ; Store the location in the list set xlist lput xcor xlist set ylist lput ycor ylist ; display ] ] ] ask dtemp [ while [ flow-id > 1 ] [ ; downhill flow-id ... moves to neighboring zeros and stops, so using replacement for downhill move-to patch-here ;; go to patch center let a-set neighbors with [ flow-id > 0 ] let b-set min-one-of a-set [ flow-id ] face b-set move-to b-set ; Store the location in the list set xlist lput xcor xlist ; No need to save Y (or even X, could be a simple scaler, but may as well be X) ; type "X Y: " type xcor type " " print ycor ] set dist-of-interest length xlist ask dtemp [ die ] ] end