当前位置:网站首页>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 .
边栏推荐
- Ten key performance indicators of software applications
- Terms related to hacker technology
- Installation of ES plug-in in Google browser
- Seven examples to understand the storage rules of shaped data on each bit
- JMeter correlation technology
- If you don't know these four caching modes, dare you say you understand caching?
- XMIND installation
- DNS hijacking
- Virtual machine configuration network
- Deepmind proposed a Zuan AI, which specially outputs network attack language
猜你喜欢
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
Installation of ES plug-in in Google browser
[Galaxy Kirin V10] [server] iSCSI deployment
[Galaxy Kirin V10] [desktop] can't be started or the screen is black
C language structure to realize simple address book
DDL statement of MySQL Foundation
On binary tree (C language)
Send a request using paste raw text
Evolution from monomer architecture to microservice architecture
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
随机推荐
leetcode842. Split the array into Fibonacci sequences
The last month before a game goes online
Two way process republication + routing policy
Jemeter plug-in technology
Day06 list job
DDL language of MySQL database: create, modify alter, delete drop of databases and tables
Network connection (II) three handshakes, four waves, socket essence, packaging of network packets, TCP header, IP header, ACK confirmation, sliding window, results of network packets, working mode of
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?
F12 clear the cookies of the corresponding web address
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
Appscan installation steps
MFC document view framework (relationship between classes)
Rhcsa day 10 operation
Safety testing aspects
Software testing related resources
[machine] [server] Taishan 200
[test theory] test the dimension of professional ability
Const's constant member function after the function; Form, characteristics and use of inline function
Add t more space to your computer (no need to add hard disk)
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.