Skip to content

Commit

Permalink
Adding missing ports
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Nov 19, 2024
1 parent 5b646c4 commit f71adff
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 87 deletions.
185 changes: 121 additions & 64 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,123 @@
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"map": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"thread": "cpp",
"cinttypes": "cpp"
},
"editor.indentSize": "tabSize",
"[r]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false
}
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"map": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"thread": "cpp",
"cinttypes": "cpp"
},
"editor.indentSize": "tabSize",
"[r]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false
},
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.cCompilerPath": "clang",
"C_Cpp_Runner.cppCompilerPath": "clang++",
"C_Cpp_Runner.debuggerPath": "lldb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

S3method("[",epiworld_agents)
S3method("[",epiworld_entities)
S3method(add_param,epiworld_model)
S3method(add_tool,epiworld_model)
S3method(add_virus,epiworld_model)
S3method(add_virus,epiworld_seir)
Expand Down Expand Up @@ -107,6 +108,7 @@ export(ModelSISD)
export(ModelSURV)
export(add_entity)
export(add_globalevent)
export(add_param)
export(add_tool)
export(add_tool_agent)
export(add_tool_n)
Expand Down Expand Up @@ -174,6 +176,7 @@ export(plot_reproductive_number)
export(queuing_off)
export(queuing_on)
export(rm_entity)
export(rm_globalevent)
export(rm_tool)
export(rm_virus)
export(run)
Expand Down
4 changes: 4 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ set_param_cpp <- function(model, pname, val) {
.Call(`_epiworldR_set_param_cpp`, model, pname, val)
}

add_param_cpp <- function(model, pname, val) {
.Call(`_epiworldR_add_param_cpp`, model, pname, val)
}

set_name_cpp <- function(model, mname) {
.Call(`_epiworldR_set_name_cpp`, model, mname)
}
Expand Down
52 changes: 38 additions & 14 deletions R/global-actions.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

#' Global Actions
#' Global Events
#'
#' Global actions are functions that are executed at each time step of the
#' Global events are functions that are executed at each time step of the
#' simulation. They are useful for implementing interventions, such as
#' vaccination, isolation, and social distancing by means of tools.
#'
#' @export
#' @param prob Numeric scalar. A probability between 0 and 1.
#' @param tool An object of class [tool].
#' @name global-actions
#' @name global-events
#' @aliases global-actions
#' @examples
#' # Simple model
#' model_sirconn <- ModelSIRCONN(
Expand All @@ -32,7 +33,7 @@
#' )
#'
#'
#' # Adding a global action
#' # Adding a global event
#' vaccine_day_20 <- globalevent_tool(epitool, .2, day = 20)
#' add_globalevent(model_sirconn, vaccine_day_20)
#'
Expand Down Expand Up @@ -98,7 +99,7 @@ globalaction_tool <- function(...) {
}

#' @export
#' @rdname global-actions
#' @rdname global-events
#' @param vars Integer vector. The position of the variables in the model.
#' @param coefs Numeric vector. The coefficients of the logistic regression.
#' @details The function `globalevent_tool_logit` allows to specify a logistic
Expand Down Expand Up @@ -143,7 +144,7 @@ globalaction_tool_logit <- function(...) {
#' @export
#' @param param Character scalar. The name of the parameter to be set.
#' @param value Numeric scalar. The value of the parameter.
#' @rdname global-actions
#' @rdname global-events
#' @details The function `globalevent_set_param` allows to set a parameter of
#' the model. The parameter is specified by its name `param` and the value by
#' `value`.
Expand Down Expand Up @@ -180,7 +181,7 @@ globalaction_set_params <- function(...) {
}

#' @export
#' @rdname global-actions
#' @rdname global-events
#' @param fun Function. The function to be executed.
#' @details The function `globalevent_fun` allows to specify a function to be
#' executed at a given day. The function object must receive an object of class
Expand Down Expand Up @@ -258,11 +259,15 @@ print.epiworld_globalevent <- function(x, ...) {
}

#' @export
#' @param action A global action.
#' @param action (Deprecated) use `event` instead.
#' @param event The event to be added or removed. If it is to add, then
#' it should be an object of class `epiworld_globalevent`. If it is to remove,
#' it should be an integer with the position of the event in the model
#' (starting from zero).
#' @param day Integer. The day (step) at which the action is executed (see details).
#' @param model An object of class [epiworld_model].
#' @param name Character scalar. The name of the action.
#' @rdname global-actions
#' @rdname global-events
#' @seealso epiworld-model
#' @details The function `add_globalevent` adds a global action to a model.
#' The model checks for actions to be executed at each time step. If the added
Expand All @@ -271,12 +276,31 @@ print.epiworld_globalevent <- function(x, ...) {
#' the action is executed at the specified time step.
#' @returns
#' - The function `add_globalevent` returns the model with the added
#' action.
add_globalevent <- function(model, action) {
#' event
add_globalevent <- function(model, event, action = NULL) {

if (length(attr(action, "tool")))
add_tool(model, attr(action, "tool"))
if (missing(event) && !missing(action)) {
event <- action
warning("The argument `action` is deprecated. Use `event` instead.")
}

stopifnot_model(model)

if (length(attr(event, "tool")))
add_tool(model, attr(event, "tool"))

invisible(add_globalevent_cpp(model, event))

}

#' @export
#' @rdname global-events
#' @returns
#' - The function `rm_globalevent` returns the model with the removed
#' event.
rm_globalevent <- function(model, event) {

invisible(add_globalevent_cpp(model, action))
stopifnot_model(model)
invisible(rm_globalevent_cpp(model, event))

}
14 changes: 13 additions & 1 deletion R/model-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ get_param.epiworld_model <- function(x, pname) {
}


#' @export
#' @rdname epiworld-methods
#' @returns
#' - `add_param` returns the model with the added parameter invisibly.
add_param <- function(x, pname, pval) UseMethod("add_param")

#' @export
#' @rdname epiworld-methods
add_param.epiworld_model <- function(x, pname, pval) {
invisible(add_param_cpp(x, pname, pval))
}


#' @export
#' @param pval Numeric. Value of the parameter.
#' @returns
Expand All @@ -217,7 +230,6 @@ set_param <- function(x, pname, pval) UseMethod("set_param")
#' @export
set_param.epiworld_model <- function(x, pname, pval) {
invisible(set_param_cpp(x, pname, pval))
invisible(x)
}

#' @export
Expand Down
10 changes: 10 additions & 0 deletions man/epiworld-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f71adff

Please sign in to comment.