Pair project: Implementation and test of elevator scheduling algorithm

Source: Internet
Author: User
Tags naming convention

Pair programmer: 12061174 Li Jing

12061167 Lin Xupeng

Files are located in Pairproject11 on TFS

Algorithm core: Two key---1.history direction variable 2 There is no one in the elevator.

The initial direction of the elevator is up by default, at each tick point in time

If the elevator is on the ground floor, the history direction is on, if the top level is down.

When there is no one in the elevator, the first traversal request, if there is a consistent direction and can go to the floor request, then reqstopat the most recent.

If the current history dirction direction, there is no consistent direction of the floor request, then check if there is no direction inconsistent and the current history dirction direction can reach the floor request, if there is, Reqstopat meet the distance farthest from the situation, And make the elevator revs variable is true, (the revs variable is true when the passenger class will enter an inconsistent direction of the elevator, received the farthest passenger after this variable is false)

If the current history dirction direction, there is no floor request, the elevator direction, the next tick to judge.

When someone is in the elevator:

Traverse all the elevator internal requests, as well as the current history dirction direction up to, and the direction of the floor request, Reqstopat these requests in the most recent, each tick point is updated.

The characteristics of the algorithm are as follows:

This algorithm allows elevators to ensure that all requests in the current direction are taken into account in each direction, and that there is no request to consider the issue of steering.

In the debugging phase we see a situation, when a layer and 0 layers have a large number of requests, elevator each time can only take a part of the stairs, the best elevator should be sent to the perfect man immediately after the next manned up, while responding to the request. And we started to think of the scheduling algorithm, it is possible that the elevator in the upstairs to respond to high-level requests, and ignore the farther layer 0 and a layer of the request, so because the 0 and 1 levels of waiting for too many, will make the average scheduling time greatly increased. Using the new algorithm, the reverse of the time to prioritize the opposition up to meet the request of the furthest request, also to the floor of the 0, 1 layer of people, in fact, to ensure that the elevator will not ignore these farther requests.

For contract programming, it is required that the person explicitly provides the programmer with explicit requirements, and the programmer page must correctly implement the functions and goals that the person expects to achieve.

One pre-condition (precondiction):

        in order to invoke a function, the condition must be true, and in the case of its violation, the function is never called, and passing good data is the responsibility of the caller.         two post conditions (postcondiction):        function guarantees what can be done, the state of the function when it is completed, the fact that the function has this means that it will end, There is no endless loop.         Three class invariant (class invariant):        from the caller's point of view, the condition is always true, and in the process of internal processing of the function, the invariant item can be changed, However, when the function finishes, control returns to the caller, the invariant must be true.         in the test module, we guarantee the equal status of both sides, through the concept and requirements of the contract to interact with different modules to ensure that each step of the process is correct and scientific. At the same time, the validity of the method is verified and inferred when the unit test is carried out.            My advantages: in cooperative programming is to support the more delicate code style, to ensure the cleanliness of the code, and more emphasis on the algorithm after the completion of the program, to find problems in time.       Cons: Poor programming ability in C #, weak code, and long-time code reading.       Lin Xupeng Advantages: With the experience of Win8app Development, C # has strong programming ability and clear thinking.       Cons: When playing code there will be a time to make careless mistakes, often make some mechanical errors (wrong variable name, etc.), in the debug time spent a long time.            Pair programming advantages, the trooped team can compensate each other's shortcomings, such as my code is weak, Lin Xupeng can write code in the time to help me, When he wrote part of the code, I was able to quickly find out where he had the wrong number and correct the time to avoid debug.       at the level of algorithmic design, we can also put forward the shortcomings of the algorithm in a timely manner, and then discuss the improvement, and personal writing procedures, perhaps sometimes also need to tell each other about the details of your program that he does not understand the specifics of the implementation, a person can not.       Two person programming skill phaseMutual supervision, improve attention, but also in the debug, debugging into the bottleneck when the timely presentation of their views, timely advice to exchange common carp speed up the programming progress, timely solve the problem of hand errors and algorithmic structure problems.       Two pairs programming can also absorb the good advantages of each other, is conducive to upgrading their skills, a person cannot do.

Information hiding: First, in a class, defined variables and methods can be preceded by an underscore "_" to identify, which is a good naming convention, you can avoid inadvertently assigned to private members. When exchanging information between classes and classes, it is necessary to use a pre-designed method to access the private variables, so that if we invoke the private variables of another class within other classes, then we must define a method to get the private variables of that class, and to change the variables in another class within the other class We also define a way to change the private variables of that class. In C #, it is particularly handy to have set and get, and we can easily define a way to access a class-private variable.

Interface design: A good interface can be provided to the back of the design of a good framework, in this elevator scheduling project, interface Ielevator, Ipassenger, IScheduler, Irequest, we through the interface can quickly know the elevator , the passengers, the scheduling scheme, the properties of the request, which methods to implement, rather than the specifics of the implementation, so that our software testing becomes simpler.

Loose coupling: In our code design, don't worry about breaking code elsewhere. This low-dependency design method between classes and classes makes one class as if it were separated from another class, and they are only connected by messages, so when designing a class, you don't have to worry about destroying the other. When the code changes, you can not change our code on a large scale, we only use the location of a problem module, and then change it is good, and can do without changing the service of other modules.

Information hiding, interface design, loose coupling are the important methods of object-oriented design, are to make the program design more close to the daily understanding, in the relationship between large modules do not worry about the details, just in the module designed to work hard.

Here are the photos and some test information when pairing is programmed

Pair project: Implementation and test of elevator scheduling algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.