Pair project: Elevator Control Program

Source: Internet
Author: User
12061160 Liu yunpeng & 12061166 song tianshu
1.1 Advantages and Disadvantages of Pair Programming
Pair programming has many advantages over individual programming.
First, the role of supervision can be quickly put into work during the discussion. In order not to delay the other party's time, we will complete their respective tasks as soon as possible;
Second, save time and communicate with each other, and be able to quickly determine algorithm schemes, which is much faster than a person's painstaking thinking;
Third, to improve efficiency, some simple units can be divided into different persons after a person can easily complete the work. For the core unit, such as the elevator scheduling algorithm part of the project, this is a core part that needs to be discussed together. After discussion, we can determine a better solution to implement it. Or, if we encounter a bug, we can quickly and effectively solve the problem;
Fourth, reduce the learning cost. Two people read the code together. If there is no such thing, they can ask and discuss with each other at any time, learn new things, and learn more about existing knowledge, I also learned some good programming habits.
Disadvantages of Pair Programming: limited time spent working together; programmers with different habits can have trouble or even conflict at work; it is difficult for everyone to integrate the modified parts of the Code.
1.2 Advantages and Disadvantages of team members
First of all, Song tianshu is a brilliant and considerate person with strong programming skills. The disadvantage is that sometimes you are eager to seek success, and it will not begin until the TA finishes writing the code. Secondly, our second member is Liu yunpeng. He is a hardworking, cooperative, and easygoing person. Strong testing code and debugging capability. The disadvantage is that sometimes the efficiency is low.

1.3 Our Cooperation Process
My cooperation is like this:
1. Get the question, read the question together, and mine the question information;
2. Read the Code together, write comments, and discuss or query the code online in case of any questions;
3. put forward opinions on the elevator scheduling algorithm, discuss, simulate and determine the algorithm;
4. In actual coding, it is found that the algorithm discussed at the beginning is not very well implemented. Through on-site communication, the algorithm is modified and the code is modified;
5. Test and optimize the Code together;
8. basically satisfied with the performance of the elevator scheduling algorithm;
9. Start to write the UI. The UI is much harder to write than you think ......
10. write blog photos: 1.4 about information hiding, interface design, loose coupling:

Information Hiding: Information Hiding refers to hiding certain specific information, including attributes or methods, in the design module. It is not accessible to other classes that do not need such information. Information Hiding improves data security, prevents illegal changes to information in unrelated areas, and facilitates modular design of programs.

In the programming process, the use of information hiding technology requires us to have a deep understanding of the role of the data and methods of each module in the entire program, in the multi-layer design, layers are added to the interface layer. Secondly, all classes and classes are accessed through the interface class. At the same time, all data members of the class are private, all accesses are implemented through access functions.

Interface Design: an interface combines public non-static methods and attributes to encapsulate a set of specific functions.

An interface is a contract. In actual engineering, when we encounter some fixed specific functions in the module, we can encapsulate these functions as interfaces. Through interfaces, other engineers can quickly learn the attributes and implementation methods of elevator, passengers, scheduling schemes, requests, and other objects without worrying about specific implementation details.

Loose coupling: coupling refers to the degree to which one element has a direct understanding of another element. Loose coupling is a method of connecting components in a system so that these modules can depend on each other within the minimum feasible range. The loosely coupled architecture can reduce the overall complexity and dependency. Each module has its own independence and transmits information only through messages. modifying a module does not damage other modules, it is convenient for us to modify and manage different modules.

In software engineering, in order to avoid too many links between modules to avoid unnecessary or even dangerous involvement, we should try our best to make the information of each module as complete and independent as possible, so as to simplify testing, reduce risks.

 

1.5 about design by contract:

Contractual design is a method for designing computer software. This method requires software designers to define formal, accurate, and verifiable interfaces for software components. In this way, a prior condition, posterior condition, and non-Variant Form are added for traditional abstract data types. The precondition refers to the caller's responsibility to call a function and must be a true condition. When a function is violated, the function will never be called and data is transferred; the post-Condition refers to what the function can do and the state of the function completion type. The fact that the function will end and will not endless loops; the non-variable type indicates that the condition is always true from the caller's point of view. During the internal processing of the function, the non-variable type can be changed, but after the function ends, when the caller is returned, the non-variant must be true.

If a class function in object orientation provides a certain function, it must:

  • It is expected that all the customer modules that call it will ensure certain entry conditions: This is the prior condition of the function-the customer's obligations and the rights of the supplier, in this way, it does not need to deal with situations that do not meet the prior conditions.
  • A specific attribute is provided when exit is guaranteed: This is the function's posterior condition-supplier's obligation, which is obviously the customer's right.
  • It is assumed at entry time and some specific attributes are maintained at Exit: Unchanged.

Advantages:

Contract Makes the document better; contract is an inherent component of the Open View of class characteristics;

With more reliable documents, you must check the assertions during operation to ensure that the established contract is consistent with the actual operation of the program;

Assertions define the expected results of the test and are maintained by the Code, so that the program has clear test guidance;

It not only benefits accurate standards, but also enables programmers to continue working in the way they are familiar.

Disadvantages:

Assertions cannot be inherited along the inheritance hierarchy. If you redefine a basic method with a contract, the assertion that implements the contract will not be called correctly. You must manually adjust the class without changing the style, and the basic contract will not be implemented automatically.

 

1.6 code contract

