当前位置:网站首页>Elevator dispatching (pairing project) ③
Elevator dispatching (pairing project) ③
2022-07-04 10:52:00 【Painting and living~】
List of articles
One 、SSTF Algorithm implementation
The shortest time to find a floor is preferred (SSTF-Shortest Seek Time First) The core idea of the algorithm is to find the nearest passenger for service . In order to make the elevator practical , Only look for the nearest passenger when there is no one in the elevator , And will not be interrupted . During this process, if there are new passengers waiting , Then get on the elevator , Interrupt search . When there are people in the elevator, run in the original direction , Until the last passenger gets off the elevator .
When the elevator reaches the floor, there are passengers waiting , The direction of passengers going upstairs and downstairs is consistent with the running direction of the elevator , And the current elevator can open the door when it reaches the passenger's target floor , Otherwise, go on 、 Downstairs . When the passenger is the highest / Passengers on the lowest floor , Open door , Get on the elevator . Do not open the door in other cases . When the elevator is empty, it will automatically detect the passengers on the highest floor and the passengers on the lowest floor , The elevator will not go lower than the building where the lowest floor passenger is located and higher than the building where the highest floor passenger is located .
SSTF The main logic of the algorithm is as follows :
public void sstfDispatcher(){
Randomly generate passengers
The thread used to dispatch the elevator ( common 4 individual )
for (int i = 0; i < ELE_COUNT; i++)
{
new Thread(()->{
while (true){
Get the current status and floor
Get the nearest passenger ( Including judging whether the target floor of the passenger can reach )
If the elevator is empty , Change the direction of the elevator to the direction of the nearest passenger
while( The nearest passenger's floor is not reached and the elevator is empty ){
If services are provided at this level
Detect that no one gets on or off the elevator
Go ahead / Downstairs
}
Determine whether to serve on this layer
Check whether there is getting on and off the elevator
The elevator runs
}
}
}).start();
}
}
among , Find the nearest passenger to use EleController Class getNearestPsg() function , This function can find the nearest passenger who can reach the target floor .
Passengers entering and leaving the elevator are also encapsulated into a function psgOnOrOff(), First detect whether there are passengers on the floor , Whether the target floor of passengers can reach , And whether the passenger's target direction is consistent with the current elevator running direction , If all is satisfied , Then open the door , Passengers get on or off the elevator . The realization and of passengers getting on and off the elevator bus Same algorithm .
There are two kinds of elevator operation , One is eleRun(), The other is eleSmartRun().eleSmartRun() Only used when the elevator is empty : If there are no customers waiting , The elevator stops sleeping for a certain time ; If the current floor goes up and does not reach the highest floor that can be reached and the floor where the passengers are on the highest floor , Then continue to go up , On the contrary, it goes down . Another kind eleRun() Keep running in the original direction , Until you reach the highest accessible floor or the last passenger gets off the elevator .
Two 、LOOK Algorithm
In the realization of SSTF In fact, when calculating the algorithm, I just put LOOK The algorithm is implemented , however SSTF The algorithm is not necessarily better than LOOK Practical algorithm .
LOOK The idea of the algorithm is to change the running direction immediately when there is no request in the moving direction of the elevator . On the implementation , Put the above SSTF The part of finding the nearest passenger in the algorithm is removed , Namely LOOK The algorithm . Mainly by eleSmartRun() Realization . The specific implementation function is the same as SSTF Algorithm .
public void lookDispatcher(){
Randomly generate passengers
The thread used to dispatch the elevator ( common 4 individual )
for (int i = 0; i < ELE_COUNT; i++)
{
new Thread(()->{
while (true){
Get the current status and floor
Determine whether to serve on this layer
Check whether there is getting on and off the elevator
The elevator runs ( Here, judge whether there is a request in the moving direction of the elevator )
}
}
}).start();
}
}
3、 ... and 、 Algorithm and UI Interface connection
ui The interface uses javafx, There are three interfaces :
Start

The function of this interface is to open multiple elevator controller windows at the same time , This is the main window . Click the button in the middle to open a new elevator controller window , Each window is independent .
MainWindow

This interface is the main interface , Passengers can be added manually on the upper left , from onAddCosButtonClicked() Realization .
Then press the next Bus,SSTF,LOOK Button to execute the corresponding algorithm . Due to time , Algorithm switching and pause are not implemented .
Then left ” Number of people waiting “,” Number of people served “, And below ” The total number of “ Corresponding to the current number of people waiting to get on the elevator , Number of people served , And the total number of people from the beginning to the operation .” Number of people served / The total number of “ It is an evaluation index of elevator operation efficiency , The initial value is 1, from refreshTotalInfo() Method realization .
White on the left TextArea It is used to display the information of all passengers , from refreshHisCosInfoArea Realization .
The situation of the four elevators on the right is explained from top to bottom :
The upper part shows the current arrival floor of the elevator in real time , from changeFloor() Method realization .
The middle number and the remaining weight can be accommodated by setEleInfo() Method realization .
Next, update the information of passengers who have boarded the elevator by refreshEleArea() Method realization .
Click the set elevator parameters button on the far right to pop up a new window , To change elevator parameters , As follows .
SetElePara

After filling in the elevator parameters, click Modify Parameters to modify the parameters of a specific elevator . from onSetButtonClicked() Method realization .
边栏推荐
- Idea SSH channel configuration
- Rhcsa12
- VLAN part of switching technology
- [Galaxy Kirin V10] [server] iSCSI deployment
- 2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
- Appscan installation error: unable to install from Net runtime security policy logout appscan solution
- Time complexity and space complexity
- IPv6 comprehensive experiment
- Iterator generators and modules
- XMIND installation
猜你喜欢

DNS hijacking

Rhsca day 11 operation

What is an excellent architect in my heart?

RHCE - day one

Appscan installation error: unable to install from Net runtime security policy logout appscan solution
![[Galaxy Kirin V10] [server] failed to start the network](/img/0f/6d2f321da85bd7437d2b86547bd8b4.jpg)
[Galaxy Kirin V10] [server] failed to start the network

Canoe - the third simulation project - bus simulation - 3-2 project implementation

Collection of practical string functions

Installation of ES plug-in in Google browser
![[Galaxy Kirin V10] [server] FTP introduction and common scenario construction](/img/ef/f0f722aaabdc2d98723cad63d520e0.jpg)
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
随机推荐
[Galaxy Kirin V10] [server] NUMA Technology
Jemeter plug-in technology
[untitled]
On binary tree (C language)
Time complexity and space complexity
From programmers to large-scale distributed architects, where are you (2)
From programmers to large-scale distributed architects, where are you (I)
DDL statement of MySQL Foundation
[test theory] test process management
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration
Idea SSH channel configuration
Jianzhi offer 04 (implemented in C language)
Regular expression
Evolution from monomer architecture to microservice architecture
Static comprehensive experiment ---hcip1
Communication layer of csframework
Performance test process
Interview and lecture summary 1
Add t more space to your computer (no need to add hard disk)
shell awk