This repository has been archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulation_test.R
58 lines (38 loc) · 1.61 KB
/
simulation_test.R
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
library(tidyverse)
load("data/pharmacy.rda")
load("data/Outstanding_orders.rda")
# set seed for sampling for dev/test
lower_lead = 1.5 # discrete min - 0.5
upper_lead = 10.5 # discrete max - 0.5
mode_lead = 4 # discrete mode
# set distribution for delivery lead time
lead_time_dis <- distr6::Triangular$new(lower = lower_lead,
upper = upper_lead,
mode = mode_lead)
# produce data
pharmacy_sub <- pharmacy %>%
filter(Site1 == "Site C", NSVCode == "Drug A")
daily_data <- phaRmacyForecasting:::make_tsibble(pharmacy_sub, frequency = "Daily")
daily_data <- daily_data %>%
mutate(inventory = sample(2000 : 6000, nrow(.)))
daily_forecast <- phaRmacyForecasting:::forecast_series(daily_data, horizon = 28,
frequency = "Daily")
# produce forecast
for(day in 2310 : nrow(daily_data)){
daily_forecast <- phaRmacyForecasting:::forecast_series(daily_data %>%
slice(1 : day), 28,
frequency = "Daily")
actual_forecast <- daily_forecast %>%
filter(.model == "ETS")
step <- phaRmacyForecasting:::drug_quantity(forecast = daily_forecast,
distribution = lead_time_dis,
min_stock = 1000,
max_stock = 20000,
p_min = 0.01,
p_max = 0.05,
inv_i = daily_data$inventory[day],
delta_pref = 14)
print(step$Q_i)
print("####")
print(step$Delta_i)
}