当前位置:网站首页>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 .
边栏推荐
- shell awk
- [Galaxy Kirin V10] [server] set time synchronization of intranet server
- 20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
- Idea SSH channel configuration
- What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
- Collection of practical string functions
- Performance test method
- XMIND installation
- RHCE day 3
- How do microservices aggregate API documents? This wave of show~
猜你喜欢
Evolution from monomer architecture to microservice architecture
Article publishing experiment
[Galaxy Kirin V10] [desktop] cannot add printer
Canoe - the second simulation project -xvihicle1 bus database design (operation)
C language structure to realize simple address book
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
JMeter correlation technology
Canoe - the second simulation engineering - xvehicle - 2panel design (principle, idea)
Dichotomy search (C language)
Idea SSH channel configuration
随机推荐
Hidden C2 tunnel -- use of icmpsh of ICMP
How do microservices aggregate API documents? This wave of show~
IPv6 comprehensive experiment
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
Seven examples to understand the storage rules of shaped data on each bit
PHP programming language (1) - operators
Dictionaries and collections
Software testing related resources
Fundamentals of database operation
Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
[testing theory] thinking about testing profession
From programmers to large-scale distributed architects, where are you (2)
如果不知道這4種緩存模式,敢說懂緩存嗎?
Article publishing experiment
Write a program that uses pointers to set all elements of an int array to 4.18: 0.
[Galaxy Kirin V10] [server] set time synchronization of intranet server
JMeter assembly point technology and logic controller
Jianzhi offer 04 (implemented in C language)
Canoe - the third simulation project - bus simulation-1 overview
/*The rewriter outputs the contents of the IA array. It is required that the type defined by typedef cannot be used in the outer loop*/