Simulate stock-and-flow model
simulate.Rd
Simulate a stock-and-flow model with simulation specifications defined by sim_specs()
. If not already run, the Julia environment will be set up with use_julia()
. If any problems are detected by debugger()
, the model cannot be simulated.
Usage
simulate(
sfm,
format_code = TRUE,
keep_nonnegative_flow = TRUE,
keep_nonnegative_stock = FALSE,
keep_unit = TRUE,
only_stocks = FALSE,
verbose = FALSE,
debug = FALSE,
...
)
Arguments
- sfm
Stock-and-flow model, object of class sdbuildR_xmile.
- format_code
If TRUE, format the R script with the styler package; only works if language is set to "R" in sim_specs. Defaults to TRUE.
- keep_nonnegative_flow
If TRUE, keeps original non-negativity setting of flows. Defaults to TRUE.
- keep_nonnegative_stock
If TRUE, keeps original non-negativity setting of stocks Defaults to TRUE.
- keep_unit
If TRUE, keeps units of variables. Defaults to TRUE.
- only_stocks
If TRUE, only save stocks. If FALSE, auxiliaries and flows are saved using a callback function. Only applies if language is set to "Julia" in sim_specs() and no delay functions are used. Defaults to FALSE.
- verbose
If TRUE, update on progress. Defaults to FALSE.
- debug
If TRUE, print output for debugging. Defaults to FALSE.
- ...
Optional arguments
Value
Object of class sdbuildR_sim, which is a list containing:
- df
Dataframe, timeseries of computed variables in the ODE
- constants
Constant parameters
- xstart
Initial value of stocks
- script
Simulation script
- duration
Duration of simulation
- success
If TRUE, simulation was successful. If FALSE, simulation failed.
- ...
Other parameters passed to simulate
Examples
sfm = xmile("SIR")
sim = simulate(sfm)
plot(sfm)
# Use Julia for models with units or delay functions
sfm = xmile("coffee_cup") %>% sim_specs(language = "Julia")
use_julia()
#> Starting Julia ...
#> Connecting to Julia TCP server at localhost:11980 ...
#> Package "Tables.jl" (version >= 1.0) is required. Installing ...
#> Starting Julia ...
#> Setting up Julia environment for sdbuildR...
sim = simulate(sfm)
plot(sfm)
# Close Julia session
use_julia(stop = TRUE)