Elevator-Scheduling-Simulator
Elevator-Scheduling-Simulator copied to clipboard
:hotel: :office: :department_store: :school: A simulation environment, which mimics the scheduling of multiple elevators within a building of any size. The multithreaded approach helps to simulate ele...
Elevator Scheduling Simulator :office: :bank: :hotel: :department_store:
Description
A simulation environment, which mimics the scheduling of multiple elevators within a building of any size. The multithreaded approach helps to simulate elevators running concurrently. The simulation also makes use of several group scheduling algorithms, which help to distribute the workload between elevator-cars as well as make the elevators adaptable to various situations (eg. more people in the morning - Up-Peak, everyone is going to the main floor - Zoning).
How to Run
> cd src/
> javac *.java
> java Building <number of floors> <number of elevators> <building population>
Data Structures Used
- CopyOnWriteArrayList - Source I, CopyOnWriteArrayList - Source II
- Makes it possible to iterate over a list in a safe way, even when concurrent modification is happening
- Creates a snapshot of the array, every time a mutation operation is invoked, hence, the iteration would always take place on the previous version of the array
- The data structure was used to hold
floorCallsandcarCallsin the Elevator class
- Makes it possible to iterate over a list in a safe way, even when concurrent modification is happening
- PriorityBlockingQueue
- Supplies blocking retrieval operations
- Allows for custom element ordering
- The data structure was used to implement
sequence, in which the calls had to be sorted based on their passage
Group Scheduling Algorithms Implemented
-
Round-Robin
- Is the default group scheduling algorithm
- Calls are assigned in the order they arrive in a sequential way to single elevators
-
Up-Peak
- A variation of Round-Robin
- If an elevator is idle for ~7 seconds, then a call is generated to take the elevator to the lobby
- This reduces the waiting time for future passengers arriving at the lobby
-
Zoning
- Splits a building into several adjacent zones
- Every elevator only serving floor calls that occur in the zone assigned to the respective car
- Implemented Static Zoning, zones are assigned permanently
-
Three-Passage
- Estimates the costs that would result from assigning a new call to the elevator
- The call is assigned to the elevator with the lowest costs
- In case every elevator already reached 80% load (number of calls > 80% elevator's capacity), calls will not get assigned until at least one elevator falls below this mark
Threads
Building.java Thread
- The main thread
- Randomly chooses a floor from the
floorsarray and calls thegeneratePassenger()method - Sleep time is ~ 20 seconds
GroupElevatorController.java Thread
- The thread calls the
scheduler()method with an interval of ~ 2 seconds - The
scheduler()method scans thefloorsarray and looks for passengers - If a passenger is found, then a job is assign to one of the elevators from the
elevatorGrouparray - The target elevator is chosen by group scheduling algorithms
Elevator.java Thread I
- The
elevatorControllerThreadcalls theelevatorController()method with an interval of ~ 2 seconds - The
elevatorController()method:- Gets a
floorCallfromfloorCallsarray - Assigns it a passage
- Adds it to the
sequencequeue
- Gets a
Elevator.java Thread II
- The
performJobThreadcalls theperformJob()method with an interval of ~ 2 seconds - The
performJob()method:- Takes a call from
sequencequeue - Simulates the elevator going up or down
- Takes a call from
Elevator.java Thread III
- The
upPeakThreadrelocates elevators in idle state to the lobby.
Elevator.java Thread IV
- The
zoningThreadrelocates elevators in idle state to go to a floor within their assigned zone.
Information Sources
- Object level locking vs. Class level locking
- Intrinsic Locks and Synchronization
- PriorityBlockingQueue Javadoc
- CopyOnWriteArrayList Javadoc
What's Next
- Analyze each algorithm by running the system with different inputs:
- Different number of elevators
- Different number of requests
- Implement the functionality to switch dynamically between the algorithms during runtime
- Implemented disk scheduling algorithms:
- First Come-First Serve (FCFS)
- Shortest Seek Time First (SSTF)
- Elevator (SCAN)
- Circular SCAN (C-SCAN)
- LOOK
- C-LOOK
- Add GUI