当前位置:网站首页>Elevator dispatching (pairing project) ②
Elevator dispatching (pairing project) ②
2022-07-04 10:52:00 【Painting and living~】
One 、UML chart
Two 、Design by Contract, Code Contract
Design by contract (Design by Contract ,DbC) It's a way of designing computer software , It is to make an agreement on some data according to some regulations . If beyond the agreement , The program will no longer run . for example , The input parameters must meet certain conditions . Standing on the java From the perspective of language , The so-called contractual programming is when certain conditions are met , Only conditional execution method body , have access to AOP Realization Java Design by contract . stay java Of Junit We use assertions in our tests (assert) Look at our program structure .
3、 ... and 、 Realization Bus Scheduling algorithm
Bus The idea of scheduling algorithm is : Use the elevator as a bus , from -1 From the first floor to the highest floor , Stop at every floor , And open the door to let passengers in and out , Then close the door and walk up . Up to the top , Down again .
In the process of implementation , We use four threads to run four elevators . In each thread , First, judge whether the elevator serves on this floor . If you can provide services , Then the elevator opens , At the same time call EleController Class synchronized Method GetPsgIn(), Pick up the passengers who can enter the elevator on this floor , This ensures that when each elevator accesses the waiting passenger list , There will be no thread conflicts bug.
public void busDispatcher(){
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
}
}
}).start();
}
}
Four 、 Making the main interface UI

The above figure shows the main interface of the elevator dispatcher made by our group , Passengers can be randomly generated on the left , You can also add passengers manually . We provide “Bus”“SSTF”“LOOK” Three buttons , For users to choose the appropriate scheduling algorithm . On the right is the simulation of elevator operation , Visually display the current floor of the elevator 、 manned 、 Load and passenger information .
“ Set elevator parameters ” Button to connect to a new interface , The service floor of the elevator can be adjusted according to the needs of users 、 Maximum manned capacity 、 Maximum load and other parameters . Enter the elevator number and fill in the new load 、 The number of , Check the service floor , You can update the parameters of the elevator .
边栏推荐
- 如果不知道這4種緩存模式,敢說懂緩存嗎?
- Two way process republication + routing policy
- XMIND installation
- DDL language of MySQL database: create, modify alter, delete drop of databases and tables
- [Galaxy Kirin V10] [desktop] can't be started or the screen is black
- [Galaxy Kirin V10] [server] system startup failed
- Summary of automated testing framework
- Day06 list job
- Advanced order of function
- Snake (C language)
猜你喜欢

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

Dynamic memory management

C language - stack

183 sets of free resume templates to help everyone find a good job

Quick sort (C language)
![[test theory] test process management](/img/d2/65865dffacf38d9a8be720868b75f0.jpg)
[test theory] test process management

Discussion | has large AI become autonomous? Lecun, chief scientist of openai

XMIND installation

How to use diff and patch to update the source code

Canoe - description of common database attributes
随机推荐
Personal thoughts on the development of game automation protocol testing tool
The most ideal automated testing model, how to achieve layering of automated testing
DDL statement of MySQL Foundation
Seven examples to understand the storage rules of shaped data on each bit
[test theory] test the dimension of professional ability
2022 ape circle recruitment project (software development)
Day7 list and dictionary jobs
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?
On binary tree (C language)
Knapsack problem and 0-1 knapsack problem
What is an excellent architect in my heart?
JMeter assembly point technology and logic controller
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
Aike AI frontier promotion (2.14)
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology
Regular expression
Rhcsa day 10 operation
How do microservices aggregate API documents? This wave of show~
The last month before a game goes online
/*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*/