当前位置:网站首页>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 .
边栏推荐
- BGP ---- border gateway routing protocol ----- basic experiment
- DCL statement of MySQL Foundation
- JMeter assembly point technology and logic controller
- Const's constant member function after the function; Form, characteristics and use of inline function
- Read a piece of text into the vector object, and each word is stored as an element in the vector. Convert each word in the vector object to uppercase letters. Output the converted elements in the vect
- Recursive method to achieve full permutation (C language)
- Four characteristics and isolation levels of database transactions
- Personal thoughts on the development of game automation protocol testing tool
- Si vous ne connaissez pas ces quatre modes de mise en cache, vous osez dire que vous connaissez la mise en cache?
- [machine] [server] Taishan 200
猜你喜欢
When I forget how to write SQL, I
JMeter Foundation
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
Using Lua to realize 99 multiplication table
Knapsack problem and 0-1 knapsack problem
Collection of practical string functions
OSPF summary
[Galaxy Kirin V10] [desktop] cannot add printer
On binary tree (C language)
随机推荐
Static comprehensive experiment ---hcip1
51 data analysis post
Knapsack problem and 0-1 knapsack problem
Locust installation
If you don't know these four caching modes, dare you say you understand caching?
The bamboo shadow sweeps the steps, the dust does not move, and the moon passes through the marsh without trace -- in-depth understanding of the pointer
Rhcsa - day 13
Strings and characters
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
XMIND installation
Canoe - the second simulation project -xvihicle1 bus database design (operation)
Introduction to tree and binary tree
[test theory] test phase analysis (unit, integration, system test)
Application and Optimization Practice of redis in vivo push platform
From programmers to large-scale distributed architects, where are you (I)
Hidden C2 tunnel -- use of icmpsh of ICMP
Hlk-w801wifi connection
[Galaxy Kirin V10] [server] NUMA Technology
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
Aike AI frontier promotion (2.14)