Elevator
Simulation Design Notes
Class Light
Definition: Light object is for the light on the the floor, When the
elevator arrive, the light is turned on, if the elevator departs, then
the light is turn off
Attribute:
status : to store the current light status
the default is off. two states: OFF, ON
Behaviors:
turnLightOn()
Begin
: set status on
End
turnLightOff()
Begin
: set status off
End
isLightOn()
Begin
: return the status of light
End
---------------------------------------------------------------------------
Class Door
Definition: Door of the elevate and door of the the floor, two doors are
behavior at the same time. but they have the different name
Attribute:
name : door name, in this project, we have elevator_door, floor_door
status : there are two states: OPEN, CLOSE
Behavior:
OpenDoor()
Begin
: set status to OPEN
End
closeDoor()
Begin
: set status to CLOSE
End
isDoorOpen()
Begin
: return the value of status,
if Door is open, return true, else return false
End
---------------------------------------------------------------------------
Class Button
Definition: Button in the Elevator and up and down button in Floor
Attribute:
status: button status which has either on or off,
Behavior:
turnOnButton()
Begin
: turn on the button by setting status = ON
End
turnOffButton()
Begin
: turn off the button by setting status = OFF
End
isButtonOn()
Begin
: to determine the button is On if status equal to ON
return true, else return false
End
---------------------------------------------------------------------------
Class Clock
Definition: Clock for the elevator, just like a count,
Attribute:
current_time : the current_time of simulation
Behavior:
ticking()
Begin
: increment time by 1
End
getCurrentTime()
Begin
: return the value of current_time
End
---------------------------------------------------------------------------
Class Person
Definition: a person know the current floor and his destination and also
his number name
Person ( current floor, destination floor, Floor)
Begin
wait on Floor(Floor, destination)
note: Floor is to keep trace of current floor
End
Attribute:
current_floor : current floor number
dest_floor : destination floor number
number_name : the sequence integer name of person
Behaviors:
waitOnFloor(Floor&, destination);
Begin
indicate the person is waiting on that floor
indicate person arrived person press floor button up or down
End
enterToElevator()
Begin
: indicate he would enter the elevator
End
pressFloorButton()
Begin
: person would press floor button to call elevator
indicate person press the floor button
End
---------------------------------------------------------------------------
Class Floor
Definition: Floor in the building, in this project, we have floor1 to floor3
Attribute:
Person *ptrToPerson : a pointer to Person, null if no person in that floor,
Door floor_door, : floor door, open and close with elevator door
Light light : light is on if elevator arrives
Button floorbutton : this button on the floor is a call button, if it
is pressed, elevator is called.
int floor_number : number of the floor, 1, 2, 3
Elevator *ptrToElevator, elevator which at that floor
Behaviors:
personArrived()
Begin
: indicate a person arrive at that floor
End
personDeparted()
Begin
: indicate a person will leave after 8 second, departure events
End
turnLightOn()
Begin
: turn floor light on by set light status to ON
End
turnLightOff()
Begin
: turn floor light off by setting light status to OFF
End
openFloorDoor();
Begin
: open the Floor door by setting floor_door status to open
End
closeFloorDoor();
Begin
: close the Floor door by setting floor_door status to close
End
isLightOn()
Begin
: get the light status
End
pressFloorButton()
Begin
: the person press Floor button to call elevator
End
resetFloorButton()
Begin
: reset the floorButton to off status
End
isOcuppied()
Begin
: is there is person, then return true, else return false
End
getFloorNumber()
Begin
: get the floor number
End
---------------------------------------------------------------------------
Class Elevator
Definition: Elevator in that floor
Attributes:
Door elevator_door : elevator door
Person *personPtr; : person in the elevator, the capacity is two
one elevator can not more than two persons
currentFloor : current Floor of the elevator
Direction : the direction of elevator will go.UP OR DOWN
ActionStatus : moving or not moving two states: MOVE,OR STOP
arrivalTimeNextFloor: keep trace 5 second for each floor
Button destButton : buttons inside the elevator, 1,2,3
calledByPerson : two states: CALLED OR NCALLED
Behaviors:
pressButton()
Begin
: person press destination button
End
resetButton()
Begin
: turn off all buttons in the elevator
End
isMoving()
Begin
: determine whether elevator is moving by get ActionStatus
End
needMove()
Begin
: if the person is onboard, and get called, have to move
End
needStop()
Begin
if go from 1 to 3, need to check whether need to stop to pick up that person
End
stop(Floor*)
Begin
: elevator stoped at certain floor
End
getCalled(Floor*)
Begin
: elevator get called at certain floor
End
departureAction()
Begin
: elevator need to turn off the light, close the door,
End
getCurrentFloor()
Begin
determine the current floor
End
Direction getDirection() :
Begin
calculate whether go up or down by compare, current floor, and destination
End
personEntered(Person* that) :
Begin
"that" person enter elevator
End
personExited()
Begin
person exit the elevator, get destroyed.
End
---------------------------------------------------------------------------
Class Scheduler
Definition: schedule the event, generate the random numbers of next arrival
time and also the destination of a person
Attribute:
arrivalTime[3] //arrival time at each floor
destinationFloor[3] //the destination floor of each person
Behaviors:
createNewPerson(currentFloor, destination, Floor&)
Begin
create a new person
End
scheduleNextArrival(floornumber)
Begin
schedule next arrival by generate random number
indicate the next arrival time
End
reschedule() :
Begin
if is occupied, we need to reschedule
schedule a new arrival time
indicate the next arrival time
End
getRandom() : get next arrival time randomly
getRandomX(currentfloor) : get the destination floor, exclude current floor
checkIfNewPersonArrived(currentTime,floor1,floor2,floor3) check all three floor whether there are any person arrived
Pseudocode:
Begin:
check if arrival time of new person == current time each floor
if floor is not occupied for each floor
create a new person
schedule the next arrival time
else
reschedule
end
---------------------------------------------------------------------------
Class Building
Definition: Inside the building, we have a sumlator to simulate everything.
Elevator, floor1, floor2, floor3 and clock are all in that building
Attribute:
Clock clock object clock in that building initial = 0
Elevator elevator
Floor floor1 first floor
Floor floor2 second floor
Floor floor3 third floor
Schedule schedule
Behavior
simulate() : simulate the whole program
Pseudocode:
begin
while current time < simulation time
display current time
if elevator is moving
check if need stop at current time
if need stop
stop the Elevator
check If new person arrived at current time of floor1, floor2,floor3
if elevator is not moving
check whether need move because of call from person
increment current time
end
Testing program
------------------------------------------------------------------
Enter the seed for random generator
Enter the length of simulation time
Declare new Building building
building.simulate(), run the simulate function
initial set of test data
-------------------------------------------------------------------
On floor 1, first person will arrive at time 16
on floor 2, first person will arrive at time 7
On floor 3, first person will arrive at time 29
time = 0
elevator is waiting on Floor 1
time = 1
elevator is waiting on Floor 1
time = 2
elevator is waiting on Floor 1
time = 3
elevator is waiting on Floor 1
time = 4
elevator is waiting on Floor 1
time = 5
elevator is waiting on Floor 1
time = 6
elevator is waiting on Floor 1
time = 7
person 1 arrived at Floor 2
next person schedule to arrive on Floor 2 at time 19
up button is pressed
Elevator is called
Elevator start to move up
time = 8
Elevator is moving up
time = 9
Elevator is moving up
time = 10
Elevator is moving up
time = 11
Elevator is moving up
time = 12
Elevator stops at Floor 2
The light on the floor is turned on.
Elevator door is opened
Person go in elevator
time = 13
Elevator is waiting on Floor 2
time = 14
Elevator is waiting on Floor 2
time = 15
Elevator is waiting on Floor 2
time = 16
Elevator is waiting on Floor 2
person 2 arrive at Floor 1
up button is pressed
Elevator is called
time = 17
Elevator is waiting on Floor 2
time = 18
Elevator is waiting on Floor 2
time = 18
Elevator is waiting on Floor 2
time = 19
Elevator is waiting on Floor 2
Reschedule: next person schedule to arrive on Floor 2 at time 20
time = 20
Light above the floor is turned off.
Person walk in the elevator
Person press floor 3 button
Elevator is moving up
Person 3 arrived at Floor 2
down button is pressed
elevator is called.
time = 21
Elevator is moving up
time = 22
Elevator is moving up
time = 23
Elevator is moving up
time = 24
Elevator is moving up
time = 25
Elevator arrive on floor 3
Light on the floor is turn on
Elevator door is opened
Person 1 go out the elevator
time = 26
Elevator is waiting at Floor 3
time = 27
Elevator is waiting at Floor 3
time = 28
Elevator is waiting at Floor 3
time = 29
Person 4 arrive at floor 3
Down button is pressed.
Elevator is called
Person 4 go in the elevator
Person press floor button 1
time = 30
Person 4 arrive at floor 3
time = 31
Person 4 arrive at floor 3
time = 32
Person 4 arrive at floor 3
time = 33
Light on the floor is turned off
Elevator door is closed
Elevator is moving down
time = 34
Elevator is moving down
time = 35
Elevator is moving down
time = 36
Elevator is moving down
time = 37
Elevator is moving down
time = 37
Elevator stop at floor 2
Light on the floor is turned on
Elevator door is opened
Person 3 go in the elevator
Person press floor button 1
time = 37
Elevator is waiting on floor 2
|