Back to 211 Main Page

Mobius strip

Assignment 4

The Assignment

http://learnu.ics.hawaii.edu/~nickles/211_Spring_2005/labs/ queue/EventQueue.html

Submission

  • Email your assignment to ztomasze@hawaii.edu.
  • Attach the source code of your Java application. Send me only the source code (.java files); do not include the .class or any other files. Do not zip or otherwise bundle the .java files.
  • Send me all the files needed to run your simulation. (However, do not change Queue.java.)

Recommendations

Queue

The first part of this assigment is to write a queue. It should implement the Queue interface given by Nickles. You must use singly-linked nodes to implement it. (Hint: reuse your stack node.) For your convenience, here is a zip file containing the interface, two exceptions, and a grader for your Queue. (You may write your own exceptions or expand these to take string messages if you want to.) You will not need to throw the QueueFullException, since your linked-list implementation won't have a capacity limit.

Event Queue

There are a number of ways do write this simulation. It is possible to do it without a queue at all, but you are required to use a queue. Even when using a queue, there are at least 4 different ways to do it. I will go over these differences in lab, but briefly they are as follows:

Job Queue. If you never use a JobEndEvent, you are using a job queue. In this implementation, the queue does not "control" the printer. Rather, the printer controls the queue. The printer processes the first job in the queue. Only once it has finished the job does it look at the next thing in the queue. This is probably the easiest implementation to do. However, it is less flexible in the long run, since you are not processing events (only jobs). If you write your simulation this way, it will -0.5 points (which may be worth it if you can finish the assignment early doing it this way).

"Event" Queue. If, every time you start processing a new event, you always put the JobEndEvent at the start of the queue (in front of all the other print jobs), it seems like you are doing a true event queue. However, since no other event is ever processed until after the JobEndEvent, this has the same functionality as a job queue.

Event Queue--with dynamic job creation and processing. This is the approach shown in Nickles's psuedocode. Since you have the pseudocode, this will probably be the best approach to do for this assignment.

Event Queue--with Priority Queue. In true event simulations, you usually use a priority queue. When adding to a priority queue, the object is inserted in sorted order rather than just at the end. This means you have less processing of events to do. If you would like to use a priority queue, you may. However, you must still submit a normal queue as well. (Hint: have a look at java.lang.Comparable, and make all your Events comparable. You may subclass MyQueue to create MyPriorityQueue and just override the enqueue method.)

Final Comments (04 March)

  • You may rename any of the classes for the simulation part of the assignment (the simulation, printer, events, etc).
  • Look at the Grading section and prioritize--what's most important to get done? What's the best way to spend your time on this assignment?
  • You may want to start with a "job queue" approach. You can always change it or expand it when you're done if you have time.
  • Focus on getting the correct simulation data.
  • Don't think in front of the computer. Plan your approach on paper. Only once you have an idea what you want to do, start writing code. If you get stuck on a design issue (rather than a coding bug), take a break away from the code to think about it.

Grading:

Out of 10 points:

1.0 - Compiles
2.0 - Documentation and coding standards
As always, document all your classes and methods.
2.0 - Queue
Implements the given interface, and uses singly-linked nodes.
1.5 - Simulation design
Should use a queue and the other classes described on the assignment page. The Printer class should contain the details about the printer (page print rate and page capacity). Should process events.
2.5 - Output
Each time your simulation runs, it should print out at least the following information:
  • total number of pages printed
  • number of print jobs handled
  • average page count per print job
  • average wait per print job
  • number of times the printer was reloaded
This information should be in a readable format, and the numbers generated should be correct for the given parameters.
1.0 - Maintainable parameter set.
The values for the parameters for this simulation--the 0-60 seconds between each successive print job, the 1-100 print job size, the printing rate of the printer (30 pages/minute), and the paper tray capacity of the printer (1100 pages)--should each occur in only one place in your code. This might be as constant variables, parameters to a constructor, initialized instance variables, etc. These numbers should NOT be scattered through-out your code. I want to be able to change each of these values in the single place they occur, recompile, and run the simulation again with the new parameters. (You may write your simulation to get this data from the user, but that is not necessary.)

Solution

Zach's Solution (zip file). See the README.txt file in the zip for a brief overview.

Solution updated 20 April: I found a small bug in JobSimulation in scenarios where there are not big backlogs of jobs. (Basically, I forgot to update the current time if the printer had been sitting idle until the next job.)

Notes on grading and results

I based my evaluation of your simulation code's correctness (worth only about 1.5 of the total value of the assignment) on your output. I ran both the original simulation and another set of parameters. If you have any questions, here are the numbers I was looking for:

Original Setup:
1 to 100 pages every 0 to 60 sec
printing a page every 2 sec
with a capacity of 1100 page
for 28800 sec
Average results
~14350 pages printed in ~280 jobs
~50 pages a job
average wait of ~10,100 sec/job
13 reloads (occassionally 12)
2nd Setup:
1 to 50 pages every 0 to 100 sec
printing a page every 1 sec
with a capacity of 1000 page
for 3600 sec
Average results
~1800 pages printed in ~73 jobs
~25 pages a job
average wait of ~7 sec/job
1 reload (occassionally 2)

These results are approximate medians; the range was sometimes rather large. I ran each version 4 to 10 times to see if the numbers were close.

Occasionally a submission would produce results within the acceptable range, but would always be lower or higher than the average. I usually just called these correct, but be aware I'd would recommend more exhaustive testing before relying on them if they were part of a real project.

If you still have questions why your code is incorrect, let me know. We can meet and go over your code.



~ztomasze Index : TA Details: ICS211: Assignment 4
http://www2.hawaii.edu/~ztomasze
Last Edited: 20 Apr 2005
©2004 by Z. Tomaszewski.