-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDEN-LightRail
185 lines (128 loc) · 3.42 KB
/
DEN-LightRail
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
extensions [ gis nw ]
globals [ den-stations
den-system
nyc-stations
nyc-system]
patches-own [
random-n
centroid
id
]
turtles-own [
infected?
susceptible?
resistant?
home-station
]
to setup
clear-all
; create agents and set their initial properties
create-turtles 500 [
setxy random-xcor random-ycor
set size 1
set color white
set infected? false
]
ask patches [ set pcolor black ]
end
to go
ask turtles [ move-station
]
end
to setup-den
;; load the datasets
set den-stations gis:load-dataset "data/DEN/LightrailStations.shp"
set den-system gis:load-dataset "data/DEN/LightrailLines_Center.shp"
;; set the world envelope to the union of the dataset envelopes, create patch world
gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of den-stations)
(gis:envelope-of den-system))
end
to setup-nyc
;; load the datasets
set nyc-stations gis:load-dataset "data/NYC/nyc-stations.shp"
set nyc-system gis:load-dataset "data/NYC/nyc-lines.shp"
;; set the world envelope to the union of the dataset envelopes, create patch world
gis:set-world-envelope (gis:envelope-union-of (gis:envelope-of nyc-stations)
(gis:envelope-of nyc-system))
end
to display-den
;; display the public transportation system i.e. bus lines, light rail lines
ask patches gis:intersecting den-system
[ set pcolor 7 ]
ask patches gis:intersecting den-stations
[ set pcolor blue]
ask patch -12 6 [set pcolor red]
ask patch -11 3 [set pcolor red]
end
to display-nyc
;; display the public transportation system i.e. bus lines, light rail lines
ask patches gis:intersecting nyc-system
[ set pcolor 7 ]
;;
ask patches gis:intersecting nyc-stations
[ set pcolor blue]
ask patch -21 -5 [set pcolor red]
ask patch -25 -6 [set pcolor red]
ask patch -22 -9 [set pcolor red]
ask patch -22 -15 [set pcolor red]
ask patch -11 -6 [set pcolor red]
ask patch -17 5 [set pcolor red]
end
to infect-setup
ask turtles
[
;; set up the number of initial infected agents
if random 50 = 1 [
set infected? true
set color red
]
if random 2 = 1 [
set susceptible? true
set color yellow
]
if random 2 = 1 [
set resistant? true
set color white
]
]
end
to move-station
;; move toward the nearest station
facexy ([pxcor] of min-one-of (patches with [pcolor = blue]) [distance myself])
([pycor] of min-one-of (patches with [pcolor = blue]) [distance myself])
fd .6
end
to find-downtown
; once at the station, move towards downtown
ask turtles
[
while [[pcolor] of patch-here != red]
[
facexy ([pxcor] of min-one-of (patches with [pcolor = red]) [distance myself])
([pycor] of min-one-of (patches with [pcolor = red]) [distance myself])
fd 0.5
]
]
end
to commute
ask turtles [
if [pcolor] of patch-ahead 1 = blue
[
forward 1
]
if [pcolor] of patch-ahead 1 = 7
[
forward 1
]
if [pcolor] of patch-ahead 1 = black
[
;set heading one-of patches in-cone 1 180 with [pcolor != black]
face min-one-of patches with [ pcolor = 7 ] [ distance myself ]
forward 1
]
if [pcolor] of patch-here = red
[
stop
]
]
end