-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessara-pond-trade.qmd
249 lines (162 loc) · 5.66 KB
/
messara-pond-trade.qmd
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
# The MesaraTrade model {#messara-pond-trade}
Finally, after much of the modelling equivalent of *blood and sweat*, we reach the point where we can combine the contribution of all our modules with the full implementation of the Pond Trade model (step 13).
## Integrating module 4 (ARID) and 5 (routes)
We use module 4 - ARID as the starting template and add `import-routes-from-file` and all route related procedures. We should be able to import the routes data saved before and load it during set up, as the last step before `setup-patches`:
```NetLogo
globals
[
...
routes
...
]
...
to setup
clear-all
; --- loading/testing parameters -----------
import-map-with-flows ; import-world must be the first step
set-constants
set-parameters
import-routes-from-file
; --- core procedures ----------------------
set currentYear weatherInputData_firstYear
set currentDayOfYear 1
;;; values are taken from input data
set-day-weather-from-input-data currentDayOfYear currentYear
ask patchesWithElevationData [ update-WAT ]
; --- display & output handling ------------------------
update-output
refresh-view
paint-routes
; -- time -------------------------------------
reset-ticks
end
...
to refresh-view
...
paint-routes
paint-active-routes
end
to paint-routes
;;; define list of shades of red in NetLogo
let redShades (list 11 12 13 14 15 16 17 18 19)
;;; NOTE: this is needed because rgb colors based on elevation are a list
;;; while NetLogo color are numbers
; resets route patches to the terrain color
foreach routes
[ ?1 ->
let aRoute ?1
foreach aRoute
[ ??1 ->
ask ??1 [ display-elevation ]
]
]
; paint route patches in shades of red depending on route frequency
foreach routes
[ ?1 ->
let aRoute ?1
foreach aRoute
[ ??1 ->
ask ??1
[
if (showRoutes)
[
ifelse (not member? pcolor redShades) ; if its the first route crossing the patch
[
set pcolor 11
]
[
set pcolor min (list (pcolor + 1) (19)) ; sets a maximum at 19 (the brightest)
]
]
]
]
]
end
to paint-active-routes
ask traders
[
foreach route
[ ?1 ->
ask ?1
[
ifelse (showActiveRoutes)
[
set pcolor yellow
]
[
if (not showRoutes) ; if not displaying all routes
[
; resets to the patch terrain color
display-elevation
]
]
]
]
]
end
```
## Integrating Pond Trade (step 13)
Next, we bring all the extra code and interface objects present in Pond Trade (step 13). Most procedures require no modifications. The exceptions are:
- There is no `isLand` variable here and, given that there is no water patches, we should simply erase the code that distinguishes it.
- Since there is only land patches and we are using the standard deviation of elevations to assign `pathCost`, there are no `relativePathCostInLand` or `relativePathCostInPort`. We can erase all reference to these two parameters, which will leave the corresponding cultural traits of transport technology as the sole modifiers of `pathCost`.
We carefully organise the scheduling of calls in `setup` and `go`:
```NetLogo
to setup
clear-all
reset-ticks
; set the random seed so we can reproduce the same experiment
random-seed seed
set patchesCount count patches
create-map
create-coastal-settlements
set-routes
create-traders-per-settlement
update-output
update-display
update-plots
end
...
to go
tick
if (ticks = 10000 or count turtles > 500) [ stop ]
update-traders
update-settlements
update-output
update-display
end
```
## Extension: ARID as a factor of settlement productivity
Last, we need to connect ARID to settlement productivity.
We first calculate the value of two new settlement variables, `catchmentArea` and `ARIDinCatchmentArea`. The latter is the average ARID within the settlement catchment area. In turn, the catchment area is calculated using a gradient decay function, dependent on `sizeLevel` and two parameters, `catchmentSlope` and `catchmentRadiusMaximum`. This is a *very* preliminary solution, but will suffice for us to observe the dynamics of Pond Trade playing out over the Mesara Valley.
```NetLogo
settlements-own
[
...
catchmentArea
ARIDinCatchmentArea
]
...
to update-ARIDinCatchmentArea
let patchesInCatchmentArea patches in-radius catchmentArea
ifelse (count patchesInCatchmentArea = 1)
[ set ARIDinCatchmentArea [ARID] of patch-here ]
[ set ARIDinCatchmentArea mean [ARID] of patchesInCatchmentArea]
end
to update-catchmentArea
set catchmentArea get-value-in-gradient sizeLevel catchmentSlope catchmentRadiusMaximum
end
to-report get-value-in-gradient [ input gradient maximum ]
report e ^ ( - input / ((gradient / 100) * maximum) )
end
```
And *voilà*! We can now run our boosted Pond Trade model within the context of our case study.
![View of MesaraTrade after set up](assets/screenshots/BlockC_module6_MesaraTrade view.png)
*View of MesaraTrade after set up*
![View of MesaraTrade interface](assets/screenshots/BlockC_module6_MesaraTrade interface.png)
*View of MesaraTrade interface*
## Margins to improve and explore
There are many other points to refactor, explore alternatives and expand. Just remember to first give it a think and then start writing code.
For example:
- Can we visualise `catchmentArea` of settlements in the NetLogo View, instead of `sizeLevel`?
- Could we find a way to calibrate the speed of traders to the same daily rhythm of the weather variables?
- Could rivers also affect `patchCost`?