CSE logo University of Washington Department of Computer Science & Engineering
 CSE 142 Winter 2003 -- Project 2
  UW Home     CSE Home   Message Board    Contact Info 

CSE 142
 Home page
 Syllabus
Classwork
 Calendar
 Homework
 Projects
 Exams
 Quizzes
Software & Computing
 Programming Lab Info
 Computing at Home
 Java Libraries
 Troubleshooting
Staying in Touch
 Discussion Board
 Virtual TA
 Announcement Archive
 Mailing Lists
Staff
 Instructors
 TAs
 Consultants
 Consultant Schedule
Check Your Scores
 MyUW
   

CSE 142 Project #2: Elevator Simulation

Part A Due With Homework 4: Wednesday, February 19 at 9:00 PM

Project Code Due: Wednesday, February 26 at 9:00 PM

Individual Written Reports Due: Friday, February 28 at 9:00 PM

Directions: You should complete all design work, specification, coding in Java, testing of code, and code documentation with your assigned partner. Please work with your partner on all components in front of the same computer using the pair programming style described in the Williams/Kessler paper and demonstrated in lecture. When working on the computer, you should normally switch roles every 10 or 15 minutes. One person is the driver (the person controlling the keyboard and mouse) while the other is the navigator. The navigator should help the driver by pointing out flaws in specification, code, and documents. The navigator also keeps track of your goals and helps the team accomplish steps to reach those goals. We ask that you work on projects in this manner so you learn to work with another student in the course and you learn to assist one another. Each member will bring strengths to the team. We hope you learn how to complement your strengths and the strengths of your partner to complete this project.

When you are finished with the project, you will turn in one set of Java files for the team. Each member should be satisfied with the content of these files. You may submit project files more than once (You are encouraged to submit files early and often!). We will grade the final set of files you submit electronically.

Once your team is finished with the Java files, each member of the team will write a project report individually and submit this by Friday, February 28. Details about what should be included in project reports can be found on this web page. Please read through the project report guidelines as you work on your project; the guidelines will help you take notes about the project as you complete the steps. Use this project report turnin page to submit your report.

Grading guidelines: Your team will receive the same grade on the Java programming part of the project. Your code will be graded on a scale from 0 to 4 in two categories:

  • Design, specification, implementation, code style, and test cases used (code quality)
  • Functionality of code and adherence to project specifications (code operation)

You will receive an individual grade based on your written report. Your written report will be graded on a scale from 0 to 4 in two categories:

  • Technical content of the written report
  • Writing style

The project is worth a total of 16 points. You can find more details about how this project will be evaluated in this grading guide.

Project Specification:

The Elevator Company has hired your team to design algorithms to control an elevator and then analyze those algorithms in terms of waiting times for people using the algorithm. The company has given you the infrastructure to run a simulation of the algorithms. A simple graphical interface shows the elevator in action, the people waiting on each floor, and the number of people in the elevator. The company's wish is for your team to design and evaluate the best algorithm to quickly service and transport people where they want to go quickly. Good luck on your algorithm designs!

Description of Starter Code

The Elevator Company is providing you with an initial simulation and naive algorithm to operate the elevator. The code consists of the following classes (classes with ** are those that you should modify while completing the project):

Class Name                            Starter Code                               

Elevator Controller **      ElevatorController.java
Naive Elevator Algorithm ** NaiveElevatorAlgorithm.java
Test Naive Algorithm ** TestNaiveAlgorithm.java
Person  Person.java
Viewer  Viewer.java

 

Interface Name                        Starter Code

Elevator Algorithm                   ElevatorAlgorithm.java

 

The purpose of each class is explained in turn, in order to help you read and understand the existing code.

ElevatorController: This class contains the information about the simulation world, runs the simulation, moves the elevator to a given floor, and loads/unloads people into/from the elevator. Important pieces about the simulation world include the number of people waiting on each floor, the capacity of the elevator, the total number of people in the simulation, the algorithm used to control the elevator, a list of people in the elevator, and the number of elapsed clock ticks. You may ignore (and should ignore) all code that operates the simulation. This code is marked as such in the Java file. You are welcome to add more methods to this class to help create good elevator algorithms. Do not remove any code having to do with clock increments since some actions do take time. If you add elevator methods to the class that do take time (unloading people, loading people, moving up a floor, moving down a floor), be sure to increment the clock accordingly inside these methods.

