/
stimulavanie-regulovanie-chovu-prasnic.nlogo
1977 lines (1781 loc) · 41 KB
/
stimulavanie-regulovanie-chovu-prasnic.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
; CODE START ;
extensions [array]
globals [building-x building-y water-x water-y-min food-x food-y-max mud-x-max mud-y-min
COUNTER NIGHT CHILDREN_MALES CHILDREN_FEMALES MALES FEMALES DAY-TICKS DAYS DEATHS CRUSHED
SOLD_MALES SOLD_FEMALES SOLD_CHILDREN_FEMALES SOLD_CHILDREN_MALES MONEY MONEY_SWITCH_MALES MONEY_ESTRUS_STIMULATION PREGNANCY_PROBABILITY BORN]
; agents
breed [people person]
people-own [pace headx heady move goalx goaly]
breed [pigs pig]
pigs-own [pace
headx heady
move reverse-move standing sleep
goalx goaly achieved
age male
death
old-color
pregnant pregnancy-duration
estrus estrus-duration estrus-cycle estrus-probability
wean wean-duration
wean-estrus-pause bad-fertility
mother
sexual-maturity sexual-puberty sexual-admission maturity
no-sex-days
]
undirected-link-breed [pregnancies pregnancy]
undirected-link-breed [children child]
to go
; 5 years simulation horizon
if COUNTER <= 912999 [
;DAY/NIGHT has 500 ticks
if COUNTER mod DAY-TICKS = 0 [
update-plots
set DAYS DAYS + 1
set NIGHT not NIGHT
setup-farm
if NIGHT = false [
wake-up-pigs
]
]
;EVERY DAY
if COUNTER mod (DAY-TICKS * 2) = 0 [
wean-pigs
set-pigs-older
pigs-death
]
;EVERY 2/3 DAY
if COUNTER mod (DAY-TICKS + (DAY-TICKS / 2)) = 0 [
set-pigs-pregnant
get-pigs-childbirth
sell-pigs
]
;EVERY MONTH
if COUNTER mod (DAY-TICKS * 2 * 31) = 0 [
sell-pigs
buy-food
if SWITCH_MALES [
switch-male-pigs
]
]
if SWITCH_MALES [
if COUNTER mod (DAY-TICKS * 2 * SWITCH_DAYS) = 0 [
switch-male-pigs
]
]
if random-boolean and random-boolean [
animate-water
]
set COUNTER COUNTER + 1
make-step
crush-pigs
]
end
to make-step
ask pigs[
change-pig-color-in-building who
grow-up-pig who
if sleep = false [
if standing > 10 and achieved = false [
set reverse-move reverse-move + 1
]
ifelse achieved [
ifelse standing < 10 [
set standing standing + 1
] ;standing a while when goal spo achieved
[
set standing 0
ifelse NIGHT or (pregnant = true and pregnancy-duration <= 2) [
pig-goal-building who
] [
random-pig-goal who
]
set achieved false
] ;else
] ;ifelse achieved
[ ;else
ifelse reverse-move > 0 [
;reverse when blocked by other agents
ifelse(reverse-move <= 3)[
set reverse-move reverse-move + 1
jump (-1 * pace)
] ;ifelse ifelse(reverse-move < 3)
[
set reverse-move 0
set standing 0
] ;else
] ;ifelse reverse-move > 0
[ ;else
facexy goalx goaly
let moved false;
ifelse(patch-ahead pace != nobody) and ;je v smere vobec nieco (dlazdica)?
((not any? turtles-on patch-ahead pace) or ;nikto z mnoziny vsetkych agentov nie je pred nim vo vzdialenosti
((count turtles-on patch-ahead pace = 1) and;ak je na dlazdici len jeden agent, som to asi ja
(one-of turtles-on patch-ahead pace = self)) ;overim ci to teda nie som ja
)[
set moved true;
jump pace ;poskocenie
] [ ;else
let angle 45
if random-boolean [
set angle 65
]
ifelse(patch-right-and-ahead angle pace != nobody) and ;je v smere vobec nieco (dlazdica)?
((not any? turtles-on patch-right-and-ahead angle pace) or ;nikto z mnoziny vsetkych agentov nie je pred nim vo vzdialenosti
((count turtles-on patch-right-and-ahead angle pace = 1) and;ak je na dlazdici len jeden agent, som to asi ja
(one-of turtles-on patch-right-and-ahead angle pace = self)) ;overim ci to teda nie som ja
)[
set moved true;
right angle
jump pace ;poskocenie
] [ ;else
set angle 45
if random-boolean [
set angle 65
]
if(patch-left-and-ahead angle pace != nobody) and ;je v smere vobec nieco (dlazdica)?
((not any? turtles-on patch-left-and-ahead angle pace) or ;nikto z mnoziny vsetkych agentov nie je pred nim vo vzdialenosti
((count turtles-on patch-left-and-ahead angle pace = 1) and;ak je na dlazdici len jeden agent, som to asi ja
(one-of turtles-on patch-left-and-ahead angle pace = self)) ;overim ci to teda nie som ja
)[
set moved true;
left angle
jump pace ;poskocenie
]
]
]
ifelse moved = true [
let x round pxcor
let y round pycor
;achieved goal destination
if (x < (goalx + 3)) and (x > (goalx - 3))
and
(y < (goaly + 3)) and (y > (goaly - 3))
[
set achieved true
set standing standing + 1
;inside building at night
if (pxcor <= (building-x - 1)) and (pycor <= (building-y - 1)) and NIGHT [
set sleep true
]
]
][;else moved
set standing standing + 1
]
] ;else reverse-move > 0
] ;else achieved
] ;if sleep = false
]
end
to buy-food
let babies-count count pigs with [age <= 50]
let price-for-babies count-price-for-food babies-count 1 20 15
let children-count count pigs with [age > 50 and age <= 90]
let price-for-children count-price-for-food children-count 1.5 20 15
let pregnant-count count pigs with [pregnant = true]
let price-for-pregnant count-price-for-food pregnant-count 3 20 18
let maturity-count count pigs with [pregnant = false and maturity = true]
let price-for-maturity count-price-for-food maturity-count 3 20 17
set MONEY (MONEY - price-for-babies - price-for-children - price-for-pregnant - price-for-maturity)
end
to-report count-price-for-food [amount-of-pigs kilo-for-pig weight-of-package price-for-package]
if amount-of-pigs = 0 [
report 0
]
let kilos (amount-of-pigs * kilo-for-pig)
let packages (kilos / weight-of-package) + 1
report packages * price-for-package
end
to switch-male-pigs
let estrus-females count pigs with [estrus-cycle > 0 and estrus-duration <= 2 ]
let bad-male-pigs count pigs with [male = true and maturity = true and no-sex-days > 6]
let good-male-pigs count pigs with [male = true and maturity = true and no-sex-days <= 1]
if estrus-females > 0 [
if good-male-pigs < estrus-females [
let max-pigs round random-normal 2 0.3
print "max pigs"
print max-pigs
let pig-counter 0
ask pigs with [male = true and maturity = true and no-sex-days > 6][
if pig-counter <= max-pigs [
set no-sex-days 0
set MONEY MONEY - 30
set MONEY_SWITCH_MALES MONEY_SWITCH_MALES + 30
]
]
]
]
end
to sell-pigs
let sell-children-males false
if CHILDREN_MALES > 12 and CHILDREN_FEMALES > 8 and count pigs with [pregnant = true] >= 1[
set sell-children-males true
]
if sell-children-males = true [
let potencional count pigs with [male = true and maturity = false and age >= sexual-puberty]
while [potencional > 0 and potencional <= 4] [
sell-young-male-in-puberty-pig
set potencional count pigs with [male = true and maturity = false and age >= sexual-puberty]
]
]
set sell-children-males false
if (CHILDREN_MALES + CHILDREN_FEMALES) > 50 and CHILDREN_MALES > (CHILDREN_FEMALES / 2) and count pigs with [pregnant = true] >= 1[
set sell-children-males true
]
if sell-children-males = true [
let potencional count pigs with [male = true and maturity = false]
while [potencional > 6] [
sell-young-male-pig
set potencional count pigs with [male = true and maturity = false]
]
]
if FEMALES > 8 and count pigs with [pregnant = true] >= 6 [
let potencional count pigs with [male = false and pregnant = false and maturity = true]
while [potencional > 0] [
sell-female-pig
set potencional count pigs with [male = false and pregnant = false and maturity = true]
]
]
while [CHILDREN_FEMALES > 18 and count pigs with [pregnant = true] >= 1] [
sell-young-female-pig
]
while [MALES > FEMALES / 2] [
sell-male-pig
]
end
to sell-young-male-in-puberty-pig
let min-age 999999999999999
let id -1
ask pigs with [male = true and maturity = false and age >= sexual-puberty] [
if age < min-age [
set min-age age
set id who
]
]
if id > -1 [
ask pig id [
ask my-children [
die
]
set CHILDREN_MALES CHILDREN_MALES - 1
set SOLD_CHILDREN_MALES SOLD_CHILDREN_MALES + 1
set MONEY (MONEY + get-sell-price age)
die
]
]
end
to sell-male-pig
let max-age -1
let id -1
ask pigs with [male = true and maturity = true] [
if age > max-age [
set max-age age
set id who
]
]
if id > -1 [
ask pig id [
set MALES MALES - 1
set SOLD_MALES SOLD_MALES + 1
set MONEY (MONEY + get-sell-price age)
die
]
]
end
to sell-young-male-pig
let min-age 999999999999999
let id -1
ask pigs with [male = true and maturity = false] [
if age < min-age [
set min-age age
set id who
]
]
if id > -1 [
ask pig id [
ask my-children [
die
]
set CHILDREN_MALES CHILDREN_MALES - 1
set SOLD_CHILDREN_MALES SOLD_CHILDREN_MALES + 1
set MONEY (MONEY + get-sell-price age)
die
]
]
end
to sell-young-female-pig
let min-age 999999999999999
let id -1
ask pigs with [male = false and size = 2] [
if age < min-age [
set min-age age
set id who
]
]
if id > -1 [
ask pig id [
ask my-children [
die
]
set CHILDREN_FEMALES CHILDREN_FEMALES - 1
set SOLD_CHILDREN_FEMALES SOLD_CHILDREN_FEMALES + 1
set MONEY (MONEY + get-sell-price age)
die
]
]
end
to sell-female-pig
let max-age -1
let id -1
ask pigs with [male = false and pregnant = false and maturity = true] [
if age > max-age [
set max-age age
set id who
]
]
if id > -1 [
if any? turtles with [mother = id] [
ask pigs with [mother = id][
set mother -1
]
]
ask pig id [
set FEMALES FEMALES - 1
set SOLD_FEMALES SOLD_FEMALES + 1
set MONEY (MONEY + get-sell-price age)
die
]
]
end
to-report get-sell-price [pig-age]
if pig-age <= 124 [
report 1 * random-normal 35 3
]
if pig-age > 124 and pig-age <= 155 [
report 1.2 * random-normal 60 3
]
if pig-age > 155 and pig-age <= 217 [
report 1.5 * random-normal 90 3
]
if pig-age > 217 and pig-age <= 240 [
report 1.75 * random-normal 90 3
]
if pig-age > 240 and pig-age <= 730 [
report 2 * random-normal 160 5
]
if pig-age > 730 [
report 3 * random-normal 260 9
]
end
to crush-pigs
ask pigs [
let pig-size size
let pig-male male
ask patch-here [
if count turtles-on neighbors >= 8 and pig-size = 2 [
ask myself [
die
]
set DEATHS DEATHS + 1
set CRUSHED CRUSHED + 1
ifelse pig-male [
set CHILDREN_MALES CHILDREN_MALES - 1
][
set CHILDREN_FEMALES CHILDREN_FEMALES - 1
]
]
if count turtles-on neighbors >= 9 and pig-size = 3 [
ask myself [
die
]
set DEATHS DEATHS + 1
set CRUSHED CRUSHED + 1
ifelse pig-male [
set CHILDREN_MALES CHILDREN_MALES - 1
][
set CHILDREN_FEMALES CHILDREN_FEMALES - 1
]
]
]
]
end
to setup
clear-all ;global reset
setup-plots
set COUNTER 0
set DEATHS 0
set CRUSHED 0
set MONEY 1000
set MONEY_SWITCH_MALES 0
set MONEY_ESTRUS_STIMULATION 0
set SOLD_MALES 0
set SOLD_FEMALES 0
set SOLD_CHILDREN_FEMALES 0
set SOLD_CHILDREN_MALES 0
set NIGHT true
set DAY-TICKS 500
set building-x 60
set building-y 15
set water-x 74
set water-y-min 14
set food-x 74
set food-y-max 15
set mud-x-max 36
set mud-y-min 18
setup-farm
setup-pigs
end
to setup-farm
ask patches [
ifelse NIGHT [set pcolor green - 4][set pcolor green - 3]
let x pxcor ; x = Patches.thisPatchXcor
let y pycor
setup-building x y
setup-water x y
setup-mud x y
setup-food x y
]
end
to animate-water
ask patches [
let x pxcor
let y pycor
setup-water x y
]
end
to setup-building [x y]
if ((x > -1) and (x < building-x) and (y > -1) and (y < building-y))
[
set pcolor brown + 3
]
if ((x > -1) and (x < building-x) and (y > 1) and (y < 13))
[
set pcolor brown + 2
]
if ((x > -1) and (x < building-x) and (y > 4) and (y < 10))
[
set pcolor brown + 1
]
if ((x > -1) and (x < building-x) and (y > 6) and (y < 8))
[
set pcolor black + 3
]
end
to setup-water [x y]
if ((x > water-x) and (x < 81) and (y > water-y-min) and (y < 34))[
ifelse random-boolean [
ifelse NIGHT [set pcolor blue - 1][set pcolor blue + 1]
][
ifelse NIGHT [set pcolor blue - 2][set pcolor blue + 2]
]
]
end
to setup-food [x y]
if ((x > food-x) and (x < 81) and (y > -1) and (y < 15))
[
ifelse random-boolean [
ifelse NIGHT [set pcolor yellow - 2][set pcolor yellow + 2]
][
ifelse NIGHT [set pcolor yellow - 3][set pcolor yellow + 3]
]
]
end
to setup-mud [x y]
if ((x > -2) and (x < mud-x-max) and (y > 20) and (y < 34))
[
ifelse NIGHT [set pcolor brown - 4][set pcolor brown - 2]
]
if ((x > 32) and (x < mud-x-max) and (y > 20) and (y < 34))
or
(((x > -2) and (x < mud-x-max) and (y > mud-y-min) and (y < 22)))
[
ifelse NIGHT [set pcolor brown - 3][set pcolor brown - 1]
]
end
;Create pigs. Order of creation is important. Females needs to be first, because they can be mother of chilren.
to setup-pigs
set FEMALES INIT_FEMALES
create-pigs INIT_FEMALES [
set color pink - 1
set old-color color
let x random-pxcor mod (building-x - 1)
let y random-pycor mod (building-y - 1)
setxy x y
set size 4
set pace random-normal 0.8 0.2
set move true
set standing 0
set achieved false
set sleep false
set male false
set death false
set age (1460 + (add-random-in-range 1460 2920))
set maturity true
set estrus-cycle get-new-estrus-cycle-number maturity
set estrus-duration 0
set estrus false
set wean false
set wean-duration 0
set bad-fertility 0
set sexual-maturity get-new-sexual-maturity-number
set sexual-puberty round sexual-maturity / 1.75
set sexual-admission get-new-sexual-admission-number
set pregnancy-duration get-new-pregnancy-duration-number
set pregnant false
set no-sex-days 0
set estrus-probability 100
random-pig-goal who
]
set CHILDREN_MALES INIT_CHILDREN_MALES
create-pigs INIT_CHILDREN_MALES [
set color pink
set old-color color
let x random-pxcor mod (building-x - 1)
let y random-pycor mod (building-y - 1)
setxy x y
set size 2
set pace random-normal 0.8 0.2
set move true
set standing 0
set achieved false
set sleep false
set male true
set death false
set maturity false
set estrus-cycle 0
set estrus-duration 0
set estrus false
set wean false
set wean-duration 0
set pregnant false
set sexual-maturity get-new-sexual-maturity-number
set sexual-puberty round sexual-maturity / 1.75
set age random-poisson 30
if age >= sexual-puberty [
set size 3
]
set sexual-admission get-new-sexual-admission-number
set mother random INIT_FEMALES
set no-sex-days 0
random-pig-goal who
]
set CHILDREN_FEMALES INIT_CHILDREN_FEMALES
create-pigs INIT_CHILDREN_FEMALES [
set color pink + 1
set old-color color
let x random-pxcor mod (building-x - 1)
let y random-pycor mod (building-y - 1)
setxy x y
set size 2
set pace random-normal 0.8 0.2
set move true
set standing 0
set achieved false
set sleep false
set male false
set death false
set maturity false
set estrus-cycle get-new-estrus-cycle-number maturity
set estrus-duration 0
set estrus false
set pregnant false
set wean false
set wean-duration 0
set bad-fertility 0
set sexual-maturity get-new-sexual-maturity-number
set sexual-puberty round sexual-maturity / 1.75
set age random-poisson 30
if age >= sexual-puberty [
set size 3
]
set sexual-admission get-new-sexual-admission-number
set mother random INIT_FEMALES
set pregnancy-duration get-new-pregnancy-duration-number
set pregnant false
set no-sex-days 0
set estrus-probability 100
random-pig-goal who
]
set MALES INIT_MALES
create-pigs INIT_MALES [
set color pink - 2
set old-color color
let x random-pxcor mod (building-x - 1)
let y random-pycor mod (building-y - 1)
setxy x y
set size 4
set pace random-normal 0.8 0.2
set move true
set standing 0
set achieved false
set sleep false
set male true
set death false
set maturity true
set age (1460 + (add-random-in-range 1460 2920))
set estrus-cycle 0
set estrus-duration 0
set estrus false
set pregnant false
set wean false
set wean-duration 0
set sexual-maturity get-new-sexual-maturity-number
set sexual-puberty round sexual-maturity / 1.75
set sexual-admission get-new-sexual-admission-number
set no-sex-days 0
random-pig-goal who
]
end
to random-pig-goal [id]
ask pig id [
ifelse age < 7 [
pig-goal-building who
][
ifelse age < sexual-puberty and mother > -1 and random-boolean = true [
let x 0
let y 0
ifelse any? turtles with [who = mother][
ask pig mother [
set x goalx
set y goaly
]
set goalx x
set goaly y
][
pig-goal-random who
]
][
let number random 55;
ifelse random-boolean [
pig-goal-random who
][
ifelse number mod 2 = 0 [
pig-goal-mud who
][
ifelse number mod 3 = 0 [
pig-goal-food who
][
pig-goal-water who
] ;else number mod 3 = 0
] ;else number mod 2 = 0
] ;else random-boolean
]; else age < 120
] ;else age < 30
]
end
to change-pig-color-in-building [id]
ask pig id [
ifelse (pxcor <= (building-x - 1)) and (pycor <= (building-y - 1))[
ifelse NIGHT [
set color old-color
]
[
set color pink - 4
]
]
[
ifelse NIGHT [
set color pink - 4
][
set color old-color
]
]
]
end
to set-pigs-pregnant
ask pigs with [maturity = true and male = false and estrus = true and pregnant = false] [
if MALES > 0 [
let sex false;
let success false;
let minus-probability (bad-fertility / 0.75)
if any? pigs with [maturity = true and male = true and no-sex-days > 3] [
ask one-of pigs with [maturity = true and male = true and no-sex-days > 3] [
let probability (70 + random 30)
set probability (probability - minus-probability)
if no-sex-days > 6 [
set probability (probability - (no-sex-days * 1.5))
]
set PREGNANCY_PROBABILITY probability
update-plots
ifelse random 100 <= probability [
set success true
set sex true
create-pregnancy-with myself
set no-sex-days 0
ask my-pregnancies [
set color yellow
]
][
set no-sex-days 0
set sex true
]
]
if sex = true [
set no-sex-days 0
]
if success = true [
set pregnant true
]
]
]
]
end
to pigs-death
ask pigs [
if death [
ifelse age >= 220 [
ifelse male = true [
set MALES MALES - 1
][
set FEMALES FEMALES - 1
]
][
ifelse male = true [
set CHILDREN_MALES CHILDREN_MALES - 1
][
set CHILDREN_FEMALES CHILDREN_FEMALES - 1
]
]
set DEATHS DEATHS + 1
ask my-pregnancies [ die ]
]
if ( age / 365 ) > 15 [
ifelse ( age / 365 ) > 20[
if random 25 = 1 [
set death true
]
][
if random 80 = 1 [
set death true
]
]
]
]
end
to grow-up-pig [id]
ask pig id [
if maturity = false [
;get bigger
if sexual-puberty <= age [
set size 3
]
;get mature
if sexual-maturity <= age [
set maturity true
set size 4
ifelse male = true [
set color pink - 2
set old-color color
set MALES MALES + 1
set CHILDREN_MALES CHILDREN_MALES - 1
][
set color pink - 1
set old-color color
set FEMALES FEMALES + 1
set CHILDREN_FEMALES CHILDREN_FEMALES - 1
]
]
]
]
end
to wake-up-pigs
ask pigs [
set sleep false
]
end
to wean-pigs
ask pigs with [wean = true][
if wean-duration >= WEAN-TIME [
ask my-children [
die
]
set wean false
set wean-duration 0
if WEAN-TIME = 21 [
set bad-fertility bad-fertility + 1
set wean-estrus-pause random-normal 10 0.3
ifelse ESTRUS_STIMULATION [
set estrus-probability (100 - random 10)
set MONEY_ESTRUS_STIMULATION MONEY_ESTRUS_STIMULATION + 50
][
set estrus-probability random-normal 30 5
]
]
if WEAN-TIME = 28 [
set wean-estrus-pause random-normal 6 0.5
ifelse ESTRUS_STIMULATION [
set estrus-probability (100 - random 5)
set MONEY_ESTRUS_STIMULATION MONEY_ESTRUS_STIMULATION + 50
][
set estrus-probability random-normal 50 5
]
]
if WEAN-TIME = 35 [
set wean-estrus-pause random-normal 5 0.3
set estrus-probability (100 - random 10)
]
if WEAN-TIME = 42 [
set wean-estrus-pause random-normal 4 0.3
set estrus-probability (100 - random 5)
]
]
]
end
;Pigs gets older. Count estrus duration for maturity females and no-sex days fro maturity males.
to set-pigs-older
ask pigs [
set age age + 1
]
ask pigs with [male = false and maturity = true][
if estrus-cycle > 0 [ ;has estrus cycle
if estrus-duration > 0 [
;estrus starts between 4,5 - 5,5 days after sex cycle started
ifelse estrus-duration >= 4 and estrus-duration <= 6 [
if random 100 <= estrus-probability [
set estrus true
]
][
set estrus false
]
] ;if estrus-duration > 0
ifelse estrus-duration > estrus-cycle [
;renew estrus cycle
set estrus-duration 0
set estrus-cycle get-new-estrus-cycle-number maturity
][
ifelse wean = true [
set wean-duration wean-duration + 1
][
set estrus-duration estrus-duration + 1
]
]
]
if pregnant = true [
set pregnancy-duration (pregnancy-duration - 1)
]
]
ask pigs with [maturity = true][
set no-sex-days no-sex-days + 1
]
end
to get-pigs-childbirth
ask pigs with [pregnant = true and pregnancy-duration = 0] [
let mother-id who
set estrus-cycle get-new-estrus-cycle-number maturity
set estrus-duration 0
set estrus false
set pregnant false
set pregnancy-duration get-new-pregnancy-duration-number
set wean true
set no-sex-days 0
ask my-pregnancies [ die ]
let number-of-newborn round random-normal 12 1
hatch number-of-newborn [
ifelse random-boolean [
set color pink + 1
set old-color color
set male false
set estrus-cycle get-new-estrus-cycle-number maturity
set pregnancy-duration get-new-pregnancy-duration-number
set CHILDREN_FEMALES CHILDREN_FEMALES + 1
][
set color pink
set old-color color
set male true
set estrus-cycle 0
set CHILDREN_MALES CHILDREN_MALES + 1
]
let x random-pxcor mod (building-x - 1)
let y random-pycor mod (building-y - 1)
setxy x y
set size 2
set pace random-normal 0.8 0.2
set move true
set standing 0
set achieved false
set sleep false
set maturity false
set age 0
set pregnant false
set estrus-duration 0
set estrus false
set wean false
set wean-duration 0
set death false
set no-sex-days 0
set mother mother-id
set sexual-maturity get-new-sexual-maturity-number
set sexual-puberty round sexual-maturity / 1.75
set sexual-admission get-new-sexual-admission-number
set BORN BORN + 1
create-child-with myself