Los pasos a seguir para simular este problema son:
Elaborar una funcion MMk que reciba el numero de clientes N, el numero de servidores k, y el dia de la semana. La funcion devuelve un dataframe.
Se corta el dataframe cuando el tiempo ha llegado a 480 mins (8 hrs x 60 min/hr)
La funcion MMk_queue es la siguiente:
MMk_queue <- function(N=20,k=2,dia=1) {
if (dia==1) p <- c(0.1,0.15,0.1,0.35,0.25,0.05,0)
if (dia==2) p <- c(0.1,0.1,0.15,0.2,0.35,0.1,0)
if (dia==3) p <- c(0,0.1,0.1,0.2,0.1,0.25,0.25)
if (dia==4) p <- c(0,0.15,0.2,0.2,0.15,0.15,0.15)
if (dia==5) p <- c(0.15,0.15,0.2,0.2,0.1,0.1,0.1)
inter_times <- c(0,1,2,3,4,5,6)
# Interarrival times
interarrival_times <- sample(inter_times,N,replace = T,prob = p)
arrival_times <- cumsum(interarrival_times)
# Service times
service_times <- ceiling(abs(rnorm(N,mean = 8,sd = 5)))
# vectors to track service time and departure
enter_service_times <- rep(0,N)
completion_times <- rep(0,N)
idle_time_server <- rep(0,N)
# first k customers
for (j in 1:k) {
enter_service_times[j] <- arrival_times[j]
completion_times[j] <- enter_service_times[j]+service_times[j]
}
# Loop through the remaining customers
for (i in (k+1):N) {
enter_service_times[i] <- max(arrival_times[i],min(completion_times[i-1],completion_times[i-2]))
if (enter_service_times[i]==enter_service_times[i-1]) {enter_service_times[i] <- max(completion_times[i-3],completion_times[i-2])}
completion_times[i] <- enter_service_times[i]+service_times[i]
}
waiting_time_q <- enter_service_times - arrival_times
total_time <- completion_times - arrival_times
df <- data.frame(inter_llegada=interarrival_times,llegada=arrival_times,tiempo_servicio=service_times,inicio_servicio=enter_service_times,finalizacion=completion_times)
return(df)
}
El resultado de la funcion es:
MMk_queue()
## inter_llegada llegada tiempo_servicio inicio_servicio finalizacion
## 1 3 3 5 3 8
## 2 3 6 7 6 13
## 3 3 9 10 9 19
## 4 5 14 13 14 27
## 5 4 18 21 19 40
## 6 4 22 8 27 35
## 7 3 25 18 35 53
## 8 2 27 1 40 41
## 9 4 31 12 41 53
## 10 0 31 4 53 57
## 11 3 34 15 53 68
## 12 0 34 8 57 65
## 13 4 38 6 65 71
## 14 4 42 17 68 85
## 15 1 43 6 71 77
## 16 3 46 6 77 83
## 17 5 51 20 85 105
## 18 2 53 6 83 89
## 19 3 56 4 89 93
## 20 5 61 9 105 114