-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathM_M.1 Queue Simulation.R
More file actions
40 lines (39 loc) · 1.32 KB
/
M_M.1 Queue Simulation.R
File metadata and controls
40 lines (39 loc) · 1.32 KB
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
#Niharika 043 IT Group G
set.seed(123)
# Number of customers
n <- 6
# Generate exponential inter-arrival and service times
arrival_times <- cumsum(rexp(n, rate = 1)) # M/M/1 arrival process
service_times <- rexp(n, rate = 2) # Service rate μ = 2
start_service <- numeric(n)
departure_times <- numeric(n)
waiting_times <- numeric(n)
# First customer
start_service[1] <- arrival_times[1]
departure_times[1] <- start_service[1] + service_times[1]
waiting_times[1] <- 0
# Loop for other customers
for (i in 2:n) {
start_service[i] <- max(arrival_times[i], departure_times[i - 1])
waiting_times[i] <- start_service[i] - arrival_times[i]
departure_times[i] <- start_service[i] + service_times[i]
}
time_in_system <- departure_times - arrival_times # Time in system
# Metrics
avg_waiting <- mean(waiting_times)
avg_system <- mean(time_in_system)
utilization <- sum(service_times) / departure_times[n]
# Output
cat("Average Waiting Time:", avg_waiting, "\n")
cat("Average Time in System:", avg_system, "\n")
cat("Server Utilization:", utilization, "\n\n")
df <- data.frame(
Customer = 1:n,
Arrival_Time = arrival_times,
Start_Service_Time = start_service,
Departure_Time = departure_times,
Waiting_Time = waiting_times
)
print(df)
cat("\nTime_in_System\n")
print(time_in_system)