-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHenri's ABM Code.txt
405 lines (371 loc) · 8.86 KB
/
Henri's ABM Code.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
;TO DOWNLOAD FULL CODE, HERE IS THE LINK:
;https://drive.google.com/drive/u/1/folders/0B5sN6_snmjHqaFItdzhNMDNRY2M
__includes [
"Modules/KDEs.nls"
"Modules/insect.nls"
"Modules/elevation.nls"
"Modules/vegetation-rank.nls"
"Modules/precipitation.nls"
"Modules/caribou-test.nls"
"Modules/NDVI.nls"
"Modules/hunters.nls"
]
;EXTENSIONS
extensions [
gis
array
matrix
table
]
;GLOBALS
globals [
;datasets
elevation-dataset
ndvi-dataset
vegetation-class-dataset
precipitation-dataset
kde-elevation-dataset
kde-insect-dataset
kde-NDVI-dataset
kde-precipitation-dataset
kde-vegrank-dataset
;lists
insect-kde-data-list
NDVI-kde-data-list
precipitation-kde-data-list
vegrank-kde-data-list
vegetation-ndvi-list
precipitation-data-list
vegetation-CP-list
vegetation-CNP-list
vegetation-PC-list
vegetation-MH-list
vegetation-ML-list
vegetation-OH-list
vegetation-OL-list
vegetation-LS-list
mosquito-means-list
oestrid-means-list
mosquito-sigma-list
oestrid-sigma-list
;maximums
ndvi-max
precipitation-max
elevation-max
mosquito-sigma
oestrid-sigma
visit-max
elev-max-k
elev-min-k
insect-max-k
insect-min-k
ndvi-max-k
ndvi-min-k
prec-max-k
prec-min-k
vegrank-max-k
vegrank-min-k
mosquito-max
oestrid-max
;coloring variables
mosquito-max-color
oestrid-max-color
mosquito-max-tenth-color
oestrid-max-tenth-color
mosquito-max-tenth
oestrid-max-tenth
mosquito-mean
oestrid-mean
;world
day
;FCM
global-fcm-matrix
global-fcm-internal
global-fcm-motor
]
;PATCHES
patches-own [
elevation
ndvi-quality
vegetation-type
vegetation-beta
precipitation-amt
veg-paint
elev-paint
prec-paint
mosquito-density
oestrid-density
coast
water
ocean
river
elevation-scale
patch-max-avg-elevation
patch-min-avg-elevation
elevation-avg
gray-scale
mosquito-scale
oestrid-scale
distance-to-coast
visitation
visit-scale
kde-elevation-estimate
kde-insect-estimate
kde-NDVI-estimate
kde-precipitation-estimate
kde-vegrank-estimate
]
;HUNTERS
breed [ hunters hunter ]
breed [ caribou a-caribou ]
hunters-own [
;concepts
prey-close ;from 0:3/5 of hunter vision, activator of hunting
prey-far ;from 2/5:5/5 of hunter vision, activator of exploring
stalking ;level of internal concept
curiousity ;level of internal concept
hunt ;hunting function
explore ;exploring function
;FCM
hunter-fcm-matrix
hunter-fcm-internal
hunter-fcm-motor
hunter-fcm-sensory
hunter-fcm-raw-internal
hunter-fcm-act-internal
;data
prey
distance-to-prey
hunter-energy
home-patch
catch-probability
prey-caught
sensory-close
sensory-far
]
to setup
reset-ticks
kill-caribou
kill-hunters
ask patches [ set pcolor green ]
ask patch 0 0 [ set pcolor black ]
kill-caribou
new-caribou
new-hunters
ask hunters [ set home-patch ( patch 0 0 )]
end
;SETUP-OLD
to setup-old
clear-all
;set insect-season 0
load-elevation-gis
set-ndvi-data-list
;set-precipitation-data-list
;set-insect-indices
;set-mosquito-activity
;set-oestrid-activity
setup-patches
load-veg-classification-gis
set-vegetation-rank-lists
set-vegetation-selection-season
;set-coastline
new-population
reset-ticks
end
to go
tick
go-caribou
ask hunters
[
ifelse ( hunter-energy > 0 )
[
ifelse (prey-caught = false)
[
hunt-funct
explore-funct
set hunter-energy (hunter-energy - 1)
]
[return-home]
]
[ return-home ]
]
end
;SETUP PATHCES
to setup-patches
setup-insect
;ask patches with [water = false]
;[
; set-elevation-scale
; set-densities
;]
;ask patches
;[ set-gray-scale ]
;repeat 2 [diffuse-test]
ask patches with [ water = true ] [ set pcolor blue ]
end
;GO PATCHES
to go-patches
ask patches with [water = false]
[ set-densities ]
repeat 2 [diffuse-test]
end
to set-FCM
set global-fcm-matrix matrix:from-row-list [[ 0 0 1 -1 0 0 ]
[ 0 0 -1 1 0 0 ]
[ 0 0 0 0 1 0 ]
[ 0 0 0 0 0 1 ]
[ 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 ]]
set global-fcm-internal matrix:submatrix global-fcm-matrix 0 2 2 4
set global-fcm-motor matrix:submatrix global-fcm-matrix 2 4 4 6
end
to set-hunter-FCMs
ask hunters
[
set hunter-fcm-matrix global-fcm-matrix
set hunter-fcm-internal global-fcm-internal
set hunter-fcm-motor global-fcm-motor
]
end
to go-hunters
ifelse ( ticks mod 2 = 0 )
[ random-walk ]
[ straight-walk ]
end
to go-caribou
ask caribou
[
ifelse ( ticks mod 2 = 0 )
[ random-walk ]
[ straight-walk ]
]
end
to-report ternary-funct [ low high sense]
if ( sense < low )
[ report 0 ]
if ( sense > high )
[ report high ]
if ( sense >= low and sense <= high )
[ report (( sense - low ) / ( high - sense )) ]
end
to-report logistic-funct [ x ]
report ( 1 / ( 1 + e ^ ( -1 * x )))
end
;MAKE NEW CARIBOU POPULATION
to new-caribou
reset-ticks
create-caribou caribou-population
[
set color white; - 2 + random 5 ;; random shades look nice
set size 1.25 ;; easier to see
let done false
let x 0
let y 0
while [done != true]
[
set x random-xcor
set y random-ycor
ask patch-at x y
[
if (patch x y != nobody)
[
set done true
]
]
]
setxy x y
]
end
to new-hunters
create-hunters hunter-population
[
set color blue; - 2 + random 5 ;; random shades look nice
set size 1.75 ;; easier to see
set hunter-energy 1000
set prey-caught false
let done false
let x 0
let y 0
while [done != true]
[
set x random-xcor
set y random-ycor
ask patch-at x y
[
if (patch x y != nobody)
[
set done true
]
]
]
setxy x y
]
end
to kill-caribou
ask caribou [ die ]
end
to kill-hunters
ask hunters [ die ]
end
;REST
to rest
rt random-float 360
end
;RANDOM WALK
to random-walk
rt random-float 360
let done false
if (patch-ahead 1 != nobody)
[
set done true
]
ifelse done = true
[fd 1]
[random-walk]
end
;STRAIGHT WALK
to straight-walk
let right-turn 0
let left-turn 0
set right-turn random-float 5
set left-turn random-float 5
make-turn right-turn left-turn
let done false
if (patch-ahead 1 != nobody)
[
set done true
]
ifelse done = true
[fd 1]
[straight-walk]
end
;MAKE TURN
; turn right or left based on the larger turn angle
to make-turn [rturn lturn] ; turtle procedure
;et turn (rturn - lturn)
ifelse rturn > lturn
[ rt rturn ]
[ lt lturn ]
end
to hunt-funct
set prey one-of caribou in-radius hunter-vision
if prey != nobody
[
set heading towards prey
set catch-probability ( random-float 1 )
if catch-probability >= 0.5
[ ask prey [ die ]
set prey-caught true
]
fd 1
]
end
to explore-funct
go-hunters
;set hunter-energy (hunter-energy - 1)
end
to return-home
set heading towards home-patch
fd 1
if ( patch-here = home-patch and hunter-energy = 0 ) [ die ]
end