Develop a simulation of an elevator that travels between floors 1 and N where N is an input. Time is sequenced in discrete steps starting at 1; at each time step, the elevator may ascend one floor, descend one floor, or remain at its current floor, as determined by its strategy. The first line of the input file indicates the number N of floors. This is followed by one line per person using the elevator: her id, call time (when she calls for the elevator), origin floor (where she boards the elevator), and destination floor (where she debarks the elevator). For example:
100 2 1 4
101 3 4 5
102 3 3 2
103 5 5 1
104 5 1 4
Here, individual 100 boards at time 2 from floor 1 with a destination of floor 4. Assume sensible inputs (e.g., times are positive integers, floors are integers in the range 1 through N).
Whenever the elevator stops at a floor from which people have called it (i.e., their origin floor but not before their call time), they all board the elevator. And whenever the elevator stops at any passengers’ destination floor, they all get off the elevator. (Everyone behaves so as to minimize their travel time.) The simulation stops when every passenger has been brought to his or her destination floor (subject of course to their call time and origin floor constraints).
A strategy determines the floor the elevator begins on at time 1, and a policy for moving to the next floor (up one floor, down one floor, or remaining at the current floor) from one time step to the next. These are implemented by its intial_floor and next_floor policy methods. A strategy is notified whenever a person calls it (person_calls method), when a passenger boards (person_gets_on), and when a passenger debarks (person_gets_off). Information provided through these last three notification methods can be used to tailor an intelligent strategy for moving from floor to floor.
def person_calls(time, from)
def person_gets_on(time, from, to)
def person_gets_off(time, to)
Here is a naïve strategy that does not make use of the information supplied by the notification methods:
Strategy 1: Start at floor 1. In each time step, successively go up one floor until reaching the top floor N, then successively go down one floor until reaching the bottom floor 1, and continue this ‘up to the top floor then down to the bottom floor’ policy.
Here we run the simulation using the input file [login to view URL] (given above) and Strategy 1: