Non-homogeneous arrival process #271
-
Is there a way to vary the arrival process as the simulation flows? In my problem, the arrival process varies with time, at 6am, very few customers joins the queue, but at 11am we have a peak of customers joining the queue, then it starts do decrease. I'm building a custom arrival function, but I'm starting to wonder if there is another way to do tackle this in simmer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
As usual with library(simmer)
t <- trajectory() %>%
log_("Here I am")
df_rel <- data.frame(time = rep(2, 5))
df_abs <- data.frame(time = seq(2, 10, 2))
env <- simmer() %>%
add_dataframe("dummy_rel", t, df_rel) %>%
add_dataframe("dummy_abs", t, df_abs, time="absolute")
run(env)
#> 2: dummy_rel0: Here I am
#> 2: dummy_abs0: Here I am
#> 4: dummy_rel1: Here I am
#> 4: dummy_abs1: Here I am
#> 6: dummy_rel2: Here I am
#> 6: dummy_abs2: Here I am
#> 8: dummy_rel3: Here I am
#> 8: dummy_abs3: Here I am
#> 10: dummy_rel4: Here I am
#> 10: dummy_abs4: Here I am
#> simmer environment: anonymous | now: 10 | next:
#> { Monitor: in memory }
#> { Source: dummy_rel | monitored: 1 | n_generated: 5 }
#> { Source: dummy_abs | monitored: 1 | n_generated: 5 } On the other hand, generator functions can be as complex as you need. You can access the simulation time using env <- simmer() %>%
add_generator("dummy", t, function() {
t <- now(env) %% 24
rate <- if (t > 8 && t < 18) 0.5 else 0.1
rexp(1, rate)
})
run(env, 48) # 48 hours
#> 0.394713: dummy0: Here I am
#> 7.78957: dummy1: Here I am
#> 19.9987: dummy2: Here I am
#> 27.249: dummy3: Here I am
#> 27.2921: dummy4: Here I am
#> 27.9629: dummy5: Here I am
#> 31.8869: dummy6: Here I am
#> 41.9274: dummy7: Here I am
#> 43.7204: dummy8: Here I am
#> simmer environment: anonymous | now: 48 | next: 59.4903857030956
#> { Monitor: in memory }
#> { Source: dummy | monitored: 1 | n_generated: 10 } |
Beta Was this translation helpful? Give feedback.
As usual with
simmer
, there are several options available to suit your needs. You could simply precompute all your arrivals up to the time you want to simulate into a dataframe, with relative (interarrival) or absolute times, then attach it and run the entire thing. This method is particularly suitable for feeding preexisting experimental data. Example: