Skip to content

younusFoysal/Single-Server-Queue-Simulation-with-Python

Repository files navigation

Grocery Store Queue Simulation - User Guide

Overview

This Python script automates the single-server queue simulation for a grocery store checkout counter. It generates the complete simulation table and calculates all performance metrics automatically.

Features

  • ✅ Automatic random digit to time mapping
  • ✅ Complete simulation table generation
  • ✅ All 7 performance metrics calculated
  • ✅ Results exported to Excel
  • ✅ Easy to customize with your own data

How to Use

Basic Usage (with the example from PDF)

Simply run the script:

python3 grocery_queue_simulation.py

This will run the simulation with the default example from your PDF.

Custom Simulation

To run your own simulation, modify the main() function in the script:

# Define your probability distributions
interarrival_dist = {
    1: 0.125, 2: 0.125, 3: 0.125, 4: 0.125,
    5: 0.125, 6: 0.125, 7: 0.125, 8: 0.125
}

service_dist = {
    1: 0.10, 2: 0.20, 3: 0.30, 4: 0.25, 5: 0.10, 6: 0.05
}

# Your random digits
arrival_random_digits = [913, 727, 15, 948, 309]
service_random_digits = [84, 10, 74, 53, 17, 79]

As a Library

You can also use it in your own Python scripts:

from grocery_queue_simulation import QueueSimulation

# Define distributions
interarrival_dist = {1: 0.2, 2: 0.3, 3: 0.5}
service_dist = {1: 0.4, 2: 0.6}

# Create simulation
sim = QueueSimulation(interarrival_dist, service_dist)

# Run with your random digits
df, metrics = sim.simulate(
    arrival_random_digits=[234, 567, 890],
    service_random_digits=[12, 45, 78, 99]
)

# Print results
print(df)
sim.print_metrics(metrics)

Output Files

The script generates:

  1. Console Output: Complete simulation table and metrics
  2. Excel File: grocery_simulation_results.xlsx with two sheets:
    • Simulation Table: Complete step-by-step simulation
    • Performance Metrics: All calculated metrics

Performance Metrics Calculated

  1. Average waiting time for a customer
  2. Probability that a customer has to wait in queue
  3. Fraction of idle time of the server
  4. Average service time
  5. Average time between arrivals
  6. Average waiting time of those who wait
  7. Average time a customer spends in the system

Example Output

================================================================================
SIMULATION TABLE
================================================================================
Customer Random_Digit_Arrival IAT  Arrival_Time  Random_Digit_Service  ...
       1                    -   -             0                    84  ...
       2                  913   8             8                    10  ...
       3                  727   6            14                    74  ...
...

================================================================================
PERFORMANCE METRICS
================================================================================
1. Average waiting time for a customer:              0.50 min
2. Probability that a customer has to wait:          0.167 (16.7%)
3. Fraction of idle time of the server:              0.367 (36.7%)
4. Average service time:                             3.17 min
5. Average time between arrivals:                    5.20 min
6. Average waiting time of those who wait:           3.00 min
7. Average time a customer spends in the system:    3.67 min
================================================================================

Requirements

  • Python 3.6+
  • pandas
  • numpy
  • openpyxl

Install with:

pip install pandas numpy openpyxl

Troubleshooting

Issue: ImportError: No module named 'pandas' Solution: Install required packages: pip install pandas numpy openpyxl

Issue: Results don't match expected values Solution: Verify your random digits and probability distributions match your problem

Customization Tips

  1. Different probability distributions: Just modify the dictionaries in main()
  2. More customers: Add more random digits to the lists
  3. Different random digit formats: The script handles both 2-digit (service) and 3-digit (interarrival) formats automatically
  4. Export to different formats: Modify the output file section to save as CSV or other formats

Questions?

The code is well-commented and includes docstrings for all methods. Check the source code for detailed explanations of each function.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages