This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
forked from delapazruiz/domestic.wastewater.variability
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dw.sms.abm.snt.2020.rob.nlogo
2401 lines (2067 loc) · 81.7 KB
/
dw.sms.abm.snt.2020.rob.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
extensions [ gis nw bitmap time rnd] ;time added
globals [
;starting-seed; for reproducible outcomes
current-time ; temporal simulation
study_area
WWTP_data
destination_node
blocks_data
households_data
pipes_data
pipes_lines
stations_data
economic.points_data; new
accumulated.wwps; monitoring wpps generated -> see count.hatching.wwps procedure
]
patches-own [
R_CVEGEO; new
];new
breed [ nodes node ]
breed [ wwps wwp ] ;watewater particles
breed [ wwtps wwtp] ;wastewater treatment plant
breed [ stations station ] ;monitoring stations
breed [ households household ]
breed [ inhabitants inhabitant]
breed [ economic.points economic.point]
directed-link-breed [ pipes pipe ]
pipes-own [ speed ]
households-own [
own_id
block_id
CVEGEO ;new
]
stations-own [
closest_node
z_value
total_volume
travel_path ;monitoring stations also the drains
manhole.id.instation; new to generate timeseries
]
wwtps-own [
closest_node
;total_volume
]
wwps-own [
origin_station
travel_path ;the travel-path of wwps is just the copy of the travel-path of buildings
dw.type ;new
ind.id ;new
manhole.id.instation;new
manhole.id.dymc.old; new to generate manhole timeseries
CVEGEO; new
CVEGEO.reloc; new
hatching.time ;new
dead.time ;new
wwps_speed
]
nodes-own [
z_value
travel_path
slope ]
;;**********************************************************************
inhabitants-own [ ; new
ind.id; new
sex
age
go.school
go.work
escolar.grade
escolar.level
CVEGEO; new
CVEGEO.reloc; new
located.at; new
wwtp.conex; new
wwtp.conex.reloc;new
]
economic.points-own [
id
CVEGEO
avg.workers
school.exist
]
; ------------- Setup - Loading GIS data etc. -------------------------------------------------------------------------------------------
to setup
ca
;random-seed reproducible.seed; setting seed for reproducibility
ask patches [set pcolor grey + 4 ]
;QGIS Processing
; To all shape files:
; Before loding shp's in netlogo: export shapes with ITRF and save them with wgs84
; Generate the following shape files:
;pipes: blueprints or propoused
;manholes: convert polygon/line vertices to points - shpaes: pipes
; a 'height' column is required for manhole stations with realistic flow directions
; when no blueprints are available, can be propoused with DEM
; Implement qgis 'sample raster values' tool. inputs: manholes.shp (points), DEM (raster)
; Adapt shpaes pipes and manholes as required to create and calcualte travel paths
;study area - qgis Extract layer extent to mz
;Mobility dynamycs
; Workers
; Based on economic poits: if DENUE (shape of economic units) is not available,
; comment the following procedures at the go-until procedure:
; homeworkrelocation, workhomerelocation
; Implication: Represents home-office DW generation
; Students
; Based on school locations: Contained at DENUE.
; Add the following fields
; In .shp economic.points_data:
; R_school_e, R_avg_work
; uncomment R_avg_work (if not available) at the economic.points-generation prodecure
gis:load-coordinate-system ("data/13m.loc.snt.2020.mz800.wgs84.prj")
set blocks_data gis:load-dataset "data/13m.loc.snt.2020.mz800.wgs84.shp" ;new
set economic.points_data gis:load-dataset "data/schools.points.snt.wgs84.shp" ;new
set stations_data gis:load-dataset "data/manholes.snt.height.shp"
set households_data gis:load-dataset "data/households.snt.wgs84.shp" ;new
set study_area gis:load-dataset "data/extent.snt.shp"
set WWTP_data gis:load-dataset "data/wwtp.snt.g.shp"
set pipes_data gis:load-dataset "data/pipes.snt.shp"
gis:set-world-envelope-ds (gis:envelope-of study_area )
gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of blocks_data))
gis:set-drawing-color grey + 3
gis:fill blocks_data 1
; gis:set-drawing-color grey + 0.5
; gis:fill households_data 5
gis:set-drawing-color brown
gis:fill WWTP_data 3
gis:set-drawing-color green
gis:fill economic.points_data 5
pipes-lines-generation ;to only generate the lines of pipes (without direction)
nodes-generation ;to generate the nodes in the lines of pipes (the nodes involve stations)
wwtp-generation ;to generate the wwtp agent
stations-generation ;to generate the stations (different from the nodes)
pipes-generation ;to generate the real-world pipes (with directions)
create-path ;to calculate the path to wwtp/destination_node for each station (the path calculation is based on nodes-pipes context)
;read-agent-data-2; new
time:anchor-schedule time:create model.starting.at 60 "minute" ; definition of starting and ending of model
set current-time time:anchor-to-ticks time:create model.starting.at 60 "minute"
RCVEGEO-dataset-in-patches ;new
households-generation ;new
read-sms-agent ;new
economic.points-generation ;new
set accumulated.wwps 0 ;new to count accumulated.wwps
;RCVEGEO; new
;avg.worker
;gis:set-drawing-color black
;gis:draw scalebar 1
;bitmap:copy-to-drawing ( bitmap:scaled ( bitmap:import "data/legend.png" ) 150 120 ) 495 400
reset-ticks
end
; ------------- Setup - Agents Generation -------------------------------------------------------------------------------------
to pipes-lines-generation
let polylines gis:feature-list-of pipes_data ;to get the set of features (one feature might have several lines)
set polylines map [ i -> first gis:vertex-lists-of i ] polylines ;to get the set of lines (here, one feature has only one line)
set polylines map [ i -> map [ ?i -> gis:location-of ?i ] i ] polylines ;to get the set of nodes (the nodes of the same line is also included within a [])
set polylines remove [] map [ i -> remove [] i ] polylines ;remove the blank nodes and lines
set pipes_lines polylines
end
to nodes-generation
foreach pipes_lines [ i ->
let j i
(foreach i [ ?i -> ifelse any? nodes with [ xcor = first ?i and ycor = last ?i ] [] [ create-nodes 1 [
setxy first ?i last ?i
set z_value 0
set slope gis:property-value ( item ( position j pipes_lines ) gis:feature-list-of pipes_data ) "SLOPE"
hide-turtle
;set shape "circle"
;set color red
;set size 2.1
] ] ] )
set i j
]
end
to wwtp-generation
let destination_center gis:centroid-of ( item 0 gis:feature-list-of WWTP_data )
create-wwtps 1 [
setxy (item 0 gis:location-of destination_center) (item 1 gis:location-of destination_center)
set size 1
set label "WWTP"
set label-color black
show-turtle
set closest_node one-of nodes with-min [ distance myself ]
set destination_node closest_node
]
end
to stations-generation
foreach gis:feature-list-of stations_data [ ? ->
create-stations 1 [
setxy (item 0 gis:location-of (gis:centroid-of (?))) (item 1 gis:location-of (gis:centroid-of (?)))
set shape "circle"
set color black
set size 1.5
show-turtle
set total_volume 0
set z_value gis:property-value ? "HEIGHT"
set manhole.id.instation gis:property-value ? "manhole_id"
ask nodes with-min [ distance myself ] [ set z_value gis:property-value ? "HEIGHT" ] ;set nodes' z_value
]
]
end
to pipes-generation
foreach pipes_lines [ i ->
if ( [ z_value ] of one-of nodes with [ xcor = first first i and ycor = last first i ] < [ z_value ] of one-of nodes with [ xcor = first last i and ycor = last last i ] ) [ set i reverse i ]
(foreach butlast i butfirst i [ [ ?1 ?2 ] -> if ?1 != ?2 [ ;skip nodes on top of each other due to rounding
ask nodes with [ xcor = first ?2 and ycor = last ?2 ] [
create-pipes-from nodes with [ xcor = first ?1 and ycor = last ?1 ]
]
]
])
]
ask pipes [ set color turquoise - 1 set thickness 0.001 ]
end
to create-path
nw:set-context nodes pipes
ask stations [
set closest_node one-of nodes with-min [ distance myself ]
set travel_path calculate-path closest_node destination_node
]
end
to-report calculate-path [ node_1 node_2 ]
ask node_1 [ set travel_path nw:turtles-on-path-to node_2 ]
report [ travel_path ] of node_1
end
; ------------- Setup - Synthetic Population Generation -------------------------------------------------------------------------------------
to households-generation
foreach gis:feature-list-of households_data [ ? ->
create-households 1 [
setxy item 0 gis:location-of (gis:centroid-of (?))
item 1 gis:location-of (gis:centroid-of (?))
set size 8
set shape "house"
set color white
show-turtle
;hide-turtle
set own_id gis:property-value ? "id"
set CVEGEO gis:property-value ? "CVEGEO"
;set block_id gis:property-value ? "BLOCK_ID"
;set laundry_load ( 0 - laundry )
;set dish_load ( 0 - dish )
]
]
end
to economic.points-generation
set-default-shape economic.points "circle"
foreach gis:feature-list-of economic.points_data [ ? ->
create-economic.points 1 [
hide-turtle
set size 2
setxy item 0 gis:location-of (gis:centroid-of (?))
item 1 gis:location-of (gis:centroid-of (?))
set id gis:property-value ? "id"
set CVEGEO gis:property-value ? "CVEGEO"
set school.exist gis:property-value ? "R_school_e"
ifelse school.exist = "no" [set color red] [set color green]
;Note: (Un)comment wheter economic points are available
;set avg.workers gis:property-value ? "R_avg_work"
]
]
end
to read-sms-agent
set-default-shape inhabitants "person"
file-open sms.agent.csv ; opens connection to file - last line in procedure closes it
while [not file-at-end?][ ; outer loop through all rows
let $case file-read-line ; reads single line from .csv file
set $case word $case "," ; add a comma at the end
let $data.list [] ; set empty list to collect elements from each case
create-inhabitants 1[ ; create single agent and read their data:
while [not empty? $case] [ ; inner loop through all elements in row
let $pos position "," $case ; find next comma
let $item read-from-string substring $case 0 $pos ; extract item before the comma
set $data.list lput $item $data.list ; add the item to the list
set $case substring $case ($pos + 1) length $case ; remove item and comma from case. repeat loop
]
; now all the items from the row are a items in data.list. assign them to the agent
set sex item 0 $data.list
set age item 1 $data.list
set go.school item 2 $data.list
set go.work item 3 $data.list
set escolar.grade item 4 $data.list
set escolar.level item 5 $data.list
set CVEGEO item 6 $data.list
set ind.id item 7 $data.list
set wwtp.conex item 8 $data.list
set CVEGEO.reloc item 6 $data.list
set located.at "home.place"
set wwtp.conex.reloc item 8 $data.list
set size 4
;hide-turtle
ifelse sex = "m" [set color blue] [set color pink] ; assign colour based on sex
;to allocate inhabitants.points into households: a)same CVEGEO b)from high to low age ranges
ifelse age = "P_25A130" [move-to one-of households with [CVEGEO = [CVEGEO] of myself]] []
ifelse age = "P_18A24" [move-to one-of households with [CVEGEO = [CVEGEO] of myself]] []
ifelse age != "P_25A130" and age != "P_18A24" [move-to one-of households with [CVEGEO = [CVEGEO] of myself]] []
]
]
file-close
end
;;**********************************************************************
to RCVEGEO-dataset-in-patches
gis:apply-coverage blocks_data "R_CVEGEO" R_CVEGEO
end
; ------------- Go Procedure ----------------------------------------------------------------------------------------------------------------
to go.pee
hatch-wwps 1 [
set shape "circle"
set color yellow
set size 3
show-turtle
;DW data analysis
set dw.type "pee"
set hatching.time time:show current-time "yyyy:MM:dd HH:mm"
set ind.id ind.id
set CVEGEO.reloc CVEGEO.reloc
;Traveling related code
set origin_station one-of stations with-min [ distance myself ]
set travel_path [ travel_path ] of origin_station
ifelse travel_path = false or length travel_path = 0 [ set wwps_speed 0 ] [
set wwps_speed 6 ;the wwps generated at households will reach its nearest station at a uniform speed 1
]
; ask wwp who[
;
; file-open "results/dwpee.snt.csv"
; file-print (
; word ;precision ticks 1","
; ind.id","
; time:show current-time "yyyy:MM:dd HH:mm" ","
; time:show current-time "EEE"","
; "pee"","
; CVEGEO.reloc","
; who )
; file-close]
]
;set accumulated.wwps (accumulated.wwps + 1); count the hatched wwps
; hatch washing hands after pee
time:schedule-event self [ [] -> go.washbasin ] (time:plus current-time 1 "minutes")
end
to go.poo
hatch-wwps 1 [
set shape "circle"
set color brown
set size 5
show-turtle
;DW data analysis
set dw.type "poo"
set hatching.time time:show current-time "yyyy:MM:dd HH:mm"
set ind.id ind.id
set CVEGEO.reloc CVEGEO.reloc
;Traveling related code
set origin_station one-of stations with-min [ distance myself ]
set travel_path [ travel_path ] of origin_station
ifelse travel_path = false or length travel_path = 0 [ set wwps_speed 0 ] [
set wwps_speed 6 ;the wwps generated at households will reach its nearest station at a uniform speed 1
]
; ask wwp who[
;
; file-open "results/dwpoo.snt.csv"
; file-print (
; word ;precision ticks 1","
; ind.id","
; time:show current-time "yyyy:MM:dd HH:mm" ","
; time:show current-time "EEE"","
; "poo"","
; CVEGEO.reloc","
; who)
; file-close]
]
; count number of wwps
;set accumulated.wwps (accumulated.wwps + 1)
; hatching washing hands after poo
time:schedule-event self [ [] -> go.washbasin ] (time:plus current-time 1 "minutes")
end
to go.washbasin ; washing hands after poo
hatch-wwps 1 [
set shape "circle"
set color blue
set size 3
show-turtle
;DW data analysis
set dw.type "washbasin"
set hatching.time time:show (current-time) "yyyy:MM:dd HH:mm"
set ind.id ind.id
set CVEGEO.reloc CVEGEO.reloc
;Traveling related code
set origin_station one-of stations with-min [ distance myself ]
set travel_path [ travel_path ] of origin_station
ifelse travel_path = false or length travel_path = 0 [ set wwps_speed 0 ] [
set wwps_speed 6 ;the wwps generated at households will reach its nearest station at a uniform speed 1
]
; ask wwp who [
;
; file-open "results/dwwashbasin.snt.csv"
; file-print (
; word ;precision ticks 1","
; ind.id","
; time:show current-time "yyyy:MM:dd HH:mm" ","
; time:show current-time "EEE"","
; "washbasin"","
; CVEGEO.reloc","
; who)
;file-close
;
; ]
]
; count number of wwps
;set accumulated.wwps (accumulated.wwps + 1)
end
to go.kitchensink
hatch-wwps 1 [
set shape "circle"
set color brown
set size 5
;show-turtle
;
;DW data analysis
set dw.type "kitchensink"
set hatching.time time:show current-time "yyyy:MM:dd HH:mm"
;set dead.time 0
set ind.id ind.id
set CVEGEO.reloc CVEGEO.reloc
;Traveling related code
set origin_station one-of stations with-min [ distance myself ]
set travel_path [ travel_path ] of origin_station
ifelse travel_path = false or length travel_path = 0 [ set wwps_speed 0 ] [
set wwps_speed 6 ;the wwps generated at households will reach its nearest station at a uniform speed 1
]
; ask wwp who[
;
; file-open "results/dwkitchensink.snt.csv"
; file-print (
; word ;precision ticks 1","
; ind.id","
; time:show current-time "yyyy:MM:dd HH:mm" ","
; time:show current-time "EEE"","
; "kitchensink"","
; CVEGEO.reloc","
; who)
;file-close
;
; ]
]
;set accumulated.wwps (accumulated.wwps + 1); count the hatched wwps
; hatching washing hands before and after kitchen
time:schedule-event self [ [] -> go.washbasin ] (time:plus current-time 1 "minutes")
time:schedule-event self [ [] -> go.washbasin ] (time:plus current-time 30 "minutes")
end
to go.shower
hatch-wwps 1 [
set shape "circle"
set color brown
set size 5
;show-turtle
;DW data analysis
set dw.type "shower"
set hatching.time time:show current-time "yyyy:MM:dd HH:mm"
;set dead.time 0
set ind.id ind.id
set CVEGEO.reloc CVEGEO.reloc
;Traveling related code
set origin_station one-of stations with-min [ distance myself ]
set travel_path [ travel_path ] of origin_station
ifelse travel_path = false or length travel_path = 0 [ set wwps_speed 0 ] [
set wwps_speed 6 ;the wwps generated at households will reach its nearest station at a uniform speed 1
]
; ask wwp who[
;
; file-open "results/dwshower.snt.csv"
; file-print (
; word ;precision ticks 1","
; ind.id","
; time:show current-time "yyyy:MM:dd HH:mm" ","
; time:show current-time "EEE"","
; "shower"","
; CVEGEO.reloc","
; who)
;file-close
;
; ]
]
;set accumulated.wwps (accumulated.wwps + 1); count the hatched wwps
;wash hands after shower
time:schedule-event self [ [] -> go.washbasin ] (time:plus current-time 15 "minutes")
end
to go.washingmachine
hatch-wwps 1 [
set shape "circle"
set color brown
set size 5
;show-turtle
;DW data analysis
set dw.type "washingmachine"
set hatching.time time:show current-time "yyyy:MM:dd HH:mm"
set ind.id ind.id
set CVEGEO.reloc CVEGEO.reloc
;Traveling related code
set origin_station one-of stations with-min [ distance myself ]
set travel_path [ travel_path ] of origin_station
ifelse travel_path = false or length travel_path = 0 [ set wwps_speed 0 ] [
set wwps_speed 6 ;the wwps generated at households will reach its nearest station at a uniform speed 1
]
; ask wwp who[
;
; file-open "results/dwwmachine.snt.csv"
; file-print (
; word ;precision ticks 1","
; ind.id","
; time:show current-time "yyyy:MM:dd HH:mm" ","
; time:show current-time "EEE"","
; "washingmachine"","
; CVEGEO.reloc","
; who)
;file-close
;
; ]
]
;set accumulated.wwps (accumulated.wwps + 1); count the two hatched wwps
;wash hands after washingmachine
time:schedule-event self [ [] -> go.washbasin ] (time:plus current-time 5 "minutes")
end
to go.homeworkrelocation
let entry.economicpoint (economic.point who)
ask entry.economicpoint [
ifelse count (inhabitants with [located.at = "home.place" and go.work = "PEA"]) > 0 [
let economic.point.workers ([avg.workers] of entry.economicpoint)
let work.CVEGEO ([CVEGEO] of entry.economicpoint)
ask up-to-n-of (economic.point.workers) inhabitants with [located.at = "home.place" and go.work = "PEA"]
[move-to entry.economicpoint
set color white
set located.at "work.place"
set CVEGEO.reloc (work.CVEGEO)]
;ask entry.economicpoint [show count inhabitants-here ]
;print time:show current-time "yyyy:MM:dd HH:mm"
] []
]
end
to go.workhomerelocation
let entry.economicpoint (economic.point who)
ask entry.economicpoint [
ifelse count (inhabitants-here) > 0 [
foreach sort inhabitants-here [ entry.inhabitant ->
ask entry.inhabitant[
move-to one-of households with [CVEGEO = [CVEGEO] of entry.inhabitant]
set color black
set located.at "home.place"
set CVEGEO.reloc ([CVEGEO] of entry.inhabitant)]
]
]
[]
;print time:show current-time "yyyy:MM:dd HH:mm"
]
end
to go.homeschoolrelocation
let entry.economicpoint (economic.point who)
ask entry.economicpoint [
ifelse count (inhabitants with [located.at = "home.place" and go.school = "PA"]) > 0 [
let school.CVEGEO ([CVEGEO] of entry.economicpoint)
let school.level ([school.exist] of entry.economicpoint)
;send to preschoolar
if (school.level = "school.pre")[
ask inhabitants with [
located.at = "home.place" and
go.school = "PA" and
go.work = "PE_INAC" and
escolar.level = "1"]
[move-to one-of economic.points with [school.exist = "school.pre"]
set color white
set located.at (school.level)
set CVEGEO.reloc (school.CVEGEO)
set wwtp.conex.reloc "n"
;ask entry.economicpoint [show count inhabitants-here ]
;print time:show current-time "yyyy:MM:dd HH:mm"
]
]
;send to elementary schools
if (school.level = "school.elementary")[
ask inhabitants with [
located.at = "home.place" and
go.school = "PA" and
go.work = "PE_INAC" and
escolar.level = "2"]
[move-to entry.economicpoint
set color white
set located.at (school.level)
set CVEGEO.reloc (school.CVEGEO)
set wwtp.conex.reloc "n"
;ask entry.economicpoint [show count inhabitants-here ]
;print time:show current-time "yyyy:MM:dd HH:mm"
]
]
;send to highschool
if (school.level = "school.high")[
ask inhabitants with [
located.at = "home.place" and
go.school = "PA" and
go.work = "PE_INAC" and
escolar.level = "3"]
[move-to entry.economicpoint
set color white
set located.at (school.level)
set CVEGEO.reloc (school.CVEGEO)
set wwtp.conex.reloc "y"
;ask entry.economicpoint [show count inhabitants-here ]
;print time:show current-time "yyyy:MM:dd HH:mm"
]
]
;send to elementary multilevel
if (school.level = "school.multilevel")[
ask inhabitants with [
located.at = "home.place" and
go.school = "PA" and
escolar.level != "1" and
escolar.level != "2" and
escolar.level != "3"]
[move-to entry.economicpoint
set color yellow
set located.at (school.level)
set CVEGEO.reloc (school.CVEGEO)
;ask entry.economicpoint [show count inhabitants-here ]
;print time:show current-time "yyyy:MM:dd HH:mm"
]
]
] []
]
end
to go.schoolhomerelocation
let entry.economicpoint (economic.point who)
ask entry.economicpoint [
ifelse count (inhabitants-here) > 0 [
foreach sort inhabitants-here [ entry.inhabitant ->
ask entry.inhabitant[
move-to one-of households with [CVEGEO = [CVEGEO] of entry.inhabitant]
set color black
set located.at "home.place"
set CVEGEO.reloc ([CVEGEO] of entry.inhabitant)
set wwtp.conex.reloc ([wwtp.conex] of entry.inhabitant)];new
]
]
[]
;print time:show current-time "yyyy:MM:dd HH:mm"
]
end
to pee
;To define probabilities of
; 1) number of pee events (from 2 to 11 times a day)
; 2) in specific hours of the day (from 0 to 23 hours)
let pee.times.aday [ 2 3 4 5 6 7 8 9 10 11 ]; people pee a minimum of 2 and max of 11 times a day
let prob.pee.times.aday [ .02 .05 .07 .13 .19 .17 .18 .12 .05 .02 ]; probabilities of each time to happen
let prob.pee.times.aday.weekend [ .01 .03 .05 .10 .19 .20 .18 .12 .08 .04 ]
; report the first item of the pair selected using; the second item (i.e., `last p`) as the weight
let pee.hour [
0 1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 ]
let prob.pee.hour [
.01 .01 .02 .02 .02 .05
.06 .07 .04 .04 .03
.03 .04 .05 .06 .04
.02 .04 .04 .06 .07
.08 .05 .05
]
let prob.pee.hour.weekend [
.02 .02 .01 .01 .02 .05
.06 .06 .03 .03 .02
.03 .03 .06 .03 .06
.05 .04 .04 .06 .07
.08 .07 .06]
;Peridos defined in interface. Used to define iteration in each day of pee
let pee.starting time:create model.starting.at
;Calculate number of days bertween pee starting and ending for iterations
;+1 is required to starti counting from 1 and not from 0
;n-values creates lenght list of number of pee days with values =[0]
let pee.n.days n-values (time:difference-between (model.starting.at) (model.ending.at) "days") [0]
foreach sort pee.n.days [
ifelse ("Saturday" = time:show pee.starting "EEEE") xor ("Sunday" = time:show pee.starting "EEEE")
[foreach sort inhabitants with [wwtp.conex.reloc = "y"]
[ the-inhabitant ->
let list.pee.event.aday (map list pee.times.aday prob.pee.times.aday.weekend)
let num.pee.event.aday (first rnd:weighted-one-of-list list.pee.event.aday [ [p] -> last p ])
let list.pee.event.hour (map list pee.hour prob.pee.hour.weekend)
let many.pee.event.hours (map first rnd:weighted-n-of-list (num.pee.event.aday) list.pee.event.hour [ [p] -> last p ])
foreach many.pee.event.hours [ hour ->
ask the-inhabitant [ time:schedule-event (inhabitant who) [ [] -> go.pee ] (time:plus (pee.starting) (precision (hour + random-float 1) 2) "hour") ]]]
]
[foreach sort inhabitants with [wwtp.conex.reloc = "y"]
[ the-inhabitant ->
let list.pee.event.aday (map list pee.times.aday prob.pee.times.aday)
let num.pee.event.aday (first rnd:weighted-one-of-list list.pee.event.aday [ [p] -> last p ])
let list.pee.event.hour (map list pee.hour prob.pee.hour)
let many.pee.event.hours (map first rnd:weighted-n-of-list (num.pee.event.aday) list.pee.event.hour [ [p] -> last p ])
foreach many.pee.event.hours [ hour ->
ask the-inhabitant [ time:schedule-event (inhabitant who) [ [] -> go.pee ] (time:plus (pee.starting) (precision (hour + random-float 1) 2) "hour") ]]]
]
set pee.starting time:plus (pee.starting) 1 "day"
]
end
to poo
;To define probabilities of
; 1) number of poo events (from 2 to 11 times a day)
; 2) in specific hours of the day (from 0 to 23 hours)
let poo.times.aday [ 1 2 3 ]; people poo a minimum of 0 and max of 3 times a day
let prob.poo.times.aday [ .6 .25 .15 ]; probabilities of each time to happen
let prob.poo.times.aday.weekend [ .6 .25 .15 ]
; report the first item of the pair selected using; the second item (i.e., `last p`) as the weight
let poo.hour [
0 1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 ]
let prob.poo.hour [
.0 .0 .0 .0 .0 .0
.05 .1 .2 .15 .15
.05 .05 .05 .05 .05
.02 .02 .02 .02 .02
.0 .0 .0 ]
let prob.poo.hour.weekend [
.0 .0 .0 .0 .0 .0
.05 .05 .1 .2 .2
.1 .05 .05 .05 .05
.02 .02 .02 .02 .02
.0 .0 .0]
;Peridos defined in interface. Used to define iteration in each day of poo
let poo.starting time:create model.starting.at
;Calculate number of days bertween poo starting and ending for iterations
;+1 is required to starti counting from 1 and not from 0
;n-values creates lenght list of number of poo days with values =[0]
let poo.n.days n-values (time:difference-between (model.starting.at) (model.ending.at) "days") [0]
foreach sort poo.n.days [
ifelse ("Saturday" = time:show poo.starting "EEEE") xor ("Sunday" = time:show poo.starting "EEEE")
[foreach sort inhabitants with [wwtp.conex.reloc = "y"]
[ the-inhabitant ->
let list.poo.event.aday (map list poo.times.aday prob.poo.times.aday.weekend)
let num.poo.event.aday (first rnd:weighted-one-of-list list.poo.event.aday [ [p] -> last p ])
let list.poo.event.hour (map list poo.hour prob.poo.hour.weekend)
let many.poo.event.hours (map first rnd:weighted-n-of-list (num.poo.event.aday) list.poo.event.hour [ [p] -> last p ])
foreach many.poo.event.hours [ hour ->
ask the-inhabitant [ time:schedule-event (inhabitant who) [ [] -> go.poo ] (time:plus (poo.starting) (precision (hour + random-float 1) 2) "hour") ]]]
]
[foreach sort inhabitants with [wwtp.conex.reloc = "y"]
[ the-inhabitant ->
let list.poo.event.aday (map list poo.times.aday prob.poo.times.aday)
let num.poo.event.aday (first rnd:weighted-one-of-list list.poo.event.aday [ [p] -> last p ])
let list.poo.event.hour (map list poo.hour prob.poo.hour)
let many.poo.event.hours (map first rnd:weighted-n-of-list (num.poo.event.aday) list.poo.event.hour [ [p] -> last p ])
foreach many.poo.event.hours [ hour ->
ask the-inhabitant [ time:schedule-event (inhabitant who) [ [] -> go.poo ] (time:plus (poo.starting) (precision (hour + random-float 1) 2) "hour") ]]]
]
set poo.starting time:plus (poo.starting) 1 "day"
]
end
to kitchensink
;To define probabilities of
; 1) number of kitchensink events (from 2 to 11 times a day)
; 2) in specific hours of the day (from 0 to 23 hours)
let kitchensink.times.aday [ 1 2 3 4 5 ]; people kitchen mimum of 1 and max of 5 uses a day
let prob.kitchensink.times.aday.high [ 0.4 0.35 0.15 0.05 0.05 ]; probabilities of each time to happen
let prob.kitchensink.times.aday.weekend.high [ 0.1 0.35 0.45 0.05 0.05 ]
; report the first item of the pair selected using; the second item (i.e., `last p`) as the weight
let prob.kitchensink.times.aday.medium [ 0.4 0.35 0.15 0.05 0.05 ]; probabilities of each time to happen
let prob.kitchensink.times.aday.weekend.medium [ 0.05 0.35 0.45 0.1 0.05 ]
let prob.kitchensink.times.aday.low [ 0.4 0.35 0.15 0.05 0.05 ]; probabilities of each time to happen
let prob.kitchensink.times.aday.weekend.low [ 0.05 0.35 0.45 0.1 0.05 ]
let kitchensink.hour [
0 1 2 3 4 5
6 7 8 9 10 11
12 13 14 15 16 17
18 19 20 21 22 23 ]
let prob.kitchensink.hour [
0 0 0 0 0 0.03 ; 0 to 5 hors
0.05 0.12 0.08 0.05 0 0 ; 6 to 11 hours
0.06 0.13 0.15 0.09 0.03 0 ; 12 to 17 hours
0 0.07 0.1 0.04 0 0 ; 18 to 23 hours
]
let prob.kitchensink.hour.weekend [
0 0 0 0 0 0 ; 0 to 5 hors
0.03 0.05 0.07 0.12 0.08 0 ; 6 to 11 hours
0.03 0.15 0.2 0.15 0.05 0 ; 12 to 17 hours
0 0.05 0.07 0.15 0.05 0 ; 18 to 23 hours
]
;Peridos defined in interface. Used to define iteration in each day of pee
let kitchensink.starting time:create model.starting.at
;Calculate number of days bertween pee starting and ending for iterations
;+1 is required to starti counting from 1 and not from 0
;n-values creates lenght list of number of pee days with values =[0]
let kitchensink.n.days n-values (time:difference-between (model.starting.at) (model.ending.at) "days") [0]
foreach sort kitchensink.n.days [
;;;;;;;;;; HIGH. high probability to use kitchen (no work no study)
ifelse ("Saturday" = time:show kitchensink.starting "EEEE") xor ("Sunday" = time:show kitchensink.starting "EEEE")
[foreach sort inhabitants with [
wwtp.conex.reloc = "y" and
go.school = "NOA" and
go.work = "PE_INAC"]
[ the-inhabitant ->
let list.kitchensink.event.aday (map list kitchensink.times.aday prob.kitchensink.times.aday.weekend.high)
let num.kitchensink.event.aday (first rnd:weighted-one-of-list list.kitchensink.event.aday [ [p] -> last p ])
let list.kitchensink.event.hour (map list kitchensink.hour prob.kitchensink.hour.weekend)
let many.kitchensink.event.hours (map first rnd:weighted-n-of-list (num.kitchensink.event.aday) list.kitchensink.event.hour [ [p] -> last p ])
foreach many.kitchensink.event.hours [ hour ->
ask the-inhabitant [ time:schedule-event (inhabitant who) [ [] -> go.kitchensink ] (time:plus (kitchensink.starting) (precision (hour + random-float 1) 2) "hour") ]]]
]
[foreach sort inhabitants with [
wwtp.conex.reloc = "y" and
go.school = "NOA" and
go.work = "PE_INAC"]
[ the-inhabitant ->
let list.kitchensink.event.aday (map list kitchensink.times.aday prob.kitchensink.times.aday.high)
let num.kitchensink.event.aday (first rnd:weighted-one-of-list list.kitchensink.event.aday [ [p] -> last p ])
let list.kitchensink.event.hour (map list kitchensink.hour prob.kitchensink.hour)
let many.kitchensink.event.hours (map first rnd:weighted-n-of-list (num.kitchensink.event.aday) list.kitchensink.event.hour [ [p] -> last p ])
foreach many.kitchensink.event.hours [ hour ->
ask the-inhabitant [ time:schedule-event (inhabitant who) [ [] -> go.kitchensink ] (time:plus (kitchensink.starting) (precision (hour + random-float 1) 2) "hour") ]]]
]
;;;;;;;;;; MEDIUM1. probability to use kitchen (work but no study)
ifelse ("Saturday" = time:show kitchensink.starting "EEEE") xor ("Sunday" = time:show kitchensink.starting "EEEE")
[foreach sort inhabitants with [
wwtp.conex.reloc = "y" and
go.school = "NOA" and
go.work = "PEA"]
[ the-inhabitant ->
let list.kitchensink.event.aday (map list kitchensink.times.aday prob.kitchensink.times.aday.weekend.medium)
let num.kitchensink.event.aday (first rnd:weighted-one-of-list list.kitchensink.event.aday [ [p] -> last p ])
let list.kitchensink.event.hour (map list kitchensink.hour prob.kitchensink.hour.weekend)
let many.kitchensink.event.hours (map first rnd:weighted-n-of-list (num.kitchensink.event.aday) list.kitchensink.event.hour [ [p] -> last p ])
foreach many.kitchensink.event.hours [ hour ->
ask the-inhabitant [ time:schedule-event (inhabitant who) [ [] -> go.kitchensink ] (time:plus (kitchensink.starting) (precision (hour + random-float 1) 2) "hour") ]]]
]
[foreach sort inhabitants with [
wwtp.conex.reloc = "y" and
go.school = "NOA" and
go.work = "PEA"]
[ the-inhabitant ->
let list.kitchensink.event.aday (map list kitchensink.times.aday prob.kitchensink.times.aday.medium)
let num.kitchensink.event.aday (first rnd:weighted-one-of-list list.kitchensink.event.aday [ [p] -> last p ])
let list.kitchensink.event.hour (map list kitchensink.hour prob.kitchensink.hour)
let many.kitchensink.event.hours (map first rnd:weighted-n-of-list (num.kitchensink.event.aday) list.kitchensink.event.hour [ [p] -> last p ])
foreach many.kitchensink.event.hours [ hour ->
ask the-inhabitant [ time:schedule-event (inhabitant who) [ [] -> go.kitchensink ] (time:plus (kitchensink.starting) (precision (hour + random-float 1) 2) "hour") ]]]
]
;;;;;;;;;; MEDIUM2. probability to use kitchen (no work but study)
ifelse ("Saturday" = time:show kitchensink.starting "EEEE") xor ("Sunday" = time:show kitchensink.starting "EEEE")
[foreach sort inhabitants with [
wwtp.conex.reloc = "y" and
go.school = "PA" and
go.work = "PE_INAC"]
[ the-inhabitant ->
let list.kitchensink.event.aday (map list kitchensink.times.aday prob.kitchensink.times.aday.weekend.medium)
let num.kitchensink.event.aday (first rnd:weighted-one-of-list list.kitchensink.event.aday [ [p] -> last p ])
let list.kitchensink.event.hour (map list kitchensink.hour prob.kitchensink.hour.weekend)
let many.kitchensink.event.hours (map first rnd:weighted-n-of-list (num.kitchensink.event.aday) list.kitchensink.event.hour [ [p] -> last p ])
foreach many.kitchensink.event.hours [ hour ->