Start by declaring an array of servers (shop checkouts) and a variable to indicate the number of servers. Each server element should contain members for the servers priority, customer finish time, idle (or busy) flag - and other variables for keeping the statistics to be printed at the end of the program. The server array can be a global or a member a class object with an appropriate name.
The main() should start by asking for a filename, then read from the file the number of servers and the priorities which are stored in the server array. Main() should then read the customer arrival events from the file and process them (as explained below).
To help process the customer arrival and server events you should implement a priority queue. The elements of the priority queue should contain thee members: the event type, event time and the service time (for customers). The element at the top of the priority queue has the smallest event time.
The event type can be a customer arriving at the shop or a customer completing payment at a server (i.e. checkout). For example, the test data file has 5 servers. You could use the numbers 0 to 4 to indicate when a customer completes payment at a server (customer complete payment event) and the number 6 (or -1) to indicate a customer arriving at the shop (customer arrival event).
You should also implement a FIFO queue for storing the customers that arrive when all the servers (checkouts) are busy. The FIFO elements should store the customers arrival time and the service time.
After initialising the server array from the file (and other objects), the main() should manage the events. The following algorithm is one example of how this could be done:
Read 1st CustomerArrival event from file and add it to the priority queue
do
Get next event from event priority queue
If Event = CustomerArrival
Add customer to customer FIFO queue
Read next CustomerArrival event from file
If not EOF add Event to event priority queue
Else // must be a CustomerCompletePayment event
Set server[Event] to idle (and do its stats)
End if
While customer FIFO not empty and idle server available
Get Next Customer from FIFO
Find fastest idle server (see note below)...
set server’s idle flag to busy
calculate server’s finish time (and do its stats)...
add CustomerCompletePayment event to priority queue
end while
While event priority queue not empty and FIFO not Empty and servers busy
Print stats
Note: to speed up finding the fastest server (i.e. checkout) you could use another priority queue!
You must write a program which models the operation of a shop using Discrete Event simulation: The shop has several servers, each of which has a different level of efficiency. This is measured by a time multiplier ei which differs for each server Si and works as follows:
If server i with efficiency ei serves customer j with service time tj the actual time taken to serve the customer is: ei x tj.
For example, if server 5 has an efficiency of 1.2 and customer 7 has a service time of 5.0 then server 5 takes a time of 6.0 to serve customer 7.
The input file contains the following information.
1. The number of servers. You may assume a maximum of 20 servers.
2. For each server: the efficiency of the server.
3. Arrival records consisting of the arrival time and service time of each customer.
Your program should:
1. Read the name of the text file from the console.
2. Read the information related to each server.
3. Read and process the customer arrival data.
Note:
1. There is a single queue of customers.
2. Each customer will be served by the server with the best available efficiency (the smallest value) from the available idle servers.
3. The servers are all initially idle.
4. Customers must be served in the order in which they arrive.
5. You should not attempt to read in all the arrival data at the start of the simulation.
At the end of the simulation, when the last customer in the file has been served, your program should print out the following information:
1. The number of customers served.
2. The time at which the last customer completed service.
3. The greatest length reached by the queue.
4. The average length of the queue.
5. The average time spent by a customer in the queue. (If a customer is served immediately, their queue time is 0.0).
6. For each server:
a. The number of customers they served
b. The time they spent idle.
You must choose appropriate data structures and algorithms to accomplish this task.
Note: A sample input file test.txt is provided for you to test your program. A larger text file may be used for final assessment.