SpaDES (version 1.1.4)

spades: Run a spatial discrete event simulation

Description

Based on code from chapter 7.8.3 of Matloff (2011): "Discrete event simulation". Here, we implement a simulation in a more modular fashion so it's easier to add submodules to the simulation. We use S4 classes and methods, and use `data.table` instead of `data.frame` to implement the event queue (because it is much faster).

Usage

spades(sim, debug, .plotInitialTime, .saveInitialTime)

## S3 method for class 'simList,logical': spades(sim, debug, .plotInitialTime, .saveInitialTime)

## S3 method for class 'simList,missing': spades(sim, .plotInitialTime, .saveInitialTime)

Arguments

sim
A simList simulation object, generally produced by simInit.
debug
Optional logical flag determines whether sim debug info will be printed (default is debug=FALSE).
.plotInitialTime
Numeric. Temporarily override the .plotInitialTime parameter for all modules. See Details.
.saveInitialTime
Numeric. Temporarily override the .plotInitialTime parameter for all modules. See Details.

Value

  • Invisibly returns the modified simList object.

Details

The is the workhorse function in the SpaDES package. It runs simulations by implementing the rules outlined in the simList.

This function gives simple access to two sets of module parameters: .plotInitialTime and with .plotInitialTime. The primary use of these arguments is to temporarily turn off plotting and saving. "Temporary" means that the simList is not changed, so it can be used again with the simList values reinstated. To turn off plotting and saving, use .plotInitialTime = NA or .saveInitialTime = NA. NOTE: if a module did not use .plotInitialTime or .saveInitialTime, then these arguments will not do anything.

References

Matloff, N. (2011). The Art of R Programming (ch. 7.8.3). San Fransisco, CA: No Starch Press, Inc.. Retrieved from https://www.nostarch.com/artofr.htm

See Also

simInit, SpaDES

Examples

Run this code
mySim <- simInit(
   times = list(start = 0.0, end = 2.0, timeunit = "year"),
   params = list(
     .globals = list(stackName = "landscape", burnStats = "nPixelsBurned")
   ),
   modules = list("randomLandscapes", "fireSpread", "caribouMovement"),
   paths = list(modulePath = system.file("sampleModules", package = "SpaDES"))
 )
 spades(mySim)

 # Can turn off plotting, and inspect the output simList instead
 out <- spades(mySim, .plotInitialTime = NA) # much faster
 completed(out) # shows completed events

Run the code above in your browser using DataLab