The program code contract is. net Framework 4.0 is a new function. It is a solution proposed by Microsoft for the design by contract concept, mainly composed of preconditions and postconditions) and object invariants (Object invariants), which can easily add verification program code to the program code, reduce the program error rate, and improve the program quality, you can also integrate unit tests to reduce the workload of unit tests, or even integrate the document manager to make the output program files more detailed.

Code contracts provides the following four features:
1. Improve the degree of Automatic Testing
2. Static Verification
3. Execution phase Verification
4. file generation

 

In our code, the idea of contract is used between modules to ensure the equality of the two sides. If necessary, the non-variant and preconditions will be written in the comment of the method to ensure that the incoming parameters of the caller must be correct. At the same time, when conducting unit tests, we also perform necessary verification on methods with preconditions and non-variant patterns: Object validity and method correctness reasoning, this ensures that all method implementations meet the specification (contract) when the object state is not changed ).

 

1.7 unit test

In addition to private methods that cannot be tested, you can still fully overwrite the code block...

We can also see that the coverage of each module is quite impressive.

In particular, scheduler, because of the private methods run () and isatbottomfloor (), isattopfloor () cannot be tested to lower the overall coverage rate, and the coverage is comprehensive...

The test function is still quite difficult to write. For example, there are more than 100 rows of sweat in the test function to cover all the blocks written by the gettargetreq method ..

1.8uml

The following figure shows a brief description:

 

Due to the excessive details: a slightly more complex graph is captured.

1.9 uniqueness of Algorithms

In our algorithm, each elevator provides an elevator scheduling subroutine and defines _ dstpassengerqueue for storing floor requests sent by passengers, every passenger who enters the elevator sends a floor request to the team. Determine whether the queue is empty or not:

There are passengers in the elevator: if the elevator is not full or fully loaded, select the request in the same direction to the upper floor, the next destination of the elevator is the nearest direction request or the nearest destination (floor request) in _ dstpassengerqueue );

Otherwise, set the target floor to the next nearest passenger destination floor in the floor Request queue.

No passengers in the elevator: determines whether the direction is divided into four priority levels with the current elevator's historyction ction. Select from all direction requests on all floors in the same direction to the top (bottom, first, the request goes to the nearest direction in the same direction, and then the request goes to the farthest direction in the opposite direction. Then, the request is selected from all directions on all floors on the opposite direction to the top (bottom, first, the request is sent in the nearest direction in the same direction, and then the request in the farthest direction in the same direction.

 

[Additional Questions]

2.1 improve the interface design of elevator scheduling so that it can better reflect the reality and help students practice algorithms to better hide and share information.

1. Add a dynamic array of target floors to each elevator. That is, _ target in our program.

2. When reading the code, we found that it was too slow to close the elevator. You should add a button that can be quickly closed in the elevator and provide an interface.

3. provide a person with a speed to enter the elevator, and the elevator time will inevitably increase during peak hours. They cannot all be regarded as the same.

4. Add an elevator delay closing interface on the basis of 3.

 

2.2 design the UI to display and implement the movements of passengers/elevators.

Time is very tight. Developing a non-stop refreshing window with. Net is a bit like writing a Java game, but it also displays other information and updates in real time. I have never done it, but I don't know how many problems will happen. So we plan to design one step, implement one step, and see how much we can finally get.

Design 1. The basic function is to simulate the elevator operation process and display the corresponding ticks in real time.

Design 2. Provide buttons and dialog boxes for setting the configuration file

Use C # winform to show the elevator status through the movement of different labels; Use the content displayed on the label to indicate the elevator information.

The program consists of two threads: the UI thread and the thread where the elevator scheduling algorithm is located.

A thread runs the main program, and a thread refreshes the UI on every tick.

If I wanted to add a background image, I was forced to refresh the interface so that it would become stuck and eventually went ..

The two buttons are respectively used to set the configuration file. After the configuration is successful, the simulated elevator starts to run.

The average time of the final passenger is displayed and the prompt message is displayed:

2.3 read articles on MVC and mvvm design patterns. Describes how the UI/algorithm/interface you wrote implements the MVC or mvvm algorithm.

After reading MVC and mvvm related articles and Baidu introduction, we learned: 

MVC is a framework model that forcibly separates the input, processing, and output of an application. MVC applications are divided into three core components: model, view, and controller. m refers to the business model, V refers to the user interface, and C refers to the Controller. They process their own tasks. The most typical MVC is the JSP + servlet + JavaBean mode. The origin of the mvvm (Model-View-viewmodel) Framework is a new architecture framework that evolved from the combination of the Model-View-presenter model and WPF.

The mvvm mode is the same as the MVC mode. It mainly aims to separate views and models.

1. Low coupling. Views can be changed and modified independently of models. A viewmodel can be bound to different "views". When a view changes, the model can remain unchanged, when the model changes, the view can also remain unchanged.

2. reusability. You can put some view logic in a viewmodel so that many views can reuse this view logic.

3. independent development. Developers can focus on business logic and data development (viewmodel). Designers can focus on page design. Using expression blend can easily design the interface and generate XAML code.

4. testable. The interface has always been difficult to test, but now the test can be written for viewmodel.

In our scheduling algorithm, the MVC mode is implemented, which separates input and output from processing. Scheduler's main scheduling algorithm is responsible for processing the operations and scheduling of the elevator. The input is completely completed by the loader, and the output is completely completed by the elevator, sigmapasenger, and world.

Pair project: Elevator Control Program

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.