当前位置:网站首页>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 .
边栏推荐
- Regular expression
- [Galaxy Kirin V10] [desktop] cannot add printer
- Unittest+airtest+beatiulreport combine the three to make a beautiful test report
- How do microservices aggregate API documents? This wave of show~
- [Galaxy Kirin V10] [server] NFS setup
- Common system modules and file operations
- VI text editor and user rights management, group management and time management
- Canoe - the third simulation project - bus simulation - 3-1 project implementation
- Collection of practical string functions
- Seven examples to understand the storage rules of shaped data on each bit
猜你喜欢
If you don't know these four caching modes, dare you say you understand caching?

DCL statement of MySQL Foundation
![[Galaxy Kirin V10] [server] soft RAID configuration](/img/d5/789387613fafc18f623d0cff45093b.jpg)
[Galaxy Kirin V10] [server] soft RAID configuration

RHCE - day one

Rhcsa learning practice
![[Galaxy Kirin V10] [server] failed to start the network](/img/0f/6d2f321da85bd7437d2b86547bd8b4.jpg)
[Galaxy Kirin V10] [server] failed to start the network

Idea SSH channel configuration

Virtual machine configuration network

Using SA token to solve websocket handshake authentication

From programmers to large-scale distributed architects, where are you (I)
随机推荐
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
On binary tree (C language)
183 sets of free resume templates to help everyone find a good job
Postman interface test
The most ideal automated testing model, how to achieve layering of automated testing
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
Performance features focus & JMeter & LoadRunner advantages and disadvantages
Terms related to hacker technology
Si vous ne connaissez pas ces quatre modes de mise en cache, vous osez dire que vous connaissez la mise en cache?
[Galaxy Kirin V10] [desktop] cannot add printer
How do microservices aggregate API documents? This wave of show~
Locust installation
DNS hijacking
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
How to quickly parse XML documents through C (in fact, other languages also have corresponding interfaces or libraries to call)
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
For and while loops
The last month before a game goes online
Deepmind proposed a Zuan AI, which specially outputs network attack language