This repository implements a simulation of an M/M/S pure loss queueing model, a fundamental model in queueing theory used to study systems with limited server capacity and no waiting queues. Calls that cannot be immediately served are lost.
The M/M/S model is defined by:
- M (Markovian Inter-Arrival Times): The time between successive arrivals follows an exponential distribution.
- M (Markovian Service Times): The service times are exponentially distributed.
- S (Finite Servers): A fixed number of servers are available to serve arriving calls.
This model is commonly used in telecommunications, emergency services, and other systems where blocked arrivals result in losses rather than waiting.
The simulation revolves around two types of events:
- Arrival Event: A new call enters the system. If a server is available, the call is served. Otherwise, the call is lost. Each arrival event generates the next arrival time (
next_arrival_time
) by sampling from the exponential inter-arrival time distribution. - Departure Event: A call completes its service and leaves the system.
Each event updates the system state, including the number of active calls (num_calls
), number of lost calls (num_dropped_calls
), and the time (current_time
).
At any point, the simulation determines which event (arrival or departure) occurs next:
- Arrival Time: Calculated as the current time plus a random inter-arrival time (
exprnd(1 / lambda)
). This is updated every time an arrival event occurs. - Departure Time: The earliest scheduled departure time from the scheduled departures (
scheduled_departure_times
) list.
The simulation compares the next arrival time (next_arrival_time
) and the earliest departure time (min(scheduled_departure_times)
) to decide:
- If the arrival time is sooner, an arrival event occurs:
- If servers are available (
num_calls < S
), the arriving call is served, the number of active calls (num_calls
) increases, and a departure is scheduled. - If servers are full (
num_calls >= S
), the call is lost, and the lost calls counter (num_dropped_calls
) is incremented . - Determines the next arrival time by sampling a new inter-arrival time.
- If servers are available (
- Otherwise, a departure event occurs:
- Reduces the number of active calls (
num_calls
). - Removes the completed departure from the schedule.
- Reduces the number of active calls (
- Arrival Rate (λ): The average number of arrivals per unit time.
- Service Rate (μ): The average number of services completed per unit time.
- Number of Servers (S): The total number of servers. This is an array for server utilization and loss probability statistics.
- Total Time: The duration of the simulation.
lambda = 10 % arrivals / unit time
mu = 2 % services / unit time
S_range = 1:1:20 % number of servers
total_time = 100 % units
- Start the simulation clock at zero (
current_time = 0
). - Generate the first arrival event and initialize the system state:
- Sample the time until the first arrival from the exponential distribution.
- Log the initial system state (time and number of calls).
- Iteratively process events by determining whether the next event is an arrival or departure:
- Compare the time of the next arrival with the earliest departure.
- Update the system state based on the type of event:
- Arrival Event:
- If space is available, serve the call, increase the number of active calls, schedule a departure and generate the next arrival time.
- Otherwise, increment the lost calls counter (
num_dropped_calls
).
- Departure Event:
- Decrease the number of active calls.
- Remove the completed departure from the schedule.
- Arrival Event:
- Log the system state after each event (time and number of calls).
- Continue until simulation time is exceeded (
current_time >= total_time
).
This process iterates until simulations are computed with all server capacities.
This plot tracks the evolution of the number of active calls during the simulation. The orange line represents the number of active calls at each logged event. The red dashed line shows the time-weighted average number of calls, computed across the simulation duration. The green dashed line indicates the overall maximum system capacity.
This visualization is only created for the last server capacity (S) value. In this case for S = 20
.
This histogram displays the probability distribution of the number of active calls during the simulation. The distribution reflects the system's overall load.
This visualization is only created for the last server capacity (S) value. In this case for S = 20
.
This plot provides two separate graphs:
- Probability of Loss Across Server Capacities: This plot shows the probability of call loss for different server capacities (S), based on fixed arrival rate (λ) and service rate (μ). The red dashed line represent the trend of simulated loss probabilities across server capacities. The green dashed line indicates simulated system overall quality of service across server capacities. The cyan dashed line represents theoretical loss probability across server capacities. Orange dots are simulated loss probabilities at each server capacity.
- Server Utilization Across Server Capacities: This plot represents the server utilization for different server capacities (S), based on fixed arrival rate (λ) and service rate (μ). The red dashed line shows the trend of simulated utilization across server capacities. The cyan dashed line represents theoretical utilization across server capacities. Orange dots are simulated utilizations at each server capacity.
- Clone the repository:
git clone https://github.com/mantvydasdeltuva/m_m_s-queue-simulation.git cd m_m_s-queue-simulation
- Open the MATLAB script in the MATLAB editor.
- Modify the parameters (
lambda
,mu
,S_range
,total_time
) if needed. - Run the script to simulate and generate the visualizations.
- MATLAB (Recommended version: R2023a or later).
- Statistics and Machine Learning Toolbox
- Curve Fitting Toolbox
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions and suggestions are welcome. Please feel free to submit an issue or a pull request for improvements.