You are tasked to write a program that simulates an elevator controller controlling a single elevator in a building.
The elevator installed in the building is destination dispatch.
Some rule :
– The building has 11 floors (G – 10)
– Move between 1 Floor = 1 seconds
– Door open or close = 5 seconds
– Passengers board or leave = 4 seconds
– At t=0, Floor = G, Door = close
– For every request, there is only one passenger
– There are no limits for the elevator capacity
For the simulation input, it will consists of the number of requests n, followed by n lines of request details consisting the request ID, request time, source floor and destination floor.
2 # Number of requests 0 0 0 10 # Request ID, request time, source floor, destination floor 1 20 5 10
You are required produce two outputs, a log file consisting of all the actions/ decisions made by the elevator controller, and a report file that holds the statistics of the elevator after serving all the requests.
Output 1 – Log File
0: Service request (Request ID: 0) received from floor G to floor 10 0: Door opening 5: Door opened 9: 1 passenger(s) entered the elevator 9: Door closing 14: Door closed 14: Heading to floor 10 20: Service request (Request ID: 1) received from floor 5 to floor 10 24: Reached floor 10 24: Door opening 29: Door opened 33: 1 passenger(s) left the elevator 33: Door closing 38: Door closed 38: Heading to floor 5 43: Reached floor 5 43: Door opening 48: Door opened 52: 1 passenger(s) entered the elevator 52: Door closing 57: Door closed 57: Heading to floor 10 62: Reached floor 10 62: Door opening 67: Door opened 71: 1 passenger(s) left the elevator 71: Door closing 76: Door closed
Output 2 – Report File
### Elevator Statistics ### Service request processed: 2 Passengers served: 2 Total floors travelled: 20 Total time taken: 76 ## Request ID - 0 Total time utilized: 38 ## Request ID - 1 Total time utilized: 56
Here what I have tried so far, sorry I do not know how to use GitLab.
What my problem is, I do not know how to make the code always check the next request and then calculate the first request and then try to calculate if next request can queue with the first request or first request need to queue behind second request,
and I do not know how to check the next request(third request until last request), If I check, I do not know how to check with previous request.
and I need to run while check because request time need to compare with real lift time to decide.
and what i imagine, if i run 1st request, got the real time, compare with 2nd request and 2nd request is queue behind 1st request, what if 3rd request should be the one who queue first? how do i undo my code to replace 3rd request need to be queue first?
My big problem is I can not see how the real algorithm for this question work.
*sorry about my enlish
*im using NetBeans 8.2