Debug stock-and-flow model
debugger.Rd
Check for common formulation problems in a stock-and-flow model.
Details
The following problems are detected:
An absence of stocks
Flows without a source (
from
) or target (to
)Flows connected to a stock that does not exist
Undefined variable references in equations
Circularity in equations
Connected stocks and flows without both having units or no units
Missing unit definitions
The following potential problems are detected:
Absence of flows
Stocks without inflows or outflows
Equations with a value of 0
See also
Other build:
as.data.frame.sdbuildR_sim()
,
as.data.frame.sdbuildR_xmile()
,
build()
,
find_dependencies()
,
get_build_code()
,
header()
,
macro()
,
plot.sdbuildR_xmile()
,
print.summary.sdbuildR_xmile()
,
summary.sdbuildR_xmile()
,
xmile()
Examples
# No issues
sfm <- xmile("SIR")
debugger(sfm)
#> No problems detected!
#> Potentially problematic:
#> * These variables have an equation of 0:
#> - Recovered
# Detect absence of stocks or flows
sfm <- xmile()
debugger(sfm)
#> Problems:
#> * Your model has no stocks.
#>
#> Potentially problematic:
#> * Your model has no flows.
# Detect stocks without inflows or outflows
sfm <- xmile() |> build("Prey", "stock")
debugger(sfm)
#> No problems detected!
#> Potentially problematic:
#> * Your model has no flows.
#>
#> * These variables have an equation of 0:
#> - Prey
# Detect circularity in equation definitions
sfm <- xmile() |>
build("Prey", "stock", eqn = "Predator") |>
build("Predator", "stock", eqn = "Prey")
debugger(sfm)
#> Problems:
#> * Ordering static equations failed. Circular dependencies detected involving variables: Predator, Prey
#> - Predator depends on Prey
#> - Prey depends on Predator
#>
#> Potentially problematic:
#> * Your model has no flows.