The project for this week is to build a Passenger agent, build a Passenger Group data structure (based on the Priority Queue in lab), get the basic elevator simulation running, and then plan out a strategy for managing a set of elevators in a building with N floors and M elevators.
Documentation for Java 1.6 is located at: Java 1.6 SE API
The Documentation for the various simulation classes
This week you'll be provided with most of a simulation of an elevator system. Your task is to create the Passenger class (Cell child) and a PassengerGroup class (a priority queue). Once completed, you should be able to run the elevator simulation. Finally, examine the current Elevator agent code and come to lab next week with a strategy you want to implement for managing the elevators.
Create a Passenger agent class that extends Cell. It will need five fields.
- private boolean active - whether the Passenger is active in the simulation.
- private boolean onboard - whether the Passenger is on an Elevator.
- private final int startFloor - the starting floor of the passenger.
- private final int targetFloor - the target floor of the passenger.
- private int waitTime - the time the Passenger has been waiting.
In addition to overriding the abstract methods, Passenger should have the following methods.
- public Passenger(int start, int target) - constructor.
- public int getStartFloor() - accessor for startFloor.
- public int getTargetFloor() - accessor for targetFloor.
- public int getWaitTime() - accessor for waitTime.
- public boolean isActive() - accessor for active.
- public void setActive() - modifier for active.
- public boolean isOnboard() - accessor for onboard.
- public void setOnboard() - modifier for onboard.
- public String toString() - generates a useful string.
- public boolean isNeighbor() - returns false.
- public void updateState() - increments waitTime.
- public void draw( Graphics g, int x0, int y0, int scale ) - draws a circle of size scale.
Create two subclasses of Passenger that implement the
Comparator<Passenger> interface. The classes should be called
MaxFloor and MinFloor. Declare them as public static classes.
The Comparator interface requires implementing one function.
- int compare( Passenger A, Passenger B ) - returns -1 if A is less than B, 0 if A is equal to B, and 1 if A is greater than B.
For the MaxFloor class, the compare function should return a positive value if the target floor of A is larger than the target floor of B. For the MinFloor class, the compare function should return a positive value if the target floor of A is smaller than the target floor of B.
Create a class PassengerGroup that extends
MyPriorityQueue<Passenger> and implements
Iterable<Passenger>. The class should also have the following
- public PassengerGroup(int max) - constructor, use MaxFloor as the default comparator.
- public void useMaxFloors() - set the comparator to Passenger.MaxFloor().
- public void useMinFloors() - set the comparator to Passenger.MinFloor().
- public String toString() - generates a useful representation of a Passenger group.
Write a useful test main function for the PassengerGroup class.
Download the Elevator code bundle.
Add your MyPriorityQueue, PassengerGroup, and Passenger classes to the
directory and then compile everything. You will also need to add your
LinkedList implementation as the class MyLinkedList.
Run ElevatorSimulation and test the simulation.
- Read through the Elevator.java file so you have some understanding of how the Agent is managing its path. Design a strategy for managing an Elevator agent and bring it to lab next week.
When you have things working, move to the second part of this project.
This is a 2-week lab. During lab next week you need to show the professor your test functions for the MyPriorityQueue and PassengerGroup classes. You also need to be prepared to discuss your elevator strategy. During the second week of the lab you will implement your strategy.