The purpose of this assignment is to continue your work with linked lists and learn a little bit about how discrete time simulations work. The scenario to be simulated is a set of users (1 through NumUsers) who send and receive email messages.
There will be several different event files for testing your program. You should deal with different numbers of users and events. The format of a 5-event 2-user file is as follows:
event_id event_type time
receiver_id sender_id priority
message
1
R 670
20
2
S 652
10
10 1
Assignments are so easy
3
R 946
10
4
S 362
10
20 1
Midterm is coming soon
5
S 561
20
10 3
CSE373 is interesting
Download more event files: 10E-1U 20E-2U 100E-3U 200E-4U. Running EventGenerator.java, you can generate any event files by specifying the numbers of events and users. There is a Java program ReadEvents.java, and a C++ version ReadEvents.cpp, illustrating how to read each field in an event from an event file that is given as a command line argument, do some computation, and output formatted events to a file. If you are not familiar with I/O, please read the example carefully.
The job of the simulator is to remove events from the Event_Queue and simulate their executions. For a sending event, the simulator must invoke the proper methods to put a message on the Mail_Queue of the specified receiver in the right position. For a receiving event, the simulator must read and remove the first message from the queue of the receiver and print its time, receiver_id, sender_id, priority and text message to a result file mails.txt (one receiving event each line). If there are no message in its Mail_Queue, output "No recent messages" to mails.txt. After simulating an event, the simulator just goes right back to the Event_Queue to get another one. It stops when the Event_Queue becomes empty.
The
only input to your program is an event file, specified by command line
arguments. Do NOT prompt for any other user-input.
The only output from your program is mails.txt. Do NOT output anything else.
For example, given the 5-event 2-user file above, the output mails.txt should be like:
time receiver_id sender_id priority message
561 20 10 3 CSE373 is interesting
362 10 20 1 Midterm is coming soon
1. Compilable. Any program that cannot compile will receive a low grade.
2. Correctness, based on the output file mails.txt, which will be generated by running your program.
3. Clearness of code, good coding style, simpleness, etc.
4. Readme.txt, explaining how you implement the Mail_Queue, the Event_Queue, and the simulator. Also mention how you implement your insertion routines and in which files these insertions are. The insertions into the Mail_Queue should be done in O(1) time and you must do it the most efficient way possible. In your code, please label the insertions.
5. Testing: we run your program with
command line arguments, using the above 4 files and 2 more files 20E-2U-2,
100E-3U-2.
The results are:
10E-1U-mails
20E-2U-mails
100E-3U-mails
200E-4U-mails
20E-2U-2-mails, 100E-3U-2_mails
All source files should be turned in online.
Java programmers: Make sure your program is compatible with Java2 SDK 1.4.x. Turn in only .java source files. You must include your main method in Simulator.java. Go to http://www.cs.washington.edu/education/courses/373/03sp/homework/prj1/turnin-java.html
C++ programmers: Your programs are strongly suggested to be compatible with MSVC 6.0. By default, your program will be compiled by MSVC 6.0 compiler at turn-in time. If your program only works on Linux/Unix, you must include detailed information in Readme.txt showing how to compile and run your program. Turn in only .cpp and .h files. You must include your main function in Simulator.cpp.