当前位置:网站首页>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 .
边栏推荐
- Huge number multiplication (C language)
- Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
- Canoe - the third simulation project - bus simulation-1 overview
- Two way process republication + routing policy
- [machine] [server] Taishan 200
- [Galaxy Kirin V10] [desktop] cannot add printer
- [Galaxy Kirin V10] [desktop] printer
- Write a program to judge whether the two arrays are equal, and then write a similar program to compare the two vectors.
- Network connection (III) functions and similarities and differences of hubs, switches and routers, routing tables and tables in switches, why do you need address translation and packet filtering?
- Send a request using paste raw text
猜你喜欢

BGP ---- border gateway routing protocol ----- basic experiment

Rhcsa - day 13

XMIND installation
![[Galaxy Kirin V10] [desktop] cannot add printer](/img/a6/28e4aa31e805a018e6db2b32ca1be0.jpg)
[Galaxy Kirin V10] [desktop] cannot add printer

Idea SSH channel configuration

The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server

Performance test method

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

VI text editor and user rights management, group management and time management

C language structure to realize simple address book
随机推荐
When I forget how to write SQL, I
[Galaxy Kirin V10] [desktop] can't be started or the screen is black
Hlk-w801wifi connection
Write a program to judge whether the elements contained in a vector < int> container are 9.20: exactly the same as those in a list < int> container.
How to quickly parse XML documents through C (in fact, other languages also have corresponding interfaces or libraries to call)
Si vous ne connaissez pas ces quatre modes de mise en cache, vous osez dire que vous connaissez la mise en cache?
Pod management
Personal thoughts on the development of game automation protocol testing tool
BGP ---- border gateway routing protocol ----- basic experiment
JMeter common configuration components and parameterization
Collection of practical string functions
Regular expression
Two way process republication + routing policy
The most ideal automated testing model, how to achieve layering of automated testing
RHCE day 3
2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected
Article publishing experiment
183 sets of free resume templates to help everyone find a good job
Write a program that uses pointers to set all elements of an int array to 4.18: 0.
Introduction to tree and binary tree