-
Notifications
You must be signed in to change notification settings - Fork 4
/
work_distribution.nls
201 lines (182 loc) · 7.16 KB
/
work_distribution.nls
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
to create-workplaces
reset-timer
let F-workers-middle turtles with [(age > 22) and (age <= 49) and (sex = "F")]
let F-workers-older turtles with [(age >= 50) and (age <= 64) and (sex = "F")]
let F-workers (turtle-set n-of round (0.79 * count F-workers-middle) F-workers-middle n-of round (0.67 * count F-workers-older) F-workers-older)
let M-workers-middle turtles with [(age > 22) and (age <= 49) and (sex = "M")]
let M-workers-older turtles with [(age >= 50) and (age <= 64) and (sex = "M")]
let M-workers (turtle-set n-of round (0.87 * count M-workers-middle) M-workers-middle n-of round (0.74 * count M-workers-older) M-workers-older)
set working-age-agents (turtle-set F-workers M-workers)
work-distribution
assign-work-to-agents
assign-colleagues
show timer
plot-worksites
output-print (word "The city has " count turtles " residents, " length (work-place) " work sites and " (count crowd-workers + count workers) " employees ")
output-print (word "of which " count crowd-workers " are working with close contact to the public ")
end
to work-distribution
let with-crowd round (0.13 * count working-age-agents) ;;13% percent of the workforce are working with crowd
set crowd-workers n-of with-crowd working-age-agents
ask crowd-workers [set crowd-worker? true ]
set workers working-age-agents with [crowd-worker? = false]
let work-size-band (list [1 4][5 9][10 14][15 49][50 60]) ;;work size bands, based on Glasgow statistics: https://www.gov.scot/publications/businesses-in-scotland-2019/ Businesses in Scotland: 2019 XLS table 8
let per-work-size (list 0.63 0.16 0.07 0.1 0.04) ;;per of sites within the size band
let nm-sites 400 * count turtles with [age > 16 ] / 10000 ;number of work sites, based on 400 work sites per 10,000 population over 16- based on Glasgow statistics
let i 0
set work-place (list )
foreach (work-size-band) [band ->
repeat round (nm-sites * item i per-work-size) [
let tmp-size (item 0 band + random (1 + item 1 band - item 0 band))
set work-place insert-item 0 work-place tmp-size
]
set i i + 1
]
let total sum work-place
let working-age count workers ;;number of workers
set work-place map [ff -> round (working-age * ff / total)] work-place ;;determning the number of employees in each site based on proportional size of the site
let y sum work-place - working-age
if y > 0 [set work-place replace-item 0 work-place (item 0 work-place - y) ]
end
to assign-work-to-agents
let tmp-workers workers
let i 1
foreach work-place [mysize ->
let my-workers n-of mysize tmp-workers
ask my-workers [
set my-work i
set tmp-workers other tmp-workers
]
set i i + 1
]
end
;to assign-colleagues
; ask turtles with [my-work != 0][
; set wide-colleagues other turtles with [my-work = [my-work] of myself ]
; ]
; let i 1
; let z max [my-work] of turtles
; repeat z [
; let worker one-of turtles with [my-work = i]
; let group (turtle-set [wide-colleagues] of worker worker)
; let group-size ceiling (count group / 4)
; ask group[set my-work-sub random (group-size)] ;;agents are randomly given a group number
; ask group [set close-colleagues other group with [my-work-sub = [my-work-sub] of myself ]] ;;creating my close-group
; ask group[
; let other-group (turtle-set close-colleagues one-of other group with [my-work-sub != [my-work-sub] of myself ]) ;;adding contacts with one of the other groups
; if other-group != nobody[
; set close-colleagues (turtle-set close-colleagues other-group)
; ask other-group[
; if (member? myself close-colleagues) = false [
; set close-colleagues (turtle-set close-colleagues myself)]
; ]
; ]
; ]
; set i i + 1
; ]
; end
to assign-colleagues
; first we create the wide group
set workplaces table:group-agents workers with [my-work != 0][my-work]
ask turtle-set table:values workplaces [
set out-grp nobody
set wide-colleagues other table:get workplaces my-work
let id my-work
create-wps-with wide-colleagues [
set wp-id id
set wtype "wide"
]
set my-work-sub (word my-work "-" random (count wide-colleagues / 4))
]
; then the restricted group
let subgroups table:group-agents workers with [my-work-sub != 0][my-work-sub]
ask turtle-set table:values subgroups [
let caller self
let id my-work
if out-grp = nobody [
set out-grp one-of (turtle-set other table:get workplaces my-work) with [out-grp = nobody]
if out-grp != nobody [ask out-grp [set out-grp myself]]
]
set close-colleagues (turtle-set out-grp other table:get subgroups my-work-sub)
ask close-colleagues [ask wp-with caller [set wtype "close"]]
]
end
to export-workplaces
file-open "workplaces.csv"
ask wps [
ask both-ends [file-type (word who ",")]
file-print (word wp-id "," wtype)
]
ask workers with [count my-wps = 0 and my-work != 0][
file-print (word who ",," my-work ",null")
]
file-close
file-open "crowd-workers.csv"
ask crowd-workers [file-print who]
file-close
end
to read-workplaces
ask turtles [
set wide-colleagues []
set close-colleagues []
]
foreach csv:from-file "workplaces.csv" [lnk ->
let orig turtle item 0 lnk
let id item 2 lnk
let tp item 3 lnk
ifelse tp != "null" [
let dest turtle item 1 lnk
ifelse tp = "wide" [
ask orig [
if my-work = 0 [set my-work id]
set wide-colleagues lput dest wide-colleagues
]
ask dest [
if my-work = 0 [set my-work id]
set wide-colleagues lput orig wide-colleagues
]
]
[
ask orig [
set my-work id
set close-colleagues lput dest close-colleagues
]
ask dest [
set my-work id
set close-colleagues lput orig close-colleagues
]
]
]
[ask orig [set my-work id]]
]
set workers turtles with [my-work != 0]
ask workers [
set office-worker? true
set wide-colleagues turtle-set wide-colleagues
set close-colleagues turtle-set close-colleagues
]
foreach csv:from-file "crowd-workers.csv" [ag ->
ask turtle item 0 ag [set crowd-worker? true]
]
set crowd-workers turtles with [crowd-worker?]
if behaviorspace-run-number = 0 [
set workplaces table:group-agents turtles with [my-work > 0] [my-work]
let work-list table:values workplaces
let i 0
set work-place[]
repeat table:length workplaces
[set work-place lput count(item i work-list) work-place
set i i + 1]
plot-worksites
output-print (word "The city has " count turtles " residents, " length (work-place) " work sites and " (count crowd-workers + count workers) " employees ")
output-print (word "of which " count crowd-workers " are working with close contact to the public ")
]
end
to plot-worksites
set-current-plot "work-sites"
plot-pen-reset ;; erase what we plotted before
let maxsize max work-place
set-plot-x-range 1 (maxsize + 1) ;; + 1 to make room for the width of the last bar
set-plot-pen-interval 5
histogram work-place
end