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.
- ✅ 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
Simply run the script:
python3 grocery_queue_simulation.pyThis will run the simulation with the default example from your PDF.
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]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)The script generates:
- Console Output: Complete simulation table and metrics
- Excel File:
grocery_simulation_results.xlsxwith two sheets:- Simulation Table: Complete step-by-step simulation
- Performance Metrics: All calculated metrics
- Average waiting time for a customer
- Probability that a customer has to wait in queue
- Fraction of idle time of the server
- Average service time
- Average time between arrivals
- Average waiting time of those who wait
- Average time a customer spends in the system
================================================================================
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
================================================================================
- Python 3.6+
- pandas
- numpy
- openpyxl
Install with:
pip install pandas numpy openpyxlIssue: 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
- Different probability distributions: Just modify the dictionaries in
main() - More customers: Add more random digits to the lists
- Different random digit formats: The script handles both 2-digit (service) and 3-digit (interarrival) formats automatically
- Export to different formats: Modify the output file section to save as CSV or other formats
The code is well-commented and includes docstrings for all methods. Check the source code for detailed explanations of each function.