For this computer assignment, you are to write and implement a Python program to simulate a typical grocery store. The purpose of this program is simply to collect statistical data during the simulation and printout the final statistics at the end of the simulation. In this model, customers enter the store by random inter-arrival times and then start picking up the grocery items, which takes a random amount of time. After picking up the grocery items, a customer gets in the checkout line to pay for his/her items. The duration of the time spent in the checkout line is also random.
Programming Notes:
1. All random numbers in simulation have integer values and the time unit for the simulation clock is in minutes. Before starting to generate random numbers, call the function seed ( ) with the argument SEED = 1 to initialize the RNG. To get a random number in the range [ low, high ], execute: randrange ( low, high + 1 ). For inter-arrival times, the range is [ MIN_INT_ARR = 1, MAX_INT_ARR = 5 ]; for the time to pick up the grocery items, the range is [ MIN_PICK = 1, MAX_PICK = 10]; and for the service time in the checkout line, the range is [ MIN_SERV = 1, MAX_SERV = 4 ], which excludes the waiting time in line.
2. To capture the data values of a customer as a single unit, define a dictionary with keys: 'atime, ptime', wtime and dtime, where atime is the arrival time, ptime is the time of completion of picking up the grocery items and then entering the checkout line, wtime is the waiting time in the checkout line, and dtime is the departing time from the store of a customer.
3. For customers who are in the process of picking up the grocery items, define a list of dictionaries, where each element of the list corresponds to a customer.
4. To capture the statistical values as a single unit, define a dictionary with keys: 'num', pick, wait, serv and shop, where num is total number of customers departed from the store, pick is the accumulated grocery picking times, wait is the accumulated waiting times, serv is the accumulated service times, and shop is the accumulated time spent in the store over all customers.
5. In the main ( ) function, initialize the simulation clock to 0, initialize the events: next_arr, next_pick, next_serv, next_dept to 0, None, None, None, correspondingly, and initialize all statistical values to 0, where next_arr is the arrival time of the next customer, next_pick is the time of a customer who is next to finish of picking up the grocery items and then enter in the checkout line, next_serv is the time of a customer who is next to be served in the checkout line, and next_dept is the departing time of a next customer from the store. The main ( ) function calls one of the following functions for a given event at the clock time and updates the clock to the time of the next event. The simulation stops if the clock >= SIMTIME, where SIMTIME = 30 * 24 * 60.
6. After every event, you need to print the type of the event and the clock time of its occurrence, but since the clock runs for a long simulation time, limit the printing for only up to events but no later than the N = 10 departing events. In case, your program fails to generate correct simulation results, you can trace the output of your program using these printed values or trace your program with any value of N >= 1.
7. One of possible techniques to find the minimum value corresponding to a key in a dictionary, in a list of dictionaries, is a list comprehension method. Using this technique, you can create a list of the dictionary values, and then use the min ( ) function on the resulting list to get the first minimum value in all dictionaries for a given key. If you need to remove the dictionary from a list, you can use the index ( ) function on the list to get the corresponding index value, and then remove the dictionary from the list using that index value.
8. There are several constant values that you need to use in your program. It's a good idea to define those values in a separate file, say header.py, and import the file in your program prog8.py.
9. Before starting to execute your program, make it executable by the statement: chmod u+x prog8.py. For a final test, you can execute your program as: Make N=8. When the execution is over, the file prog8.out will contain the output, as well as the error messages (if any). You can find the correct output in file prog8.out, which is in the same directory with the data files.
10. In your program, do not use any global variables and try not to use any redundant variables and characters.
11. Your program needs to be fully documented. Without a proper documentation, a program does not carry much value to its users. As specified in the course syllabus, your program will be graded by three individual criteria: correctness, efficiency, and documentation.
12. At the top of your program, insert the following lines:
#!/usr/bin/python3
from random import seed, randrange
from header import *