extensions [ gis ] globals [ HSI-map day year generation total-distance ] patches-own [ HSI visits cardinal-region patch-status exit score patch-max patch-min ] turtles-own [ age status yearly-distance daily-distance-travelled target-patch contacts home-region hr hd dispersed dispersal-distance path candidates ] to setup clear-all reset-ticks random-seed 777 set year 1 set day 1 set generation 1 ; World size maxpxcor: 508 maxpycor: 314, cell size: 100 x 100 --> 50.8 km x 41.4 km set HSI-map gis:load-dataset "C:/Users/.../HSI_Klagenfurt.asc" gis:set-world-envelope gis:envelope-of HSI-map let w gis:width-of hsi-map let h gis:height-of hsi-map resize-world 0 (w - 1) 0 (h - 1) gis:paint HSI-map 0 gis:apply-raster HSI-map HSI ask patches[ if is-number? HSI [ set patch-status "inside"] if patch-status != "inside"[ set patch-status "border" ] if patch-status = "border"[ set pcolor white set HSI 0] ] end to put-one crt 1 [ setxy x-coordinate y-coordinate set age 0 set color colour pen-down] end ;Procedures ;Go to go set day day + 1 if day mod 365 = 0 [ set year year + 1 set day 1 ask turtles [ set age age + 1 set total-distance total-distance + yearly-distance set yearly-distance 0 if home-range? [set hr patches in-radius home-range] ]] move emigrate if year > max-years[ print (word "Simulation terminated after " max-years " years") print (word "Generations: " (generation / n)) print (word "Potential exit patches: " count patches with [patch-status = "potential exit"]) let mean-distance ((( total-distance ) / year ) / n ) print (word "Mean yearly distance: " mean-distance) export-patch-visits "C:/.../.csv" stop ] ;End of go tick end ;Submodels to emigrate ask turtles[ if [patch-status] of patch-here = "border" [ set patch-status "potential exit" while [[patch-status] of patch-here = "border" or [patch-status] of patch-here = "potential exit" ] [ let center-x ( max-pxcor / 2 ) let center-y ( max-pycor / 2 ) facexy center-x center-y set color turquoise + random-float 0.5 ;calculate-scores uphill HSI ]]] end to move ;Homeranger ask turtles [ while [ daily-distance-travelled < max-daily-distance] [ set candidates patches in-radius perceptual-range if home-range? [set candidates hr with [ distance myself <= perceptual-range ]] ask candidates [set score HSI] if site-fidelity? [ ask candidates [ set score (HSI - ( 0.1 * distance myself)) if score < 0 [set score 0]]] let score-sum sum [score] of candidates let target-list sort-on [ score ] candidates let patch-max-old 0.0 foreach target-list [ p -> let h [score] of p ask p [ set patch-min patch-max-old set patch-max (patch-max-old + h) ] set patch-max-old (patch-max-old + h) ] let x random-float score-sum set target-patch one-of (candidates with [ (x > patch-min) and (x <= patch-max) ]) if target-patch = nobody [ uphill HSI stop] while [patch-here != target-patch] [ let temp-targets patches in-radius 1.5 face target-patch if directional-movement? [ ask temp-targets[ set score 0] ask temp-targets in-cone 1.5 180 [set score 0.75 * HSI] ask temp-targets in-cone 1.5 90 [set score HSI] ] set score-sum sum [score] of temp-targets let temp-target-list sort-on [score] temp-targets set patch-max-old 0.0 foreach temp-target-list [ p -> let s [score] of p ask p [ set patch-min patch-max-old set patch-max (patch-max-old + s) ] set patch-max-old (patch-max-old + s) ] set x random-float score-sum let temp-target one-of (temp-targets with [ (x > patch-min) and (x <= patch-max) ]) let last-patch patch-here move-to temp-target if record-path?[set path lput temp-target path] set daily-distance-travelled daily-distance-travelled + distance last-patch set visits visits + 1 ]] if daily-distance-travelled >= max-daily-distance [ set yearly-distance yearly-distance + daily-distance-travelled set daily-distance-travelled 0 stop] ] end