Question

Write a program that simulates a checkout line at a supermarket. The line is a queue...

Write a program that simulates a checkout line at a supermarket. The line is a queue object. Customers (i.e., customer objects) arrive in random integer intervals of from 1 to 4 minutes. Also, each customer is serviced in random integer intervals of from 1 to 4 minutes. Obviously, the rates need to be balanced. If the average arrival rate is larger than the average service rate, the queue will grow infinitely. Even with “balanced” rates, randomness can still cause long lines. Run the supermarket simulation for a 12-hour day (720 minutes), using the following algorithm:

a) Choose a random integer between 1 and 4 to determine the minute at which the first customer arrives

.

b) At the first customer’s arrival time, do the following:

Determine customer’s service time (random integer from 1 to 4).

Begin servicing the customer.

Schedule the arrival time of the next customer (random integer 1 to 4 added to the current time).

c) For each minute of the day, consider the following:

If the next customer arrives, proceed as follows:

Say so.

Enqueue the customer.

Schedule the arrival time of the next customer.

If service was completed for the last customer, do the following:

Say so.

Dequeue next customer to be serviced.

Determine customer’s service completion time (random integer from 1 to 4 added to the current time).

Now run your simulation for 720 minutes and answer each of the following:

a) What is the maximum number of customers in the queue at any time?

b) What is the longest wait any one customer experiences?

c) What happens if the arrival interval is changed from 1 to 4 minutes to 1 to 3 minutes?

Please note that a “minute “is what you define it to be. It could be an iteration etc. (I strongly suggest that it be “one iteration”)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution;

#include <stdio.h>

#include <stdlib.h>

#include "genlib.h"

#include "strlib.h"

#include "random.h"

#include "queue.h"

#define SimulationTime     720

#define ArrivalProbability    0.1

#define MinServiceTime        1

#define MaxServiceTime       4

typedef struct {

    int customerNumber;

    int arrivalTime;

    int serviceTime;

} *customerT;

typedef struct {

    queueADT queue;

    customerT activeCustomer;

    int time;

    int numCustomers;

    int numServed;

    long totalWaitTime;

    long totalLineLength;

} simDataT;

static bool traceFlag = FALSE;

static void InitializeSimulation(simDataT *sdp);

static void RunSimulation(simDataT *sdp);

static void EnqueueCustomer(simDataT *sdp);

static void ProcessQueue(simDataT *sdp);

static void ServeCustomer(simDataT *sdp);

static void DismissCustomer(simDataT *sdp);

static void ReportResults(simDataT *sdp);

main()

{

    simDataT simData;

    Randomize();

    InitializeSimulation(&simData);

    RunSimulation(&simData);

    ReportResults(&simData);

}

static void InitializeSimulation(simDataT *sdp)

{

    sdp->queue = NewQueue();

    sdp->activeCustomer = NULL;

    sdp->numServed = 0;

    sdp->totalWaitTime = 0;

    sdp->totalLineLength = 0;

}

static void RunSimulation(simDataT *sdp)

{

    for (sdp->time = 0; sdp->time < SimulationTime; sdp->time++) {

        if (RandomChance(ArrivalProbability)) {

            EnqueueCustomer(sdp);

        }

        ProcessQueue(sdp);

    }

}

static void EnqueueCustomer(simDataT *sdp)

{

    customerT c;

    sdp->numCustomers++;

    c = New(customerT);

    c->customerNumber = sdp->numCustomers;

    c->arrivalTime = sdp->time;

    c->serviceTime = RandomInteger(MinServiceTime, MaxServiceTime);

    Enqueue(sdp->queue, c);

    if (traceFlag) {

        printf("%4d: Customer %d arrives and gets in line\n",

               sdp->time, sdp->numCustomers);

    }

}

static void ProcessQueue(simDataT *sdp)

{

    if (sdp->activeCustomer == NULL) {

        if (!QueueIsEmpty(sdp->queue)) {

            ServeCustomer(sdp);

        }

    } else {

        if (sdp->activeCustomer->serviceTime == 0) {

            DismissCustomer(sdp);

        } else {

            sdp->activeCustomer->serviceTime--;

        }

    }

    sdp->totalLineLength += QueueLength(sdp->queue);

}

static void ServeCustomer(simDataT *sdp)

{

    customerT c;

    c = Dequeue(sdp->queue);

    sdp->activeCustomer = c;

    sdp->numServed++;

    sdp->totalWaitTime += (sdp->time - c->arrivalTime);

    if (traceFlag) {

        printf("%4d: Customer %d reaches cashier\n",

               sdp->time, c->customerNumber);

    }

}

static void DismissCustomer(simDataT *sdp)

