Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A queue can be used to set up a simulation for customer checkout at a supermarke

ID: 3533026 • Letter: A

Question

A queue can be used to set up a simulation for customer checkout at a supermarket or customers handled by tellers in a bank. By running different scenarios, management can tell how many checkout lines to use or tellers to have on duty. The queue will hold an object of a customer in a checkout line with an id number, arrival time, and service time of 1-4 minutes, assigned randomly as the customer enters the queue Use the following algorithm:

Set up empty queue

Set current time = 0

Schedule the arrival for the first customer for some arbitrary value (t_arrival = 0 will be okay)

Loop 0 to maxtime (use 720 minutes

Explanation / Answer

#include queue int main() { //initialize arrival and departure time int custArrive, custLeave = 0; //set clock to zero int clock = 0; // set count to second customer int count = 2; // variables to track earliest next arrival and earlist next departure int earlyAr = 0; int earlyDept = 0; //variable to track next event int earlyEvent = earlyAr; //create list of customers list l; //create iterator for list list::iterator i; //create queue for checkout line queue q; //create stat object to store final statistics stat s; //create a customer object cust c1; //initilize with 1st cust data c1.atime = 0; c1.wtime = 0; c1.s_checkout = start_checkout(0); c1.id = 1; //add to list l.push_back(c1); //determine earliest next event custArrive = arr_time(clock); earlyEvent = custArrive; //update clock to time of next earliest event clock = custArrive; //Start of Simulation********************* // while simulation is still running while(clock s_checkout) { //create object to move cust from list to queue cust temp; //copy values from list item to queue item temp.id = i -> id; temp.atime = i -> atime; temp.wtime = i -> wtime; temp.s_checkout = i -> s_checkout; //insert element into queue q.push(temp); //if queue is empty(this is the only element about to be in queue) if(q.size() == 1) { //set wait time to zero q.front().wtime = 0; //use dept_time to obtain departure time custLeave = dept_time(clock); } //set departure as next earliest departure earlyDept = custLeave; } // if customer departed else { //remove customer from queue cust c = q.front(); q.pop(); //use dept_time and update wtime of next cust in queue q.front().wtime = clock - q.front().s_checkout; clock += dept_time(clock); //update stat structure update_fin_stat( s, c, clock ); } //determine next earliest event // if list isnt empty if(l.size() > 0) { i = min_element(l.begin(),l.end(), cmp); //find earliest checkout time } else { i -> s_checkout = (1000000); //set value to above sim-time } //if arrival is less than checkout time if(earlyAr s_checkout) { earlyEvent = earlyAr; //earliest event is arrival } //else the checkout time is less than arrival else { earlyEvent = i -> s_checkout; //earliest event is checkout } //if list not empty and departure less than earliest event if (l.size() > 0 && earlyDept