COMP 2100 Project 3: Queuing System Simulation
Fall 2015
PHASE 2 : Develop and test the WaitingLine class
Due: in lab, Thursday 29 October 2015
20 points
PHASE 2 : Develop and Test the WaitingLine class
A complex project like this needs to be developed in phases. In the second phase, you will define
a class to represent a waiting line (queue) for the simulation framework and test it using a provided test driver.
Implementation Notes
- Here is a ZIP file that contains a folder of files you will need for development and testing of
WaitingLine: phase2.zip. Extract its files into your Pr3 folder, where the event classes
should already be.
- I am providing a stubbed-in version of the WaitingLine class (click for API). Your solution
will build on it.
- I am providing a complete version of the Customer (click for API) class, both because the WaitingLine
class needs it and because it is not interesting enough to assign.
- I am providing complete
Statistic
and WeightedStatistic classes (click for API), in case you are feeling
uncertain about the ones you wrote earlier this semester.
- I am also providing a partly-completed version of the Simulation class that contains the code
to test the WaitingLine class. You will test your code by running the Simulation class.
Simulation will be replaced in a later phase.
- The WaitingLine class will require at least three significant instance variables:
- an ArrayDeque<Customer> object for the waiting line itself,
- a WeightedStatistic object to gather queue length data, and
- a Statistic object to gather waiting time data
These variables will be updated within the enter() and leave() methods.
- The enter() method is used to place a customer into the queue. When this happens,
the queue length statistic needs to be collected since the queue length is about to change.
The simulation clock time also needs to be put into the customer's timestamp.
- The leave() method is used to remove a customer from the queue. When this happens,
the queue length statistic needs to be collected since the queue length is about to change.
The waiting time statistic also needs to be collected since the customer's wait is now over. Details below.
- Waiting time is calculated by subtracting the customer's timestamp
(time it entered queue, obtained from the customer object) from the current simulation clock time (time it leaves queue).
- Queue length, collected both upon enter and leave, is more difficult to collect.
It is a weighted statistic, therefore every queue length sample
also has an associated weight. The weight here represents time.
The Exercise 2
description uses a waiting line as an example. If the length is 1 for 2 time units then 2 for 8 time units,
the average length is 1.8, calculated from ((1 * 2) + (2 * 8))/10, not 1.5,
calculated from (1 + 2)/2. To correctly collect the queue length, you need to compute the length of
simulation time for which the queue length had the value being collected. Here's how to do it: define
an int instance variable, I'll call it timeOfLastChange and initialize it to 0 (zero).
Each time the queue length changes (this happens in both enter() and leave()), do two things in this order
(1) Subtract the value of timeOfLastChange from the current simulation clock value.
The difference is the weight for this weighted statistic and the queue length (before change!) is the value.
(2) Assign the current simulation clock value into timeOfLastChange. This updates it appropriately.
- The above descriptions make multiple references to the simulation clock value. The
only way to access this value is from the Simulation object using its getTime()
method. You can obtain a reference to this object at any time using the Simulation static
method getInstance(). Putting them together: Simulation.getInstance().getTime()
- The main() method in the Simulation class contains code to test WaitingLine methods.
To run the tests, compile and run Simulation.java.
Scoring
Points | Description |
9 |
the leave() method |
7 |
the enter() method |
4 |
remaining methods |
To Turn In
Zip your entire Pr3 working folder into a ZIP file with phase2 in its name. Then drop it into your DropBox.
[ COMP 2100
| Peter Sanderson
| Math Sciences home page
| Otterbein
]
Last updated:
Peter Sanderson (PSanderson@otterbein.edu)