In-lecture group exercise Fri Oct 15th In groups of 3 or 4, each group should try to establish an algorithm for controlling/simulating the elevator behaviour. It can assume the building descriptions and passenger requests have already been error-checked, so only valid requests/data need to be considered here. Below is an initial draft of the algorithm I thought of, it undoubtedly still has some issues, possibly significant ones :) Elevator control/simulation algorithm - assuming the building description file(s) have been validated - assuming the passenger requests have been validated, and that a separate queue of requests (time-sorted) has been formed for each building Elevator algorithm for any one building data stored/used: each floor will have its own queue of waiting passenger requests, sorted by time of request initially each queue is empty [possibly even use two queues on each floor, one for requests going up from that floor, the other for requests going down ] the elevator will have a queue of onboard passenger requests, sorted by time of request initially the queue is empty initialization: while the building request queue is not empty read the next request from the queue and enqueue it at the back of the appropriate floor's queue set the current number of passengers on the elevator (0) the current direction of the elevator (up) the current time (0) core algorithm: repeat note the current time as the floor arrival time if the elevator onboard queue is not empty determine the number of passengers disembarking on the current floor (if any), update the elevator onboard queue and compute the time at which passengers can start embarking if the elevator on board queue is empty and there are no waiting requests on this floor (at this point in time, remember the floor queue contains all future entries) or any floor further in the current direction then reverse the elevator direction check to see if the floor queue contains any passengers waiting to embark in the current direction and, if there is space on the elevator, update the elevator onboard queue, the floor waiting queue, the time at which passengers finish embarking, and the number of passengers left behind on the floor (who were travelling in the current direction) [ if only some members of a group can get on the elevator, then the request still has to be left in the floor queue, just with a smaller number of passengers waiting from that group alternatively would be to act as though the remaining passengers "pushed the button" again, adding a new floor request ] generate the output from the current floor's stop (building, arrival time, floor, #disembarking, #embarking, #left behind, departure time, direction of travel) compute the time and floor the elevator will *next* stop at, and set these as the new current time and elevator floor [ this will need to consider both the next destination floor for the passengers on board the elevator and also whether there are waiting requests in the same direction on any floors in between ] until all floor queues are empty AND the elevator onboard queue is empty final phase if the empty elevator is not on ground floor then send it to the ground floor and display arrival info