Skip to content

Commit

Permalink
Add internal utility functions
Browse files Browse the repository at this point in the history
Add three internal utility functions to get the number of nodes,
number of compartments and number of transitions from a model.
  • Loading branch information
stewid committed Mar 8, 2017
1 parent 34423dd commit 38482c0
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions R/siminf_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,21 @@ siminf_error <- function(err)
stop("Unknown error code.")
}

## Number of nodes
Nn <- function(model) {
dim(model@u0)[2]
}

## Number of compartments
Nc <- function(model) {
dim(model@S)[1]
}

## Number of transitions
Nt <- function(model) {
dim(model@G)[1]
}

##' @rdname run-methods
##' @export
setMethod("run",
Expand Down Expand Up @@ -630,9 +645,9 @@ setMethod("show",
cat(sprintf("Model: %s\n\n",
as.character(class(object))))

cat(sprintf("Number of nodes: %i\n", dim(object@u0)[2]))
cat(sprintf("Number of compartments: %i\n", dim(object@S)[1]))
cat(sprintf("Number of transitions: %i\n", dim(object@G)[1]))
cat(sprintf("Number of nodes: %i\n", Nn(object)))
cat(sprintf("Number of compartments: %i\n", Nc(object)))
cat(sprintf("Number of transitions: %i\n", Nt(object)))
show(object@events)

cat("\n")
Expand All @@ -658,9 +673,9 @@ setMethod("summary",
cat(sprintf("Model: %s\n\n",
as.character(class(object))))

cat(sprintf("Number of nodes: %i\n", dim(object@u0)[2]))
cat(sprintf("Number of compartments: %i\n", dim(object@S)[1]))
cat(sprintf("Number of transitions: %i\n", dim(object@G)[1]))
cat(sprintf("Number of nodes: %i\n", Nn(object)))
cat(sprintf("Number of compartments: %i\n", Nc(object)))
cat(sprintf("Number of transitions: %i\n", Nt(object)))
summary(object@events)

cat("\n")
Expand Down

0 comments on commit 38482c0

Please sign in to comment.