21 The MesaraTrade model
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).
21.1 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
:
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
21.2 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 norelativePathCostInLand
orrelativePathCostInPort
. We can erase all reference to these two parameters, which will leave the corresponding cultural traits of transport technology as the sole modifiers ofpathCost
.
We carefully organise the scheduling of calls in setup
and go
:
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
21.3 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.
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
View of MesaraTrade interface
21.4 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
?