NaiveElevatorAlgorithm: This class contains the implementation of a naive elevator algorithm. The starter code simply has the elevator pick up the person who has waited the longest and drop them off at their target floor. It is not too intelligent since it does not make use of the elevator's capacity. The important pieces about this class include the move method (which decides how to move the elevator given the state of the ElevatorController) and the setController method. This class implements the ElevatorAlgorithm interface, which means that NaiveElevatorAlgorithm must implement the methods move and setController. Every algorithm class you create should implement the ElevatorAlgorithm interface.

TestNaiveAlgorithm: This class includes the main method that serves as the starting point of the program. It simply creates the ElevatorController, creates the algorithm, runs the simulation, and returns the statistic about the total waiting time for all people in the simulation. You should write your own classes that include main to test out your algorithms.

Person: This class simply represents a person in the simulation. Important properties of a Person include the target floor, the starting floor, and the total waiting time. You should not need to modify this class.

Viewer: This class operates the graphics to represent the state of the simulation. You should not need to modify this class.

ElevatorAlgorithm: This interface represents the interface for all elevator algorithm classes. All elevator algorithm classes should implement this interface and should define the methods for move and setController. See NaiveElevatorAlgorithm for an example of how a class implements an interface. You should not need to modify this interface.

Project Part A

1. Your first task is to run the starter code. Download all starter code, compile it in Dr. Java, and in the interactions window type:

java TestNaiveAlgorithm

You should see a window containing a simple graphical interface of 5 floors and an elevator. The people are represented by yellow circles and the numbers inside the circles are their target floors. The elevator is a rectangle and shows how many people are currently in the elevator. Helpful messages about the simulation are printed on the simulation window and the interactions window. The simulation takes a while to complete (202 clock ticks), so you may want to stop the simulation. The simplest way to stop the simulation in DrJava is to reset the interactions window.

If you want the simulation to run faster or slower, you can change the constant defaultDelayBetweenStepsMilli in class ElevatorController to specify a shorter or longer delay between steps in the simulation.

2. Investigate the class definitions of the ElevatorController, NaiveElevatorAlgorithm, and TestNaiveAlgorithm. Keep in mind the class descriptions above when looking through the code. If you are unsure of what you see, you can always look at the online Java documentation. Investigate the NaiveElevatorAlgorithm code in the move method. Make sure you understand what it is doing.

