Description Format Construction Public Methods Examples
Pipeline acts as a wraper for event functions. It can shuffle the order in which the wrapped event functions get executed and also control how many times they should be run within the pipeline. The later capability allows the modeller to mix events with different time resolutions in a single microsimulation pipeline. A more tangible example would be when you are modelling residential relocation of households, renters may relocate every 6 months but buyers don't move that often hence you can use the Pipeline to run a renter relocation event twice for every run of a buy relocation event.
pipeline <- Pipeline$new(. %>% renter_relocation_event()) for (year in 1:5) { world %>% pipeline$run(n_loops = 2) %>% buyer_relocation_event() }
R6::R6Class object inheriting from Generic.
1 |
x
Event functions in a %>%
structure where the start of the pipe must be .
. \
See the example section below.
set(x)
Sets the event functions inside the Pipeline object.
get()
Returns the event functions.
run(x, shuffle = FALSE, n_loops = 1L)
(Container, logical(1)
, integer(1)
) -> Container
Execute the event functions in the order that it was added. To make the
order randomised set shuffle as TRUE
. n_loops
controls how many times
should the event functions be executed before exiting the Pipeline. If it is
greater than one then the event functions will be run multiple times it
the same order or randomised orders each time, depending on the value in shuffle
.
print()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # create Population
Pop <- Population$new(toy_individuals, toy_households, pid_col = "pid", hid_col = "hid")
# create 3 dummy events
event1 <- function(object) {
# do something
return(object)
}
event2 <- function(object) {
# do something
return(object)
}
event3 <- function(object) {
# do something
return(object)
}
# construct the sequence of the dummy events
# pipeline <- Pipeline$new(. %>% event1 %>% event2 %>% event3)
# pipeline$get()
# run events in a random order
# pipeline$run(x = Pop, shuffle = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.