Simulation: Queues, Priority-Queues, Random Number Distributions

Simulation: Queues, Priority-Queues, Random Number Distributions

Computer Science 2210 - Project 4

Simulation: Queues, Priority-Queues, Random Number Distributions

November 2018


The purpose of this assignment is to obtain experience with the C#Queue,and PriorityQueue classes, the random number class, and with computer simulations.

Your company has been hired by the management of a new supermarket that is going to open ata prime locationin your city.

The supermarket is initially planning to be open from 8 am until midnight(16 hours a day) and serve an expected 600 customers (random number from the Poisson distribution) each day. The managementwants to determine how few checkout lanes it can install and staff to serve its customers without having any lines exceeding two customers (one being serviced and one waiting). Experience at other similar supermarkets has shown that it takes an average of 5 minutes and 45 secondsto process one customer, and no customer takes less than two minutes to be served.


Write a C# program to simulate the operation of thecheck-out lanes at the new supermarket.

You may assume that customers arrive at the check-out lines at the supermarket according to a uniform distribution throughout the entire day’s hours of operation.

The time required to process a given customer once he or she has reached the front of the checkout line is determined from a (negative) exponential distribution.

Create classes for Customer and Event. For the purposes of this assignment, an Event is a customer entering aline waiting at a register or a customer leaving the register line when he/she has been processed.

A customer does not begin to check out, obviously, until reaching the front of the register line.

The Supermarket class should manage the simulation using the Customer and Event classes and the data structures needed.

Though the supermarket’s managementexpects a certain number of customers per day and a certain number of hours of operation each day, they want your solution to be flexible enough to be able to answer “what if” questions such as:

  • What if we stayed open a half-hour less?
  • What if we expecteda different number of customers on the average?
  • What if the expected service time or the minimum service time at a register changes?


Use aPriorityQueue to manage the Events, and use a Queue of Customers to simulate a single line of customers at a register. Use a ListQueue<Customer> > to simulate the collection of lines at the registers. The goal is to find the smallest number of Queues the List must have to be sure the individual register lines do not exceed two customers in length. You may make these assumptions.

  • Customers always enter the shortest line and that, once in a line, they do not change lines.
  • The supermarket will remain open until the last person completes his/her service, but no one will enter a checkout line after closing time.
  • During execution, you should display enough information in sufficient detail to show that your simulation is working and that you are tracking the proper pieces of information. This should include (but is not limited to) pseudo-graphical information showing the simulation in progress.
  • The design of the user interface is up to you, but it must be such that you are able to convince your customer that your answer is correct and not just some numbers you made up.

Your program should be flexible enough so that if the supermarket decided to stay open longer, close earlier, handle more (or fewer) customers, or deal with a situation in which the expected service time changes, you could provide a reasonably quick solution to the problem for the modified set of parameters. You may use a Windows Forms solution or a menu-driven console application for your project.


The following hints and/or suggestions should be considered in designing this program. You are not required to use these, but you should consider them and be able to show why you found an alternate approach to be better.

  • Begin by generating all Customer objects with their random arrival times and the random amounts of time required to be served once they reach the front of their checkout queues. Then, enqueue the arrival events in the PriorityQueue.
  • Exit events cannot be determined easily until customers reach the front of register lines, so exit eventsmust be generated at that time. Enqueue an exit event for a Customerobject when the customer reaches a register and can begin checking out.
  • Keep track of all of the information that you need, but not more than that. For example, it is important to be able to identify individual customers for tracking purposes, but that does not mean they have to have names.
  • Simulate the operation of the supermarket for each number (1, 2, 3 . . .) of checkout lines until you think you know what the correct minimum is.
  • Because different sets of random values may generate different queue lengths, you should make several runs with N, N-1, and N+1checkout lines when you think the answer might be N. You do not want your answer to be correct on one particular day but incorrect on many/most others.
  • Keep track of the maximum line length for all scenarios so that you can report on your findings.
  • You set expected values for items such as length of service interval and number of customers per day. Display actual values or averages for such at the end of the simulation (or some other appropriate time).
  • The granularity of your time calculations can impact the accuracy of your solution. For example, if you time all events to the nearest millennium, your answer will not be as accurate as if you time to the nearest yoctosecond. All time calculationsfor this assignment should be done in seconds.
  • It is not necessary or even helpful to maintain a “clock”. A clock adds unnecessary complexity.Do not use a clock or other timer. The museum example did not use a clock – it did not need one either.
  • The program should be user-friendly – remember that you must have and display sufficient data to convince the customer that your solution is correct. The display must be convincing without being overwhelming. A display that simply lists all events, the times they occurred, etc., and leavesit to the reader to extract the useful information from the display would not be considered very helpful.
  • Documentation is NOT optional. See Documentation Policies on the web site.


Write a short, Microsoft Word report (one page or so, but not too skimpy) on your findings and your recommendations to the supermarket’s board of directors (who hired you to do this project). Your report should include headings, sections if needed, dates, and authors. Spelling, grammar, and readability are factors in grading the project. Zip this report and your complete projectinto a folder. Submit as usual as with previous assignments. Be sure to include both the grader and instructor as recipients.

You may work in groups of two or three on this assignment. Be sure to include the names of everyone in the group in all appropriate places such as the zipped file, the program documentation, and your written report.

Don Bailes / Page 1 / Simulation Project