3. The naive elevator algorithm is rather naive. It does not use the full elevator capacity and only serves one person at a time. Implement the following enhancement to the algorithm. When loading the person who has waited the longest, check to see if other people are waiting for the elevator. If there are other people waiting on the floor with the person who has waited the longest, then load those people at the same time. Deliver everyone in the elevator where they want to go. [Of course, you can only load as many people as the elevator's capacity.] To complete this implementation, you'll want to modify the NaiveElevatorAlgorithm class and the ElevatorController class. For example, you'll want to write a method in the controller that will load as many people as possible from a given floor. For this part of the project, you may modify these files and TestNaiveAlgorithm.java files only. Do not modify the other three starter files.

4. Test your improved naive algorithm by using the TestNaiveAlgorithm class. If it does not work as intended, debug your code and try the test again.

5. Simulations are only useful if statistics are gathered and algorithms are compared based on these statistics. The starter code includes a method to calculate the total waiting time [includes time standing on floor and in elevator] for all people in the simulation. In the ElevatorController class, implement two more methods: Add a method that calculates the longest time any one person waited. Add a method that calculates the shortest time any one person waited. Be sure to call these methods from the TestNaiveAlgorithm class once the simulation is over, so the numbers will be printed.

6. Once you are confident that your algorithm is working, record the total waiting time of the people, the total number of clock ticks, the maximum waiting time, and the minimum waiting time. You'll want to save these numbers to include in your written report.

7. Turn in the modified class definitions using the turnin form with homework 4. You should turn in: ElevatorController.java, NaiveElevatorAlgorithm.java, and TestNaiveAlgorithm.java. These files will be compiled with copies of the original versions of the other elevator program files, which are already stored on the turnin server (you do not need to submit these files for this part of the project). The files you and your partner submit should be identical.

Project Part B

Please read the entire description before starting part B.

The Elevator Company would like "smarter" algorithms designed and implemented in the simulation before building the controller of a real elevator. Your job is to design and implement two algorithms (different from the naive algorithm and the enhanced naive algorithm). Once the algorithms are implemented, gather statistics about the algorithms to evaluate their effectiveness.

When designing the new algorithms, create new classes that implement the ElevatorAlgorithm interface. Also, create test classes for each algorithm. This will make your job easier by keeping code for different algorithms in separate classes. Remember, designing algorithms takes quite a bit of paper and pencil work before any implementation can occur.

Be sure to test your algorithms thoroughly. You can create different simulation scenarios by changing the number of floors and the number of people in the simulation. To do this, you'll want to create a constructor in the ElevatorController class that takes in the numberOfPeopleMax (in simulation) and the numberOfFloors and sets these values appropriately. Then, in the test classes, you can specify your simulation scenarios by using the parameterized constructor in ElevatorController. 

The simulation creates people at random using a random number generator. You do not need to understand how this code works. A random number generator takes a seed (an initial number) to get the sequence of numbers started. The seed is set in ElevatorController to make your testing easier (the people should always arrive in the same sequence each time the simulation is run). Once you are confident that your code works, you can try "random" arrivals by changing the randomSeed class variable in ElevatorController.

Once you have your algorithms implemented and tested, analyze your algorithms. Look at the statistics gathered (total waiting time, total clock ticks, min wait time, max wait time). You may find that you want additional statistics, and you are welcome to implement methods that calculate those. For example, you may want the mean and standard deviation of wait times. You may want the mean wait times for people who started on each floor. Record these statistics for the algorithms. You should gather these statistics for various simulation scenarios (with different numbers of people and different numbers of floors).

Make a chart/table/graph of the statistics you gathered and paste these into a Word file (.doc) or any other file format that is readable by Microsoft Word. As a team, write a short report about your analysis. You may want to answer questions such as:

Which algorithm seemed to be the most efficient (getting people where they need to go in the fewest clock ticks) and why? Did one algorithm outperform the other in certain situations? Does the algorithm make certain people wait longer than others? What are the unique characteristics of your algorithms? Do you have suggestions for improving the algorithms? Does the algorithm favor people on certain floors over others?

Hints: Things to think about when designing the algorithm:

1. It seems reasonable to fill the elevator when possible.

2. It seems reasonable to first fill the elevator with people who have waited the longest.

3. The elevator movement may depend on whether people want to go up or down.

4. Where should the elevator stop if no one is waiting for it?

When you are finished, turn in all of the Java files that make up your program, your test cases, and the ElevatorController. Also, turn in the document containing your analysis. Use this turnin form to submit these files. You and your partner should turn in only one copy of the files with both of your names on them.

Additional Enrichment:

[If you have time after you have finished parts A and B, feel free to try the following tasks.]

  • The graphical interface for the elevator is somewhat simple. Modify the Viewer class (yes, you may modify this class if you do the additional enrichment) to enhance the graphics. One enhancement would be for the people to turn more red (as they get more angry) as their wait time increases. You could also include the people objects in the elevator instead of showing the elevator capacity. Feel free to make the graphical interface more interesting. You may need to modify the Person class to include more properties.
  • Perform more analysis on the algorithms by changing the capacity of the elevator. How does the capacity of the elevator affect the statistics gathered about the algorithms?
  • [Very challenging] The ElevatorController controls just a single elevator at the moment. Re-design the classes so that the ElevatorController controls more than one elevator to serve the people. You'll probably want to modify the Viewer to show multiple elevators. This enrichment is very challenging since it involves code re-design and new algorithms to control multiple elevators.


CSE logo Department of Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
[comments to cse142-webmaster]