The Elevator Problem
Problem Specification:
You have been hired
by an airport to build a controller for an elevator in the 10 floor
terminal building which is used by people going from floor to floor
(some of whom have trolleys with baggage). The elevator is represented
as a thread. Each
person boarding or leaving the elevator is also represented by a
thread.
You would need to implement the methods called by the arriving person.
e.g. a method ArrivingGoingFromTo(int
atFloor,
int toFloor) should wake up the elevator (if necessary) and tell
it which floor to go to. The elevator is fast but it is not
instantaneous,
it takes only 100 ticks to go from one floor to the adjacent one. For
simplicity,
you can assume the following:
- There is only one
elevator and it holds 10 people of arbitary weight obviously this is
affected by the trolleys (as a first approximation you can take these
to be of fixed weight, say equal to that of two people).
- The elevator
'knows' the details (weight, ID, arrival floor, destination floor
etc) of the people when they enter.
- There is only one
person entering the elevator at a floor at a time.
- The elevator
ascends one floor at a time without skipping floors.
- When not in
service, the elevator waits at the last floor it visited
and
'sleeps'
You have to come up
with
a way of storing the requests to the elevator e.g. if a person is
accessing
the elevator at the 3
rd floor and some body is trying to get
access from the 5
th floor then latter person has to wait
before
he could place his request. In other words (s)he has to be put in a
queue.
Also if the elevator is going upwards all the requests for the
destinations
downwards should not be accepted until it starts its downward motion
and
vice versa.
These specifications are for the "vanilla option" of the
implementation.
Any form of creativity that you feel like putting in that will add
interest
to my marking of the project (variable weight trolleys, GUIs, multiple
elevators, 'smart'
elevators
etc) is encouraged. The marks awarded for the project will
reflect
this.
The assignment has
to be done in Java.
Hint:
The program will
have
two major classes “elevator” and “person” both of which will extend the
Java thread class (or extend runnable
interface). Each "person" should be generated with a random
arrival
time, arrival floor and destination floor and have a unique ID for
identification
purposes.
In order to simulate
the
100 ticks between the two consecutive floors, you can use the
“wait
(100)” construct. You can refer to the website http://java.sun.com/docs/books/tutorial/essential/threads/waitAndNotify.html
for details of how to use “wait” for this purpose.
You can assume 100
ticks
is equivalent to your 1 unit of time (discussed above).
In order to compile a
java
code, you first have to run the java compiler with “javac
<filename>“
and after it gets compiled execute it with “java
<filename(executable)>”.
Command line
parameters
are permissable.
Output file:
The format for the
output
file should be something like following.
“Person (Thread
ID)
# makes request at time # starting at floor # with the destination
floor
#.”
There should be as
many
lines printed as are the number of requests. You should also
generate
an output file output.dat to
store your output.
Note: You must
assume
that you the starting time for the first request is 0.
Deliverables and
instructions for submission:
- Please also write
a short (5 page max) design documentation which may
get
you some partial credit if your program does not execute.
- You have to turn
in all you source files, documentation and also all
the
generated class files for the unix platform.
- Mail the above to
me with a statement that you have done it yourself except
the parts where otherwise stated and that you are aware of the
University
rules concerning plagiarism at
http://www.compapp.dcu.ie/current/policy/plagiarism.htm
- Deadline for
submission is the last friday before Christmas, eg Friday 18th of December 2009 at 5.00pm.
Good
luck!