{

    if (traceFlag) {

        printf("%4d: Customer %d leaves cashier\n",

               sdp->time, sdp->activeCustomer->customerNumber);

    }

    FreeBlock(sdp->activeCustomer);

    sdp->activeCustomer = NULL;

}

static void ReportResults(simDataT *sdp)

{

    printf("Simulation results given the following parameters:\n");

    printf(" SimulationTime:     %4d\n", (int) SimulationTime);

    printf(" ArrivalProbability: %7.2f\n",

                                   (double) ArrivalProbability);

    printf(" MinServiceTime:     %4d\n", (int) MinServiceTime);

    printf(" MaxServiceTime:     %4d\n", (int) MaxServiceTime);

    printf("\n");

    printf("Customers served:     %4d\n", sdp->numServed);

    printf("Average waiting time: %7.2f\n",

           (double) sdp->totalWaitTime / sdp->numServed);

    printf("Average line length: %7.2f\n",

           (double) sdp->totalLineLength / SimulationTime);

}

Add a comment
Know the answer?
Add Answer to:
Write a program that simulates a checkout line at a supermarket. The line is a queue...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I...

    Hello, I am having some trouble with a supermarket checkout simulation program in C++. What I have so far just basically adds customers to the queue and prints when they arrive. I am struggling with how to implement a way of keeping track of when a given customer finishes(I will attach what I have so far). I had already created queue and node classes (with headers and cpp files) that I modified in my attempt. I would be very grateful...

  • Queues This programming exercise introduces the Queue data structure. The students must create all the necessary...

    Queues This programming exercise introduces the Queue data structure. The students must create all the necessary methods for the queue and use the queue in a Java program. Step 1 - Create a new project in Netbeans Use the following naming convention: “Module4_Lastname_Assignment1”. Step 2 - Build a solution You have been asked to create a customer service program for a new phone store that will be opening soon. Since this company anticipates being the agent for a rising new...

  • C++ Sample run might look like this: How many minutes should the simulation run? 10 Running...

    C++ Sample run might look like this: How many minutes should the simulation run? 10 Running simulation for 10 minutes. minute 1: nothing happens minute 2: customer 1 arrives and will need 3 minutes to check out minute 3: nothing happens minute 4: customer 2 arrives and will need 1 minute to check out minute 5: customer 3 arrives and will need 1 minute to check out minute 5: customer 1 has checked out minute 6: customer 2 has checked...

  • A checkout counter at a supermarket completes the process according to an exponential distribution with a...

    A checkout counter at a supermarket completes the process according to an exponential distribution with a service rate of 6 per hour. A customer arrives at the checkout counter. Find the probability of the following events. a) The service is completed in fewer than 5 minutes. b) The customer leaves the counter more than 10 minutes after arriving. c) The service is completed in a time between 5 and 8 minutes.

  • Consider the M/G/1 queue with FIFO service (see Homework 6) Assume that (1) the arrival rate...

    Consider the M/G/1 queue with FIFO service (see Homework 6) Assume that (1) the arrival rate is 1 customer per minute, and (2) the service times are exponentially distributed with average service time 45 seconds. 07. Find the server utilization 88. Find the average value of the waiting time (in minutes). 9. Find the probability that an arriving customer will wait in the queue for at least 1 minute. 10. Find the probability that an arriving customer who finds the...

  • Consider a simple queuing system in which customers arrive randomly such that the time between successive...

    Consider a simple queuing system in which customers arrive randomly such that the time between successive arrivals is exponentially distributed with a rate parameter l = 2.8 per minute. The service time, that is the time it takes to serve each customer is also Exponentially distributed with a rate parameter m = 3 per minute. Create a Matlab simulation to model the above queuing system by randomly sampling time between arrivals and service times from the Exponential Distribution. If a...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Java Project For this assignment, you will write a simulation program to determine the average waiting...

    Java Project For this assignment, you will write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: delete the addfirst, addlast, and add(index) methods and instead include a single add method...

  • In Java, complete the following: During the lunch hour, the ATM machine in a large office...

    In Java, complete the following: During the lunch hour, the ATM machine in a large office complex is in heavy demand. Customers complain that the waiting time is much too long. The local bank considering the addition of a second ATM machine. But first, the bank needs a few statistics to justify the cost of adding a second ATM machine. Using a Queue, simulate a waiting line at the ATM machine for a period of one hour. Make the following...

  • For the following problems compute (a) utilization, (b) average time a customer waits in the queue,...

    For the following problems compute (a) utilization, (b) average time a customer waits in the queue, (c) average number of customers waiting in the queue, (d) average number of customers in service, (e) the average time a customer spends in the system. Problem 1. An average of 10 cars per hour (with variance 4) arrives at a single-server drive-in teller. Assume that the average service time for each customer is 5.5 minutes (with variance 5). Problem 2. Customers arrive to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT