Design an Object oriented elevator

The main idea here is to have a centralized bank to schedule the activity to all cars.

Lets simulate the situation when we have only one car. The car has status of either movingUp, movingDown or Standing at certain floor. To save time, if the car is moving up, it will move to as far as it needs to, and then comeback down. It is true for the reversed direction too. each car will have a list of target that it needs to stop and it was set by the centralized bank after it takes command from the buttons inside the car as well as buttons on each floor.

The centralized bank sends command to the car and the car fulfills the command in the order specified by the centralized bank. i.e every car has a request queue and each time it takes the next request from head of the queue and goes to that floor. If the request queue is empty, then it simply stopped at the current floor.

One thing is needs to note is that you need to serve a request that the car is not scheduled to reach by the buttons inside itself. So when a new request is entered, the centralized bank will make sure that the request will be served by the car.

So the idea is that centralized bank receives all the input from each floor and each car. and dispatch them to each car. If the input is from one specific car, then the same input is send back to the original car. If the request is from a floor, then the centralized bank will pick a car according to the following order: if a car is standing at that floor, it was send to that car -> if a car (or multiple cars) is moving towards this floor, pick the closest one -> otherwise pick a car standing at another floor -> otherwise pick the first car. When each car received a request, it will insert the car into its request queue. -> if the requested floor is already in the queue, ignore -> otherwise if the floor is on its way up (or down), add it to the list. -> if need to go further to reach the requested floor, add it to proper position as well. (Or we can use two queues one for go up and one for go down to make implementation easier). The whole idea is the centrialized bank dispatch request and car execute request by itself in optimized order.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s