/
covid19-ibirama.nlogo
2196 lines (1957 loc) · 57.9 KB
/
covid19-ibirama.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
;World extent for running: max-pxcor=1435 / max-pycor=2143
;FDS: Lucas, please fill with the values you use to run the simulation on your computer -> World extent for debuging/testing: max-pxcor=717 /max-pycor=1071
extensions [ gis csv ]
globals [
roads-dataset
escolas-ceis-dataset
escolas-fundamental1-dataset
escolas-fundamental2-dataset
escolas-medio-dataset
escolas-universidades-dataset
escolas-cejas-dataset
empresas-dataset
pracas-parques-dataset
NUMBER_HOUSES
NUMBER_CIVILIANS
NUMBER_WORKERS
NUMBER_STUDENTS
NUMBER_PERIODS_OF_DAY ; 4 = morning, afternoon, evening, night
STUDENTS_LIMIT
population_pyramid_labels
population_pyramid_values
families_size
families_number
education-labels
education-values
mortality_labels
mortality_values
init med fin ;; Variables to control the turns logic flow
elapsed-days ;FDS magic variables?
dead
; constants
LOCATION_COMPANY
LOCATION_EDUCATION_INFANTIL
LOCATION_EDUCATION_FUNDAMENTAL1
LOCATION_EDUCATION_FUNDAMENTAL2
LOCATION_EDUCATION_MEDIO
LOCATION_EDUCATION_CEJA
LOCATION_EDUCATION_UNIVERSIDADE
LOCATION_PARK
CIVILIAN_EDUCATION_INFANTIL
CIVILIAN_EDUCATION_FUNDAMENTAL1
CIVILIAN_EDUCATION_FUNDAMENTAL2
CIVILIAN_EDUCATION_MEDIO
CIVILIAN_EDUCATION_CEJA
CIVILIAN_EDUCATION_UNIVERSIDADE
CIVILIAN_NAO_ESTUDANTE
]
breed [ road-labels road-label ]
breed [ ponto-de-interesse-labels ponto-de-interesse-label ]
breed [ houses house]
breed [ civilians civilian]
breed [ locations location ]
civilians-own[
homes work school park
age types worker
period-of-day ;; Variable to control at which turn the agent should move ( 0 = Matutino, 1 = Vespertino, 2 = Noturno )
state days-in-state current-days
contamined?
testar stay-home
how_many_i_infected
mortality-rate
already-spread
currentPlaceName
currentPlace
anteriorPlace
contLocal
]
houses-own[
family_members
]
locations-own [
location_type
location_label
location_capacity
]
to setup
; show "setup is running, please wait..."
clear-all
; initializing the constants
set NUMBER_HOUSES 5515
set NUMBER_CIVILIANS 17330
set NUMBER_WORKERS 2462
set NUMBER_STUDENTS 4230
set STUDENTS_LIMIT 0
set NUMBER_PERIODS_OF_DAY 4 ;morning, afternoon, evening, night
set CIVILIAN_EDUCATION_INFANTIL "EI"
set CIVILIAN_EDUCATION_FUNDAMENTAL1 "EF1"
set CIVILIAN_EDUCATION_FUNDAMENTAL2 "EF2"
set CIVILIAN_EDUCATION_MEDIO "EM"
set CIVILIAN_EDUCATION_CEJA "CEJA"
set CIVILIAN_EDUCATION_UNIVERSIDADE "UNI"
set CIVILIAN_NAO_ESTUDANTE "NE"
set LOCATION_COMPANY "COMP"
set LOCATION_EDUCATION_INFANTIL "EI"
set LOCATION_EDUCATION_FUNDAMENTAL1 "EF1"
set LOCATION_EDUCATION_FUNDAMENTAL2 "EF2"
set LOCATION_EDUCATION_MEDIO "EM"
set LOCATION_EDUCATION_CEJA "CEJA"
set LOCATION_EDUCATION_UNIVERSIDADE "UNI"
set LOCATION_PARK "PARK"
set init "mat" ;; Stands for matutino (morning)
set med "vesp" ;; Stands for vespertino (afternoon)
set fin "not" ;; Stands for noturno (evening)
set elapsed-days 3
set dead 0
initialize-population-pyramid
initialize-families-data
initialize-education-data
initialize-mortality-data
gis:load-coordinate-system (word "shapes/ruas/ruas-e-rodovias-ibirama-osm.prj")
; roads dataset
set roads-dataset gis:load-dataset "shapes/ruas/ruas-e-rodovias-ibirama-osm.shp"
; education datasets
set escolas-ceis-dataset gis:load-dataset "shapes/educacao/ibirama-educacao-infantil.shp"
set escolas-fundamental1-dataset gis:load-dataset "shapes/educacao/ibirama-educacao-fundamental1.shp"
set escolas-fundamental2-dataset gis:load-dataset "shapes/educacao/ibirama-educacao-fundamental2.shp"
set escolas-medio-dataset gis:load-dataset "shapes/educacao/ibirama-educacao-medio.shp"
set escolas-universidades-dataset gis:load-dataset "shapes/educacao/ibirama-educacao-universidades.shp"
set escolas-cejas-dataset gis:load-dataset "shapes/educacao/ibirama-educacao-jovens-adultos.shp"
; companies
set empresas-dataset gis:load-dataset "shapes/empresas/ibirama-empresas-todas.shp"
; parks and squares
set pracas-parques-dataset gis:load-dataset "shapes/pracas-parques/ibirama-pracas-parques.shp"
gis:set-world-envelope-ds gis:envelope-of roads-dataset
;gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of roads-dataset) (gis:envelope-of escolas-diurnas-dataset) (gis:envelope-of escolas-noturnas-dataset) (gis:envelope-of hospitais-clinicas-dataset) (gis:envelope-of igrejas-dataset) (gis:envelope-of mercados-dataset) (gis:envelope-of pracas-parques-dataset))
import-drawing "images/ibirama-ruas-google-satellite-transp50.png"
display-roads
create-ibirama-companies
create-ibirama-schools
create-ibirama-parks-and-squares
; creation of houses and agents
create-ibirama-houses
create-ibirama-civilians
assign-civilians-workplace
assign-civilians-school
agents-turns
infect-people
isolar
if label-points-of-interest [
ask locations [ set label location_label]
]
reset-ticks
; show "setup is done!"
end
to display-education
display-pontos-interesse escolas-ceis-dataset yellow
display-pontos-interesse escolas-fundamental1-dataset yellow
display-pontos-interesse escolas-fundamental2-dataset yellow
display-pontos-interesse escolas-medio-dataset yellow
display-pontos-interesse escolas-universidades-dataset yellow
display-pontos-interesse escolas-cejas-dataset yellow
end
to display-companies
display-pontos-interesse empresas-dataset magenta
end
to display-parks-and-squares
display-pontos-interesse pracas-parques-dataset lime
end
to initialize-families-data
set families_size [
1
2
3
4
5
6
7
8
9
10
11
]
set families_number [
617
1457
1467
1094
530
213
81
34
8
7
7
]
end
to initialize-population-pyramid
set population_pyramid_labels [
0
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
30
35
40
45
50
55
60
65
70
75
80
90
100
] ;Olhar as faixas etárias na planilha
set population_pyramid_values [
235
221
235
247
246
230
263
236
266
265
280
290
270
286
306
306
297
282
289
270
308
296
297
313
331
1527
1276
1337
1229
1194
1003
834
609
516
392
270
243
35
0
]
end
to initialize-education-data
set education-labels[
"EI" ; Educação Infantil
"EF1" ; Ensino Fundamental 1
"EF2" ; Ensino Fundamental 2
"EM" ; Ensino Médio
"CEJA"; Ensino de Jovens e Adultos
"UNI" ; Universidades
]
set education-values[
449
1567
1078
465
480
448
]
end
to initialize-mortality-data
set mortality_labels []
set mortality_values []
let mortality_data csv:from-file mortality-rates-file
foreach mortality_data [ mortality ->
set mortality_labels lput (item 0 mortality) mortality_labels
set mortality_values lput (item 1 mortality) mortality_values
]
end
to create-ibirama-companies
foreach gis:feature-list-of empresas-dataset [ feature ->
foreach gis:vertex-lists-of feature [ vertex ->
let coordinates gis:location-of item 0 vertex
create-locations 1 [
setxy (item 0 coordinates) (item 1 coordinates)
set shape "triangle"
set color magenta
set size 1
set location_type LOCATION_COMPANY
set location_label gis:property-value feature "NAME"
]
]
]
; read the CSV file and initialize the number of employees for each company
let companies locations with [location_type = LOCATION_COMPANY]
; show (word "created companies: " count companies )
let companies_data csv:from-file "data/empresas/ibirama-empresas-estimativa-funcionarios.csv"
foreach companies_data [ company ->
ask one-of companies with [ location_label = item 0 company and location_capacity = 0] [
;ask locations with [ location_label = item 0 company and location_capacity = 0] [
if location_capacity > 0 [ error "ja tem" ]
set location_capacity item 1 company
]
]
;show "Companies created!"
end
to create-ibirama-schools
foreach gis:feature-list-of escolas-ceis-dataset [ feature ->
foreach gis:vertex-lists-of feature [ vertex ->
let coordinates gis:location-of item 0 vertex
create-locations 1 [
setxy (item 0 coordinates) (item 1 coordinates)
set shape "star"
set color yellow
set size 1
set location_type LOCATION_EDUCATION_INFANTIL
set location_label gis:property-value feature "NAME"
]
]
]
foreach gis:feature-list-of escolas-fundamental1-dataset [ feature ->
foreach gis:vertex-lists-of feature [ vertex ->
let coordinates gis:location-of item 0 vertex
create-locations 1 [
setxy (item 0 coordinates) (item 1 coordinates)
set shape "star"
set color yellow
set size 1
set location_type LOCATION_EDUCATION_FUNDAMENTAL1
set location_label gis:property-value feature "NAME"
]
]
]
foreach gis:feature-list-of escolas-fundamental2-dataset [ feature ->
foreach gis:vertex-lists-of feature [ vertex ->
let coordinates gis:location-of item 0 vertex
create-locations 1 [
setxy (item 0 coordinates) (item 1 coordinates)
set shape "star"
set color yellow
set size 1
set location_type LOCATION_EDUCATION_FUNDAMENTAL2
set location_label gis:property-value feature "NAME"
]
]
]
foreach gis:feature-list-of escolas-medio-dataset [ feature ->
foreach gis:vertex-lists-of feature [ vertex ->
let coordinates gis:location-of item 0 vertex
create-locations 1 [
setxy (item 0 coordinates) (item 1 coordinates)
set shape "star"
set color yellow
set size 1
set location_type LOCATION_EDUCATION_MEDIO
set location_label gis:property-value feature "NAME"
]
]
]
foreach gis:feature-list-of escolas-cejas-dataset [ feature ->
foreach gis:vertex-lists-of feature [ vertex ->
let coordinates gis:location-of item 0 vertex
create-locations 1 [
setxy (item 0 coordinates) (item 1 coordinates)
set shape "star"
set color yellow
set size 1
set location_type LOCATION_EDUCATION_CEJA
set location_label gis:property-value feature "NAME"
]
]
]
foreach gis:feature-list-of escolas-universidades-dataset [ feature ->
foreach gis:vertex-lists-of feature [ vertex ->
let coordinates gis:location-of item 0 vertex
create-locations 1 [
setxy (item 0 coordinates) (item 1 coordinates)
set shape "star"
set color yellow
set size 1
set location_type LOCATION_EDUCATION_UNIVERSIDADE
set location_label gis:property-value feature "NAME"
]
]
]
; show "Schools created!"
end
to create-ibirama-parks-and-squares
foreach gis:feature-list-of pracas-parques-dataset [ feature ->
foreach gis:vertex-lists-of feature [ vertex ->
let coordinates gis:location-of item 0 vertex
create-locations 1 [
setxy (item 0 coordinates) (item 1 coordinates)
set shape "tree"
set color green
set size 1
set location_type LOCATION_PARK
set location_label gis:property-value feature "NAME"
]
]
]
; show "Parks created!"
end
to create-ibirama-civilians
let i 0;
while [ i < (length families_number - 1)][
let families item i families_number; families with more than 10 people are created later
let members item i families_size
;show (word "creating " families " families with " members " members ")
ask n-of families houses with [ family_members = 0 ] [
let me who
set family_members members
;; create civilians for the family
repeat members [
ask patch-here [
ifelse any? civilians-here with [age >= 16] [
sprout-civilians 1 [
set shape "person"
set homes house me
set types CIVILIAN_NAO_ESTUDANTE
set state 1
set period-of-day 0
set current-days 0
set testar 0
set worker false
set contamined? false
set stay-home false
set already-spread false
let x random 39
while [ item x population_pyramid_values = 0 ][
set x random 39
]
set age item x population_pyramid_labels
let nro item x population_pyramid_values
set nro nro - 1
set population_pyramid_values replace-item x population_pyramid_values nro
]
][
sprout-civilians 1 [
set shape "person"
set homes house me
set types CIVILIAN_NAO_ESTUDANTE
set state 1
set period-of-day 0
set current-days 0
set testar 0
set worker false
set contamined? false
set stay-home false
set already-spread false
let x 16 + random 23
while [ item x population_pyramid_values = 0 ][
set x 16 + random 23
]
set age item x population_pyramid_labels
let nro item x population_pyramid_values
set nro nro - 1
set population_pyramid_values replace-item x population_pyramid_values nro
]
]
]
]
]
set i i + 1
]
; creating families with more than 10 people
; first, we create N families with 11 civilians each
let families item ((length families_number) - 1) families_number
let members item ((length families_size) - 1) families_size
; show (word "creating " families " families with " members " members ")
ask n-of families houses with [ family_members = 0 ][
let me who
set family_members members
repeat members [
ask patch-here [
sprout-civilians 1 [
set shape "person"
set homes house me
set types CIVILIAN_NAO_ESTUDANTE
set state 1
set period-of-day 0
set current-days 0
set testar 0
set worker false
set contamined? false
set stay-home false
set already-spread false
let x random 39
while [ item x population_pyramid_values = 0 ][
set x random 39
]
set age item x population_pyramid_labels
let nro item x population_pyramid_values
set nro nro - 1
set population_pyramid_values replace-item x population_pyramid_values nro
]
]
]
]
; then, we add more civilians to these families, until NUMBER_CIVILIANS is reached
; show (word "adding " (NUMBER_CIVILIANS - count civilians) " more members to families with more than 10 members")
repeat NUMBER_CIVILIANS - count civilians [
ask one-of houses with [ family_members > 10 ][
let me who
set family_members family_members + 1
ask patch-here [
sprout-civilians 1 [
set shape "person"
set homes house me
set types CIVILIAN_NAO_ESTUDANTE
set state 1
set period-of-day 0
set current-days 0
set testar 0
set worker false
set contamined? false
set stay-home false
set already-spread false
let x random 39
while [ item x population_pyramid_values = 0 ][ set x random 39 ]
set age item x population_pyramid_labels
let nro item x population_pyramid_values
set nro nro - 1
set population_pyramid_values replace-item x population_pyramid_values nro
]
]
]
]
; show "done create-ibirama-civilians"
end
to assign-civilians-school
while [STUDENTS_LIMIT < NUMBER_STUDENTS] [
ask one-of civilians with [types = CIVILIAN_NAO_ESTUDANTE] [
( ifelse
age <= 5 [
set types CIVILIAN_EDUCATION_INFANTIL
let y position types education-labels
ifelse item y education-values <= 0 [ set types CIVILIAN_NAO_ESTUDANTE ] ; NE = Nao estudante, se for trabalhador pode sair de casa, caso contrario deve ficar
[let tmp item y education-values
set tmp tmp - 1
set education-values replace-item y education-values tmp
set school one-of locations with [ location_type = LOCATION_EDUCATION_INFANTIL ]
set STUDENTS_LIMIT STUDENTS_LIMIT + 1
]
]
age >= 6 and age <= 10 [
set types CIVILIAN_EDUCATION_FUNDAMENTAL1
let y position types education-labels
ifelse item y education-values <= 0 [ set types CIVILIAN_NAO_ESTUDANTE ] ; NE = Nao estudante, se for trabalhador pode sair de casa, caso contrario deve ficar
[let tmp item y education-values
set tmp tmp - 1
set education-values replace-item y education-values tmp
set school one-of locations with [ location_type = LOCATION_EDUCATION_FUNDAMENTAL1 ]
set STUDENTS_LIMIT STUDENTS_LIMIT + 1
]
]
age >= 11 and age <= 14 [
set types CIVILIAN_EDUCATION_FUNDAMENTAL2
let y position types education-labels
ifelse item y education-values <= 0 [ set types CIVILIAN_NAO_ESTUDANTE ] ; NE = Nao estudante, se for trabalhador pode sair de casa, caso contrario deve ficar
[let tmp item y education-values
set tmp tmp - 1
set education-values replace-item y education-values tmp
set school one-of locations with [ location_type = LOCATION_EDUCATION_FUNDAMENTAL2 ]
set STUDENTS_LIMIT STUDENTS_LIMIT + 1
]
]
age >= 15 [
let k position CIVILIAN_EDUCATION_CEJA education-labels
ifelse item k education-values <= 0 [
if age >= 15 and age <= 17 [
set types CIVILIAN_EDUCATION_MEDIO
let y position types education-labels
ifelse item y education-values <= 0 [ set types CIVILIAN_NAO_ESTUDANTE ] ; NE = Nao estudante, se for trabalhador pode sair de casa, caso contrario deve ficar
[let tmp item y education-values
set tmp tmp - 1
set education-values replace-item y education-values tmp
set school one-of locations with [ location_type = LOCATION_EDUCATION_MEDIO ]
set STUDENTS_LIMIT STUDENTS_LIMIT + 1
]
]
][
set types CIVILIAN_EDUCATION_CEJA
let y position types education-labels
let tmp item y education-values
set tmp tmp - 1
set education-values replace-item y education-values tmp
set school one-of locations with [ location_type = LOCATION_EDUCATION_CEJA ]
set STUDENTS_LIMIT STUDENTS_LIMIT + 1
]
])
if age >= 18 and types != CIVILIAN_EDUCATION_CEJA [
set types CIVILIAN_EDUCATION_UNIVERSIDADE
set period-of-day 2
let y position types education-labels
ifelse item y education-values <= 0 [ set types CIVILIAN_NAO_ESTUDANTE ] ; NE = Nao estudante, se for trabalhador pode sair de casa, caso contrario deve ficar
[let tmp item y education-values
set tmp tmp - 1
set education-values replace-item y education-values tmp
set school one-of locations with [ location_type = LOCATION_EDUCATION_UNIVERSIDADE ]
set STUDENTS_LIMIT STUDENTS_LIMIT + 1
]
]
]
]
; show (word "Educação Infantil: " count civilians with [ types = CIVILIAN_EDUCATION_INFANTIL] " alunos")
; show (word "Ensino Fundamental 1: " count civilians with [ types = CIVILIAN_EDUCATION_FUNDAMENTAL1] " alunos")
; show (word "Ensino Fundamental 2: " count civilians with [ types = CIVILIAN_EDUCATION_FUNDAMENTAL2] " alunos")
; show (word "Ensino Médio: " count civilians with [ types = CIVILIAN_EDUCATION_MEDIO] " alunos")
; show (word "CEJA: " count civilians with [ types = CIVILIAN_EDUCATION_CEJA] " alunos")
; show (word "Universidade: " count civilians with [ types = CIVILIAN_EDUCATION_UNIVERSIDADE] " alunos")
end
to assign-civilians-workplace
ask n-of NUMBER_WORKERS civilians with [ age >= 10 ] [
set worker true
set work one-of locations with [ location_type = LOCATION_COMPANY and location_capacity > 0 ]
ask work [set location_capacity location_capacity - 1 ]
]
end
to infect-people
; show (word "infecting " infected-students" students...")
ask n-of infected-students civilians with [ types != CIVILIAN_NAO_ESTUDANTE and not worker][ ; just students
set state 2
let b (max-exposed - min-exposed) + 1
set days-in-state min-exposed + random b
]
; show "infection of students is done"
; show (word "infecting " infected-workers" workers...")
ask n-of infected-workers civilians with [ worker = true and types = CIVILIAN_NAO_ESTUDANTE] [ ; just workers
set state 2
let b (max-exposed - min-exposed) + 1
set days-in-state min-exposed + random b
]
; show "infection of workers is done"
; show (word "infecting " infected-workers" workers that are also students...")
ask n-of infected-workers-that-study civilians with [ worker = true and types != CIVILIAN_NAO_ESTUDANTE ] [ ; workers that study
set state 2
let b (max-exposed - min-exposed) + 1
set days-in-state min-exposed + random b
]
; show "infection of workers that are also students is done"
; show (word "infecting " infected-workers" non-students and unemployed people...")
ask n-of infected-nonstudents-unemployed civilians with [ worker = false and types = CIVILIAN_NAO_ESTUDANTE] [
set state 2
let b (max-exposed - min-exposed) + 1
set days-in-state min-exposed + random b
]
; show "infection of non-students and unemployed people is done"
end
to create-ibirama-houses
display-roads-in-patches ; first we need to identify the patches that are roads
ask n-of NUMBER_HOUSES patches with [pcolor = cyan and count neighbors with [pcolor != cyan] > 0] [
; create a home in a neighbor patch that is not a road (whose color is not cyan)
ask n-of 1 neighbors with [ pcolor != cyan] [
sprout-houses 1 [
set shape "house"
set family_members 0
]
]
]
ask patches [ set pcolor black ]
; show "done create-ibirama-houses"
end
to display-roads
ask road-labels [ die ]
gis:set-drawing-color blue
gis:draw roads-dataset 1
if label-roads
[
label-dataset roads-dataset
]
end
;to display-pontos-interesse
; ask ponto-de-interesse-labels [ die ]
; gis:set-drawing-color yellow
; gis:draw escolas-diurnas-dataset 1
; if label-roads
; [
; label-dataset escolas-diurnas-dataset
; ]
;end
to display-pontos-interesse [the-dataset the-color]
gis:set-drawing-color the-color
gis:draw the-dataset 1
if label-points-of-interest
[
label-dataset the-dataset
]
end
to label-dataset [the-dataset]
foreach gis:feature-list-of the-dataset [ vector-feature ->
let centroid gis:location-of gis:centroid-of vector-feature
; centroid will be an empty list if it lies outside the bounds
; of the current NetLogo world, as defined by our current GIS
; coordinate transformation
if not empty? centroid
[ create-road-labels 1
[ set xcor item 0 centroid
set ycor item 1 centroid
set size 0
set label gis:property-value vector-feature "NAME"
set hidden? false
]
]
]
end
; Using gis:intersecting to find the set of patches that intersects
; a given vector feature (in this case, a road).
to display-roads-in-patches
ask patches [ set pcolor black ]
ask patches gis:intersecting roads-dataset
[ set pcolor cyan ]
end
; This is an example of how to select a subset of a raster dataset
; whose size and shape matches the dimensions of the NetLogo world.
; It doesn't actually draw anything; it just modifies the coordinate
; transformation to line up patch boundaries with raster cell
; boundaries. You need to call one of the other commands after calling
; this one to see its effect.
to match-cells-to-patches
gis:set-world-envelope gis:raster-world-envelope roads-dataset 0 0
clear-drawing
clear-turtles
end
to agents-turns
let cont count civilians with [ types = CIVILIAN_EDUCATION_FUNDAMENTAL1 ]
set cont cont / 2
ask n-of cont civilians with [ types = CIVILIAN_EDUCATION_FUNDAMENTAL1 ] [
set period-of-day 1
]
set cont count civilians with [ types = CIVILIAN_EDUCATION_FUNDAMENTAL2 ]
set cont cont / 2
ask n-of cont civilians with [ types = CIVILIAN_EDUCATION_FUNDAMENTAL2 ] [
set period-of-day 1
]
set cont count civilians with [ types = CIVILIAN_EDUCATION_MEDIO ]
set cont cont / 3
ask n-of cont civilians with [ types = CIVILIAN_EDUCATION_MEDIO ] [
set period-of-day 1
]
ask n-of cont civilians with [ types = CIVILIAN_EDUCATION_MEDIO and period-of-day != 1 ] [
set period-of-day 2
]
set cont count civilians with [ types = CIVILIAN_EDUCATION_CEJA ]
set cont cont / 3
ask n-of cont civilians with [ types = CIVILIAN_EDUCATION_CEJA ] [
set period-of-day 1
]
ask n-of cont civilians with [ types = CIVILIAN_EDUCATION_CEJA and period-of-day != 1 ] [
set period-of-day 2
]
end
to turns
if ticks != elapsed-days [
;Show "---------------------------------------------------"
; show word "Turno atual que se passou é: " init
let aux init
set init med
set med fin
set fin aux
; show word "Próximo turno será: " init
]
if ticks >= elapsed-days [
set elapsed-days elapsed-days + 4
; show "madrugada!"
]
;; Resembles something like a bubbleSort for a simple logic to be used
end
to go
move
human-state
turns
show ticks
ask civilians with [stay-home = false ] [
if (xcor = item 0 currentPlace) and (ycor = item 1 currentPlace) [
set contLocal contLocal + 1
if worker = true or types != CIVILIAN_NAO_ESTUDANTE [
ifelse worker = true and types != CIVILIAN_NAO_ESTUDANTE and period-of-day = 2 [
ifelse ( [xcor] of work != [xcor] of school ) and ( [ycor] of work != [ycor] of school ) [
if contLocal >= 3 [ show "Agente se movendo errado!" ]
][ if contLocal > 3 [ show "Agente se movendo errado!" ] ]
][
if contLocal >= 3 [ show "Agente se movendo errado!" ]
]
]
]
]
tick
end
to move
;ask walkers[ ;FDS why not 'ask'?
foreach sort civilians [ the-turtle -> ;; EI EF1 EF2 EM CEJA UNI ;FDS why 'sort'?
ask the-turtle [ ;; 'period-of-day' represents the variable to control at which turn the agent should move ( 0 = Matutino, 1 = Vespertino, 2 = Noturno )
ifelse stay-home = true [][
ifelse ticks >= elapsed-days [ ;; EF1 e EF2 sao dividos em 0 e 1, CEJA e EM sao dividos em 0;1;2, UNI sempre será 2, EI é 0 mas deve permanecer no turno vespertino
if period-of-day = 2 and types != CIVILIAN_NAO_ESTUDANTE [ if types = CIVILIAN_NAO_ESTUDANTE [ show "Agente se movendo errado" ] move-backhome ]
set currentPlace [ 0 0 ]
set contLocal 0
set already-spread false
][
if init = "mat" [
if (period-of-day = 0 and types != CIVILIAN_NAO_ESTUDANTE) [ if types = CIVILIAN_NAO_ESTUDANTE [ show "Agente se movendo errado" ] move-to-school ]
if (worker = true and period-of-day != 0) [if worker = false [ show "Agente se movendo errado" ] move-to-work ]
if (worker = true and period-of-day = 0 and types = CIVILIAN_NAO_ESTUDANTE) [ if worker = false [ show "Agente se movendo errado" ] move-to-work]
set anteriorPlace list xcor ycor
set currentPlace anteriorPlace
]
if init = "vesp" [
if ( period-of-day = 0 and worker = false and types != CIVILIAN_EDUCATION_INFANTIL and types != CIVILIAN_NAO_ESTUDANTE) [ if worker = true or types = CIVILIAN_EDUCATION_INFANTIL [ show "Agente se movendo errado" ] move-backhome ] ;; <- Rotina da escola pra casa
if ( period-of-day = 0 and worker = true and types != CIVILIAN_NAO_ESTUDANTE) [if types = CIVILIAN_NAO_ESTUDANTE [ show "Agente se movendo errado" ] move-to-work] ;; <- Rotina da escola pro trabalho
if (period-of-day = 1 and worker = false and types != CIVILIAN_NAO_ESTUDANTE) [if types = CIVILIAN_NAO_ESTUDANTE [ show "Agente se movendo errado" ] move-to-school ] ;; <- Rotina de casa para a escola
if (period-of-day = 1 and worker = true and types != CIVILIAN_NAO_ESTUDANTE) [ if types = CIVILIAN_NAO_ESTUDANTE [ show "Agente se movendo errado" ] move-to-school ] ;; <- Rotina do trabalho para a escola
set currentPlace anteriorPlace
set anteriorPlace list xcor ycor
]
if init = "not" [
if period-of-day = 1 [ move-backhome ]
if (period-of-day = 0 and worker = true) or (types = CIVILIAN_EDUCATION_INFANTIL) [ move-backhome]
if (types = CIVILIAN_NAO_ESTUDANTE) and (worker = true) [ move-backhome] ;;Somar as 3 rotinas de backhome para dar valor total
if period-of-day = 2 and worker = false and types != CIVILIAN_NAO_ESTUDANTE [ if types = CIVILIAN_NAO_ESTUDANTE [ show "Agente se movendo errado" ] move-to-school ] ;; <- Rotina de casa pra escola
if period-of-day = 2 and worker = true and types != CIVILIAN_NAO_ESTUDANTE [if types = CIVILIAN_NAO_ESTUDANTE [ show "Agente se movendo errado" ] move-to-school ] ;; <- Rotina do trabalho pra escola
set already-spread false
set currentPlace anteriorPlace
set anteriorPlace list xcor ycor
]
]
]
]
]
;]
end
to isolar
let try 0
set try workers-isolation-fraction * NUMBER_WORKERS
; show try
ask n-of try civilians with [ worker = true ][
set stay-home true
]
set try students-isolation-fraction * NUMBER_STUDENTS
; show try
ask n-of try civilians with [ types != CIVILIAN_NAO_ESTUDANTE ][
set stay-home true
]
end
to move-to-school
move-to school
set currentPlaceName [location_label] of school
set testar testar + 1