-
Notifications
You must be signed in to change notification settings - Fork 0
/
evolution_linearite10-DR.nlogo
4157 lines (3719 loc) · 100 KB
/
evolution_linearite10-DR.nlogo
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
breed [departures departure]
breed [tortoises tortoise]
breed [ndepartures departure]
tortoises-own [
autonomy
departure-patch-name
energy
reluctance
sinuosity-in
sinuosity-out
did-out
angle
most-close-target
last-patch-name
perceptual-range
perceptual-field
status
immigrant
Age
OffspringSize
Fitness
FitnessAbs
]
patches-own [
name
patch-type
]
departures-own [
distance-closest
new?
]
ndepartures-own [distance-closest]
globals [
XDeparturePoints
YDeparturePoints
UDXcor
UDYcor
DistMinPatch
DistMeanPatch
MeanNearestNB
MeanFitnessAtDeath_D
MeanAgeAtDeath_D
MeanOffspringAtDeath_D
TotalFitnessAtDeath_D
TotalAgeAtDeath_D
TotalOffspringAtDeath_D
MeanFitnessAtDeath_R
MeanAgeAtDeath_R
MeanOffspringAtDeath_R
TotalFitnessAtDeath_R
TotalAgeAtDeath_R
TotalOffspringAtDeath_R
ListSize_D
ListSize_R
MaxFitnessAbs
FileMap
DiffFitnessLiss
DiffFitnessList
shannon
even
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup-landscape
clear-all
ask patches [
set pcolor white
set patch-type "matrix"
]
create-departures number-patches [
set color red
set new? FALSE
setxy random-xcor random-ycor
]
;if (check-overfit = TRUE) [
;ask departures [
;set distance-closest distance (min-one-of (departures) [distance self])
;while [distance-closest <= patch--size * 2] [
; setxy random-xcor random-ycor
; set distance-closest distance (min-one-of (departures) [distance self])
; ]
; ]
; ]
if (check-overfit = TRUE) [
ask departures [ create-links-with other departures ]
while [ min [link-length] of links < (( patch--size * 2) + MinimalDist) ] [layout-spring departures links 0.01 (patch--size * 2) REPULSION ]
;while [ min [link-length] of links <= patch--size ] [ layout-spring departures links 0 (patch--size * 2) REPULSION ]
;repeat 100 [ layout-spring departures links 0 (patch--size * 2) REPULSION ] ;
if ShowLinks? = False [ ask links [ hide-link ] ]
]
;set pcolor red
ask departures[
let pname who + 1
ask patches in-radius patch--size
[ set pcolor green
set name pname
set patch-type "habitat"
]
set distance-closest distance (min-one-of (departures) [distance self])
;set most-close-target min-one-of (patches in-cone perceptual-range perceptual-field with [pcolor = green]) [ distance myself ]
set shape "circle"
]
;ask departures [die]
set DistMinPatch (min [link-length] of links - patch--size * 2)
set DistMeanPatch (mean [link-length] of links - patch--size * 2)
set MeanNearestNB ( mean [distance-closest] of departures - patch--size * 2 )
reset-ticks
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to add-a-patch
let howmany 1
if count departures = 0 [set howmany 2] ; Tweak to avoid creating a departure without a patch for the first one (when landscape is empty). Probably optimisable.
create-departures howmany [
set color red
set new? TRUE
setxy random-xcor random-ycor
ask departures [ create-links-with other departures ]
let aap-count 0 ; a counter to avoid an eternal loop when there is no solution to create a new patch
while [ min [link-length] of links < (( patch--size * 2) + MinimalDist) and aap-count < 2000 ] [
setxy random-xcor random-ycor ask departures [ create-links-with other departures ]
set aap-count aap-count + 1 ; a counter to avoid an eternal loop when there is no solution to create a new patch
]
if aap-count >= 2000 [die] ; without this condition you create a patch in the last wrong place that has been evaluated
;ask ndepartures
;[
let pname who + 1
ask patches in-radius patch--size
[ set pcolor green
set name pname
set patch-type "habitat"
]
set distance-closest distance (min-one-of (departures) [distance self])
set shape "circle"
;]
]
set DistMinPatch (min [link-length] of links - patch--size * 2)
set DistMeanPatch (mean [link-length] of links - patch--size * 2)
set MeanNearestNB ( mean [distance-closest] of departures - patch--size * 2 )
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to erase-a-patch
ask one-of departures [
ask patches in-radius patch--size
[ set pcolor white
set name 0
set patch-type "matrix"
]
die
]
ask departures [
create-links-with other departures
set distance-closest distance (min-one-of (departures) [distance self])
]
set DistMinPatch (min [link-length] of links - patch--size * 2)
set DistMeanPatch (mean [link-length] of links - patch--size * 2)
set MeanNearestNB ( mean [distance-closest] of departures - patch--size * 2 )
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to erase-new-patch
ask one-of departures with [ new? = TRUE] [
ask patches in-radius patch--size
[ set pcolor white
set name 0
set patch-type "matrix"
]
die
]
ask departures [
create-links-with other departures
set distance-closest distance (min-one-of (departures) [distance self])
]
set DistMinPatch (min [link-length] of links - patch--size * 2)
set DistMeanPatch (mean [link-length] of links - patch--size * 2)
set MeanNearestNB ( mean [distance-closest] of departures - patch--size * 2 )
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to erase-closest-patch
;ask min-one-of departures [distance-closest] [
;ask patches in-radius patch--size
;[set pcolor pink ]
;]
ask min-one-of links [link-length] [
;show-link
;set label link-length
;set label-color red
ask one-of both-ends [
;set color blue]
ask patches in-radius patch--size
[ set pcolor white
set name 0
set patch-type "matrix"
]
die
]
]
ask departures [
create-links-with other departures
set distance-closest distance (min-one-of (departures) [distance self])
]
set DistMinPatch (min [link-length] of links - patch--size * 2)
set DistMeanPatch (mean [link-length] of links - patch--size * 2)
set MeanNearestNB ( mean [distance-closest] of departures - patch--size * 2 )
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup-tortoises
set ListSize_R 0
set ListSize_D 0
set TotalFitnessAtDeath_R list 0 0
set TotalOffspringAtDeath_R list 0 0
set TotalAgeAtDeath_R list 0 0
set TotalFitnessAtDeath_D list 0 0
set TotalOffspringAtDeath_D list 0 0
set TotalAgeAtDeath_D list 0 0
set MaxFitnessAbs 0
set DiffFitnessList list 0 0
create-tortoises number-tortoises [
move-to one-of departures
;set autonomy random-poisson MeanDist
set departure-patch-name [name] of patch-here
set pen-mode pen-value
set angle 0
ifelse Sinuosity-in-fixed? [set sinuosity-in Sinuosity-in-slider] [set sinuosity-in random 100]
ifelse Sinuosity-out-fixed? [set sinuosity-out Sinuosity-out-slider] [set sinuosity-out random 100]
ifelse Reluctance-fixed? [set reluctance Reluctance-slider] [set reluctance random 100]
ifelse Perception-fixed?
[set perceptual-range perceptual-range-slider
set perceptual-field perceptual-field-slider
]
[
if (LimitPerceptualDistance = 50 ) [ set perceptual-range random 50 ]
if (LimitPerceptualDistance = "Min" ) [ set perceptual-range random DistMinPatch ]
if (LimitPerceptualDistance = "Mean" ) [ set perceptual-range random DistMeanPatch ]
if (LimitPerceptualDistance = "MeanNearestNB" ) [ set perceptual-range random MeanNearestNB ]
;set perceptual-range random DistMinPatch
set perceptual-field random 360
]
set did-out false
set energy 5
set status one-of [ "disperser" "resident" ]
if (status = "disperser") [set color blue]
if (status = "resident") [set color brown]
set Age 1
set immigrant FALSE
set OffspringSize 0
set Fitness 0
set FitnessAbs 0
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to CaptureMouseXY
if (mouse-down? = TRUE) [
set UDXcor round mouse-xcor
set UDYcor round mouse-Ycor
create-departures 1 [
set color red
set new? TRUE
setxy UDXcor UDYCor
;ask departures [ create-links-with other departures ]
;ask ndepartures
;[
let pname who + 1
ask patches in-radius patch--size
[ set pcolor green
set name pname
set patch-type "habitat"
]
set shape "circle"
;]
set distance-closest distance (min-one-of (departures) [distance self])
]
if (count departures > 3) [
ask departures [ create-links-with other departures ]
set DistMinPatch (min (remove 0 ([link-length] of links)) - patch--size * 2)
set DistMeanPatch (mean (remove 0 ([link-length] of links)) - patch--size * 2)
set MeanNearestNB ( mean (remove 0 ([distance-closest] of departures)) - patch--size * 2 )
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to Load-Map
;; (for this model to work with NetLogo's new plotting features,
;; __clear-all-and-reset-ticks should be replaced with clear-all at
;; the beginning of your setup procedure and reset-ticks at the end
;; of the procedure.)
__clear-all-and-reset-ticks
ask patches [
set pcolor white
set patch-type "matrix"
]
file-open UserFileMap ;user-file
repeat file-read [
create-departures 1 [
setxy file-read file-read
set color red
let pname who + 1
ask patches in-radius patch--size
[ set pcolor green
set name pname
set patch-type "habitat"
]
set distance-closest distance (min-one-of (departures) [distance self])
]
]
ask departures [ create-links-with other departures ]
set DistMinPatch (min (remove 0 ([link-length] of links)) - patch--size * 2)
if (count departures >= 2) [
set DistMeanPatch (mean (remove 0 ([link-length] of links)) - patch--size * 2)
;set MeanNearestNB ( mean (remove 0 ([distance-closest] of departures)) - patch--size * 2 )
]
ask links [ hide-link ]
file-close
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
; summarize-landscape
; if (count tortoises with [status = "disperser"] = 0 ) [stop]
; if (count tortoises with [status = "resident"] = 0) [stop]
read-patch-name
move-tortoises
perceive-at-distance
check-death
reproduce
eat-grass
regrow-grass
destroy
if (count tortoises = 0) [stop]
tick
do-plots
erase-pen
calculate-fitness
calculate-mean-fitness
check-maxfitnessabs
do-stats
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;to summarize-landscape
; set DistMinPatch (min [link-length] of links - patch--size * 2)
;end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to calculate-fitness
ask tortoises [
if ( FitnessMeasure = "Multiple") [ set Fitness ( Age * OffspringSize ) ]
if ( FitnessMeasure = "Divide") [ set Fitness ( (OffspringSize) / (Age + 0.0001) ) * 100 ]
if ( FitnessMeasure = "Relative") [
set FitnessAbs ( Age * OffspringSize )
set Fitness ( FitnessAbs / (MaxFitnessAbs + 0.0001 ) ) * 100
]
if ( FitnessMeasure = "Absolute") [ set Fitness OffspringSize ]
if ( FitnessMeasure = "Relative2") [
set FitnessAbs ( OffspringSize )
set Fitness ( FitnessAbs / (MaxFitnessAbs + 0.0001 ) )
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to check-maxfitnessabs
set MaxFitnessAbs max [FitnessAbs] of tortoises
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to read-patch-name
ask tortoises[
if [patch-type] of patch-here = "habitat" [
set last-patch-name [name] of patch-here ; stocke le nom du dernier patch quitt�
]
if (last-patch-name != departure-patch-name) [ set immigrant TRUE ]
;set label-color black
;set label last-patch-name
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to move-tortoises
ask tortoises [
let ProbaSortie random 100
let new-patch-name [name] of patch-at-heading-and-distance angle 1
;;;;;;;;;;;
if (did-out = false) and (new-patch-name != 0) [ ;on est dans l'habitat, on y reste au pixel suivant
set heading angle
forward 1
if pcolor != green [
if (status = "disperser") and (immigrant = TRUE) [set energy energy - DisperserImmigCompetitionCost]
if (status = "disperser") and (immigrant = FALSE) [set energy energy - DisperserHomeCompetitionCost]
if (status = "resident") and (immigrant = TRUE) [set energy energy - ResidentImmigCompetitionCost]
if (status = "resident") and (immigrant = FALSE) [set energy energy - ResidentHomeCompetitionCost]
]
let SeuilAutoCor random 100
if SeuilAutoCor <= sinuosity-in [ set angle random 360 ]
]
;;;;;;;;;;;
if (did-out = false) and (new-patch-name = 0) and (Probasortie <= reluctance) [ ;on est dans l'habitat, pixel suivant mauvais, on choisit de ne pas sortir
set angle (angle - random 180)
if angle < -360 [set angle (angle + 360)]
]
;;;;;;;;;;;
if (did-out = false) and (new-patch-name = 0) and (Probasortie >= reluctance) [ ;on est dans l'habitat, pixel suivant mauvais, on choisit de sortir
set heading angle
set did-out true
forward 1
if pcolor != green [
;set autonomy autonomy - 1
if (status = "disperser") [set energy energy - DisperserMatrixCost ]
if (status = "resident") [set energy energy - ResidentMatrixCost ]
]
let SeuilAutoCor random 100
if SeuilAutoCor <= sinuosity-in [ set angle random 360 ]
]
;;;;;;;;;;;
if (did-out = true) and (new-patch-name = 0) [ ; on est dans la matrice, prochain pixel mauvais
ifelse (Perceptual-Range?) and (most-close-target != nobody) and ([name] of most-close-target != last-patch-name )
;;;;;;----
[ face most-close-target
let SeuilAutoCor random 100
if SeuilAutoCor <= sinuosity-out [ right ((random 180) - 90) ] ;set angle heading + random 90 ]
set angle heading
forward 1
if pcolor != green [
if (status = "disperser") [set energy energy - DisperserMatrixCost ]
if (status = "resident") [set energy energy - ResidentMatrixCost ] ]
]
;;;;;;----
[ set heading angle
forward 1
if pcolor != green [
if (status = "disperser") [set energy energy - DisperserMatrixCost ]
if (status = "resident") [set energy energy - ResidentMatrixCost]
]
let SeuilAutoCor random 100
if SeuilAutoCor <= sinuosity-out [ set angle random 360 ]
]
;;;;;;----
]
;;;;;;;;;;;
if (did-out = true) and (new-patch-name != 0) [ ; on est dans la matrice, prochain pixel bon
set did-out false
set heading angle
forward 1
if pcolor != green [
;set autonomy autonomy - 1
if (status = "disperser") [set energy energy - DisperserMatrixCost ]
if (status = "resident") [set energy energy - ResidentMatrixCost ]
]
]
;right random 360
;forward 1
;if pcolor != green [
;set autonomy autonomy - 1
;set energy energy - 1
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to perceive-at-distance
if ( Perceptual-Range? ) [
ask tortoises [
if (did-out = true) [
;show min-one-of patches with [pcolor = green and distance myself <= distpp] [ distance myself ] ;; --> affiche dans la fen�tre le patch consid�r� par la tortue
;set most-close-target min-one-of patches with [pcolor = green and distance myself <= distpp] [ distance myself ] ; voir aussi la fonction in-radius
set most-close-target min-one-of (patches in-cone perceptual-range perceptual-field with [patch-type = "habitat"]) [ distance myself ]
;set most-close-target one-of (patches in-cone 10 60 with [pcolor = green])
;if (most-close-target != nobody) [ask most-close-target [set pcolor blue]]
]
if (did-out = false) [ set most-close-target nobody ]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to eat-grass
ask tortoises [
if pcolor = green [
set pcolor black
;; the value of energy-from-grass slider is added to energy
if (status = "disperser") and (immigrant = TRUE) [set energy energy + DisperserImmigGainFromFood ]
if (status = "disperser") and (immigrant = FALSE) [set energy energy + DisperserHomeGainFromFood ]
if (status = "resident") and (immigrant = TRUE) [set energy energy + ResidentImmigGainFromFood ]
if (status = "resident") and (immigrant = FALSE) [set energy energy + ResidentHomeGainFromFood ]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to reproduce
ask tortoises [
;if ([name] of patch-here != departure-patch-name) and ([name] of patch-here != 0) and (energy > reproduction-threshold) [ ;; repro dans un nouveau patch uniquement (dispersion obligatoire pour repro)
if ([name] of patch-here != 0) and (energy > reproduction-threshold) [
;if (status = "disperser") [set energy energy - (hatch-energy / Ratio) ]
;if (status = "resident") [set energy energy - (hatch-energy * Ratio) ]
if (status = "disperser") and (immigrant = FALSE) [set energy energy - DisperserHomeHatchEnergy]
if (status = "resident") and (immigrant = FALSE) [set energy energy - ResidentHomeHatchEnergy ]
if (status = "disperser") and (immigrant = TRUE) [set energy energy - DisperserImmigHatchEnergy]
if (status = "resident") and (immigrant = TRUE) [set energy energy - ResidentImmigHatchEnergy ]
hatch 1 [
set Age 0
set OffspringSize 0
set Fitness 0
set FitnessAbs 0
if (status = "disperser") and (immigrant = FALSE) [set energy DisperserHomeHatchEnergy]
if (status = "resident") and (immigrant = FALSE) [set energy ResidentHomeHatchEnergy ]
if (status = "disperser") and (immigrant = TRUE) [set energy DisperserImmigHatchEnergy]
if (status = "resident") and (immigrant = TRUE) [set energy ResidentImmigHatchEnergy ]
set immigrant FALSE
set departure-patch-name [name] of patch-here
if mutations? [
ifelse Reluctance-fixed? [set reluctance Reluctance-slider] [
let Mute1 (random 1000000 / 10000)
if Mute1 <= ReluctanceMutationRate [ set reluctance abs ( reluctance - ( (random 200) - 100) )
if reluctance > 100 [set reluctance reluctance - (reluctance - 100) ]
if reluctance < 0 [set reluctance reluctance + (0 - reluctance) ]
]
]
ifelse Sinuosity-in-fixed? [set sinuosity-in Sinuosity-in-slider] [
let Mute2 (random 1000000 / 10000)
if Mute2 <= S-IN_MutationRate [ set sinuosity-in abs ( sinuosity-in - ( (random 200) - 100) )
if sinuosity-in > 100 [set sinuosity-in sinuosity-in - (sinuosity-in - 100) ]
if sinuosity-in < 0 [set sinuosity-in sinuosity-in + (0 - sinuosity-in) ]
]
]
ifelse Sinuosity-out-fixed? [set sinuosity-out Sinuosity-out-slider] [
let Mute3 (random 1000000 / 10000)
if Mute3 <= S-OUT_MutationRate [ set sinuosity-out abs ( sinuosity-out - ( (random 200) - 100) )
if sinuosity-out > 100 [set sinuosity-out sinuosity-out - (sinuosity-out - 100) ]
if sinuosity-out < 0 [set sinuosity-out sinuosity-out + (0 - sinuosity-out) ]
]
]
ifelse Status-fixed? [ ]
[let Mute4 (random 1000 / 10)
if Mute4 <= StatusMutationRate [ set status one-of [ "disperser" "resident" ]
if (status = "disperser") [set color blue]
if (status = "resident") [set color brown]
]
]
if Perceptual-Range? [
ifelse Perception-fixed? [
set perceptual-range perceptual-range-slider
set perceptual-field perceptual-field-slider ]
[let Mute5 (random 1000000 / 10000)
if Mute5 <= Percept_MutationRate [
if (LimitPerceptualDistance = 50 ) [
set perceptual-range abs ( perceptual-range - ( (random (50 * 2)) - 50) )
if perceptual-range > 50 [set perceptual-range perceptual-range - (perceptual-range - 50) ]
]
if (LimitPerceptualDistance = "Min" ) [
set perceptual-range abs ( perceptual-range - ( (random (DistMinPatch * 2)) - DistMinPatch) )
if perceptual-range > DistMinPatch [set perceptual-range perceptual-range - (perceptual-range - DistMinPatch) ]
]
if (LimitPerceptualDistance = "Mean" ) [
set perceptual-range abs ( perceptual-range - ( (random (DistMeanPatch * 2)) - DistMeanPatch) )
if perceptual-range > DistMeanPatch [set perceptual-range perceptual-range - (perceptual-range - DistMeanPatch) ]
]
if (LimitPerceptualDistance = "MeanNearestNB" ) [
set perceptual-range abs ( perceptual-range - ( (random (MeanNearestNB * 2)) - MeanNearestNB) )
if perceptual-range > MeanNearestNB [set perceptual-range perceptual-range - (perceptual-range - MeanNearestNB) ]
]
;set perceptual-range abs ( perceptual-range - ( (random (DistMinPatch * 2)) - DistMinPatch) )
;if perceptual-range > DistMinPatch [set perceptual-range perceptual-range - (perceptual-range - DistMinPatch) ]
if perceptual-range < 0 [set perceptual-range perceptual-range + (0 - perceptual-range) ]
set perceptual-field abs ( perceptual-field - ( (random 720) - 360) )
if perceptual-field < 0 [set perceptual-field perceptual-field + (0 - perceptual-field) ]
if perceptual-field > 360 [set perceptual-field perceptual-field - (perceptual-field - 360) ]
]
] ]
;set color one-of base-colors
]
set pen-mode pen-value
]
set OffspringSize OffspringSize + 1
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to regrow-grass
ask patches [ ;; 3 out of 100 times, the patch color is set to green
if (name != 0) and (pcolor = black or pcolor = brown) and (random 100 < regrow-rate) [ set pcolor green ]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to destroy
if meteor?[
let ProbaMeteor random 100
if ProbaMeteor <= Frequency [
let destroyed n-of NumberDestroyed [name] of patches
set destroyed remove 0 destroyed
;show destroyed
foreach destroyed [
ask patches with [name = ? ] [set pcolor brown] ; on supprime la ressource (indirect, et repousse vite)
ask patches with [name = ? ] [ask tortoises-here [die] ] ; on supprime les individus
]
]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to erase-pen
ask turtles [
ifelse ([patch-type] of patch-here = "habitat") [ pen-up ] [ set pen-mode pen-value ]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to check-death
ask tortoises with [ status = "disperser"] [
; if autonomy <= 0 [die] ; mort en fonction de la distance de dispersion
set Age Age + 1
if energy <= 0 [
set TotalFitnessAtDeath_D lput Fitness TotalFitnessAtDeath_D
set TotalAgeAtDeath_D lput Age TotalAgeAtDeath_D
set TotalOffspringAtDeath_D lput OffspringSize TotalOffspringAtDeath_D
set ListSize_D ListSize_D + 1
die] ; mort en fonction de l'�nergie disponible
if (AgeLimit? = True) and (Age >= AgeDeath) [
set TotalFitnessAtDeath_D lput Fitness TotalFitnessAtDeath_D
set TotalAgeAtDeath_D lput Age TotalAgeAtDeath_D
set TotalOffspringAtDeath_D lput OffspringSize TotalOffspringAtDeath_D
set ListSize_D ListSize_D + 1
die ]
]
ask tortoises with [ status = "resident"] [
; if autonomy <= 0 [die] ; mort en fonction de la distance de dispersion
set Age Age + 1
if energy <= 0 [
set TotalFitnessAtDeath_R lput Fitness TotalFitnessAtDeath_R
set TotalAgeAtDeath_R lput Age TotalAgeAtDeath_R
set TotalOffspringAtDeath_R lput OffspringSize TotalOffspringAtDeath_R
set ListSize_R ListSize_R + 1
die] ; mort en fonction de l'�nergie disponible
if (AgeLimit? = True) and (Age >= AgeDeath) [
set TotalFitnessAtDeath_R lput Fitness TotalFitnessAtDeath_R
set TotalAgeAtDeath_R lput Age TotalAgeAtDeath_R
set TotalOffspringAtDeath_R lput OffspringSize TotalOffspringAtDeath_R
set ListSize_R ListSize_R + 1
die ]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to calculate-mean-fitness
if (length TotalFitnessAtDeath_D > TimeGap ) [
let depassement (length TotalFitnessAtDeath_D - TimeGap)
repeat depassement [ set TotalFitnessAtDeath_D remove-item 0 TotalFitnessAtDeath_D]
]
if (length TotalAgeAtDeath_D > TimeGap ) [
let depassement (length TotalAgeAtDeath_D - TimeGap)
repeat depassement [ set TotalAgeAtDeath_D remove-item 0 TotalAgeAtDeath_D]
]
if (length TotalOffspringAtDeath_D > TimeGap ) [
let depassement (length TotalOffspringAtDeath_D - TimeGap)
repeat depassement [ set TotalOffspringAtDeath_D remove-item 0 TotalOffspringAtDeath_D]
]
if (length TotalFitnessAtDeath_D != 0) [ set MeanFitnessAtDeath_D mean TotalFitnessAtDeath_D ]
if (length TotalAgeAtDeath_D != 0) [ set MeanAgeAtDeath_D mean TotalAgeAtDeath_D ]
if (length TotalOffspringAtDeath_D != 0) [ set MeanOffspringAtDeath_D mean TotalOffspringAtDeath_D ]
if (length TotalFitnessAtDeath_R > TimeGap ) [
let depassement (length TotalFitnessAtDeath_R - TimeGap)
repeat depassement [ set TotalFitnessAtDeath_R remove-item 0 TotalFitnessAtDeath_R]
]
if (length TotalAgeAtDeath_R > TimeGap ) [
let depassement (length TotalAgeAtDeath_R - TimeGap)
repeat depassement [ set TotalAgeAtDeath_R remove-item 0 TotalAgeAtDeath_R]
]
if (length TotalOffspringAtDeath_R > TimeGap ) [
let depassement (length TotalOffspringAtDeath_R - TimeGap)
repeat depassement [ set TotalOffspringAtDeath_R remove-item 0 TotalOffspringAtDeath_R]
]
if (length TotalFitnessAtDeath_R != 0) [ set MeanFitnessAtDeath_R mean TotalFitnessAtDeath_R ]
if (length TotalAgeAtDeath_R != 0) [ set MeanAgeAtDeath_R mean TotalAgeAtDeath_R ]
if (length TotalOffspringAtDeath_R != 0) [ set MeanOffspringAtDeath_R mean TotalOffspringAtDeath_R ]
let DF MeanFitnessAtDeath_R - MeanFitnessAtDeath_D
set DiffFitnessList lput DF DiffFitnessList
if (length DiffFitnessList > 400 ) [
let depassement (length DiffFitnessList - 400)
repeat depassement [ set DiffFitnessList remove-item 0 DiffFitnessList]
]
set DiffFitnessLiss mean DiffFitnessList
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;to-report mean-reluctance
; set mn-rlc ( mean reluctance of tortoises
; if (count tortoises = 0) [stop]
; report pctg-disp
;end
to do-plots
set-current-plot "Population" ;; which plot we want to use next
;set-current-plot-pen "tortoises" ;; which pen we want to use next
;plot count tortoises ;; what will be plotted by the current pen
;set-current-plot-pen "grass" ;; which pen we want to use next
;plot count patches with [pcolor = green] ;; what will be plotted by the current pen
set-current-plot-pen "dispersers"
plot count tortoises with [status = "disperser"]
set-current-plot-pen "residents"
plot count tortoises with [status = "resident"]
set-current-plot "Reluctance to emigrate"
set-current-plot-pen "Mean of dispersers"
ifelse (count tortoises with [status = "disperser"] != 0) [plot mean [reluctance] of tortoises with [status = "disperser"]] [plot 0]
;set-current-plot-pen "Min of dispersers"
;ifelse (count tortoises with [status = "disperser"] != 0) [plot min [reluctance] of tortoises with [status = "disperser"]] [plot 0]
;set-current-plot-pen "Max of dispersers"
;ifelse (count tortoises with [status = "disperser"] != 0) [plot max [reluctance] of tortoises with [status = "disperser"]] [plot 0]
set-current-plot-pen "Mean of residents"
ifelse (count tortoises with [status = "resident"] != 0) [plot mean [reluctance] of tortoises with [status = "resident"]] [plot 0]
;set-current-plot-pen "Min of residents"
;ifelse (count tortoises with [status = "resident"] != 0) [plot min [reluctance] of tortoises with [status = "resident"]] [plot 0]
;set-current-plot-pen "Max of residents"
;ifelse (count tortoises with [status = "resident"] != 0) [plot max [reluctance] of tortoises with [status = "resident"]] [plot 0]
set-current-plot "Sinuosity"
;set-current-plot-pen "Sinuosity IN"
;plot mean [sinuosity-in] of tortoises
;set-current-plot-pen "Sinuosity OUT"
;plot mean [sinuosity-out] of tortoises
set-current-plot-pen "Sinu. IN D"
ifelse (count tortoises with [status = "disperser"] != 0) [plot mean [sinuosity-in] of tortoises with [status = "disperser"]] [plot 0]
set-current-plot-pen "Sinu. OUT D"
ifelse (count tortoises with [status = "disperser"] != 0) [plot mean [sinuosity-out] of tortoises with [status = "disperser"]] [plot 0]
set-current-plot-pen "Sinu. IN R"
ifelse (count tortoises with [status = "resident"] != 0) [plot mean [sinuosity-in] of tortoises with [status = "resident"]] [plot 0]
set-current-plot-pen "Sinu. OUT R"
ifelse (count tortoises with [status = "resident"] != 0) [plot mean [sinuosity-out] of tortoises with [status = "resident"]] [plot 0]
set-current-plot "Perceptual distance"
set-current-plot-pen "Dispersers"
ifelse (count tortoises with [status = "disperser"] != 0) [plot mean [perceptual-range] of tortoises with [status = "disperser"] ] [plot 0]
set-current-plot-pen "Residents"
ifelse (count tortoises with [status = "resident"] != 0) [plot mean [perceptual-range] of tortoises with [status = "resident"] ] [plot 0]
set-current-plot "Perceptual field"
set-current-plot-pen "Dispersers"
ifelse (count tortoises with [status = "disperser"] != 0) [plot mean [perceptual-field] of tortoises with [status = "disperser"] ] [plot 0]
set-current-plot-pen "Residents"
ifelse (count tortoises with [status = "resident"] != 0) [plot mean [perceptual-field] of tortoises with [status = "resident"] ] [plot 0]
set-current-plot "Fitness"
set-current-plot-pen "Dispersers"
ifelse (count tortoises with [status = "disperser"] != 0) [plot MeanFitnessAtDeath_D ] [plot 0]
set-current-plot-pen "Residents"
ifelse (count tortoises with [status = "resident"] != 0) [plot MeanFitnessAtDeath_R ] [plot 0]
set-current-plot "DiffFitness"
set-current-plot-pen "Fitness R- Fitness D"
plot ((MeanFitnessAtDeath_R - MeanFitnessAtDeath_D) / 1.1 )
set-current-plot-pen "Zero Line"
plot 0
set-current-plot-pen "Smoothed DiffFitness"
plot DiffFitnessLiss
; set-current-plot "Dispersal Distance"
; set-current-plot-pen "Distance"
; plot mean [autonomy] of tortoises
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;