HW06: Elevator

Implement a subclass of ElevatorLogic such that all passengers are served and, ideally, average passenger wait times are lower than the provided implementation.

Start with my code on londo after making your own directory:

cp -R /home/jeckroth/csci221/elevator/* .

Read some auto-generated documentation.

Commit just the *.cpp, *.h, *.R files, and Makefile to git. Do not commit anything else!

Avoid all memory leaks. Check with valgrind.

You can test your implementation by running the test_elevator binary that you build with the Makefile, followed by this command:

Rscript test_elevator.R

You should see Total passengers: 369 Total satisfied passengers: 369 (these should be equal) and your average wait times.

Some notes about the elevator simulator

  • Multiple elevators are simulated at once, like in a skyscraper.
  • Random passengers are generated on random floors, and they request an elevator up or down.
  • When an elevator passes by their floor, they get in (you can’t prevent this).
  • When a passenger enters an elevator, they request their desired floor number.
  • When a passenger is in an elevator and it passes by their desired floor, they get out.

About the generated statistics

  • After multiple random simulations, several statistics are computed. Note, everyone will be subjected to the same random simulation (same random seed).
  • Average call time is how long a passenger waits to get in.
  • Average in elevator time is how long a passenger stands in the elevator.
  • Average satisfaction time is a sum of the other two statistics, per passenger.


Full credit requires: your code compiles & runs, the simulator finishes (i.e., no infinite loops), there are no memory leaks, and all passengers are satisfied (according to the Rscript output).

Try to get the lowest possible average satisfaction time, but this is not graded.


  • Start by making a simple, blank subclass of ElevatorLogic. You’ll need a constructor that calls the parent constructor, passing the same arguments, as done in the MoneyMarketAccount example on these notes. Create the required methods (the ones that are “pure virtual”, i.e., =0; note you do not need to say “virtual” in the subclass). Notice that the es and ecount variables are protected in the parent class so your subclass has access to them.
  • Notice when the logic methods get called. call is when a person wants to get in an elevator on a certain floor. selectFloor is when a passenger presses a button inside. notifyFloorChanged is when one of the elevator moves (because your logic told it to).
  • Look at common_defs.h to see the variables (enums, actually) used for up/down directions when a person asks for an elevator and up/down/halt for elevator motion commands, and the MAX_FLOORS define.
  • Your elevator logic notifyFloorChanged method should check if the elevator that moved reached the ground floor or top floor; if so, make sure you halt it.
  • For simplicity, start by just moving one elevator in the array up/down to where the passengers are and want to go, before trying to move several.

CSCI 221 material by Joshua Eckroth is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Source code for this website available at GitHub.