A first operation unit summary OO - expression derivative

A first operation unit summary OO

The first job

Structure analysis code based on the metrics

  • The basic algorithm

    The first job is a simple polynomial function to solve the guide, do not need to input data to the legitimacy judgment,

The basic idea is to (coeff, expo)represent tuples coeff*x**expo, and polynomial each item can be stored in the form tuple, the benefits of this is that every single store in the form of polynomial specification, derivation rules will become very simple , plus there is no need to consider the legality of the input data or not, simplification relatively simple, so as to achieve quickly.

Of course, disadvantages are also obvious, scalability poor, only support simple polynomial, the next iteration have to reconstruct.

  • UML 类图:

 

 

  • Coupling Analysis:

 

 

Specific binding analysis of the code, this assignment to write four class, the main class ; Polycomputer , to parse the string to generate expression Poly objects; Poly class, using the expression ArrayList storage, and management of the various kinds of data are put Poly in this class of, such as adding a new item, derivation, simplifying etc., term class represents an item.

Coupling analysis showed substantially minimize complexity of the whole process, preferably an overall degree of structure of the program;

The method smpAndPrint () and PersePoly () did more work, resulting in cyclomatic complexity (v (G)) and a module design complexity (iv (G)) are large. This shows smpAndPrint () module design is not good enough, leading to frequent scheduling between the modules, the module also carries more features, more control statements.

Come to think of two ways to achieve this is indeed not good enough, because the Poly class storage with List expression, leading to simplification of the time had to create a new HashMap , the expression after simplification by HashMap said that this put less any existing classes, can only incidentally printout, do not only consume memory resources, but also greatly limits the scalability, for example, we can not operate on a single item, it can not simply be simplified processing . If Poly class using HashMap storage, it can be well decoupled.

Beta

Cece strong a bug, when the expression is simplified output may have a coefficient of "0" when the connector without adding any item 0, scored only 91 points, so profound understanding of the importance of strong measured.

Where class issues and approaches for the Poly class smpAndPrint () , since this method poorly designed, resulting in print when no special sentence 0, wrong.

Mutual Testing

  • It was hack six times, both in attack this point ooo;

  • Mutual Testing Policy

First, using a manual configuration data for testing, black box testing, code design do not own observation of the structure of the program under test, but I think this job is relatively simple, you write very much the same, so the emphasis on the boundary conditions, combined mode, simplification tests, such as coefficient or index of 0, hack successfully five times, the last of the other code simply look and found a non-homogeneous bug should be three;

After that, inspired by the structure of the forum posts a simple evaluation machine, a bug but did not measure up.

Second job

Structure analysis code based on the metrics

  • The basic algorithm

The second operation increases simply cosine function, and some combination of rules, and the need to judge the legitimacy of the data;

Reconstruction of the week - are the current and previous job requires a lot of work changes, a die-tuple, the input data have to be determined; however, I discovered that after each one can be expressed as simplified a*x**b*sin(x)**c*cos(x)**dform, so using the quad (a,b,c,d), and learned the last lesson, expression classes Expressionusing HashMap<(b,c,d),a>containers to store the expression, it is a good merger of similar items, but also conducive to further simplification. For the legality of data input processing, it is then judged by Taisho, but parse the string extracted item when it is more targeted small regular.

This assignment to write time is not yet thought of good should simplify how, after the completion of the basic functions, out of consideration to achieve a trade-off between accuracy and performance of difficulty and I decided to only basis sin(x)**2+cos(x)**2=1be simplified.

Ideas are as follows: to achieve in Expression implementation class simplify the method to re-create a hashmap<(a,b,c+d),List<c>>, which (a,b,c+d)is newly added vector class SmpVector , (a,b,c+d)completely equal terms, means that there is hope to merge simplification, so there will be hope of items in a container, List of processing each, such that c1 and c2 difference of 2 may be combined, so that it is possible to achieve simplification.

  • UML 类图:

  • Coupling Analysis:

 

 

From the measurement and analysis point of view, Homework2 although to achieve a lot of class, but the design of the structure is quite clear, in general each class is fairly carry out their duties, the only downside is rewriting Expression of toString methods and DealString of StringParse method You may write too complicated? Each one should realize toString then Expression call. DealString too.

Beta

With the last time a strong intensity measurement error measured points down to 90, ROOM B down to the house of the painful lessons before the test I had a good test to submit the test of Python syntax is not enough skilled, less likely to use Exger and Sympy library , this did not have time to build evaluation machine.

Hands full measure, construct their own test data, configuration strategy is to first construct the basic data to ensure that the basic function properly implement; after considering the boundary conditions, the legitimacy of data, as many combination rules, and so some complex data structure, especially for data legitimacy and boundary conditions, almost every time the data structure will involve boundary cases, after the index was calculated as the coefficient simplified to 0, after the merger cancellation and the like. Such construction measure a lot of bug, specifically spent a night, but fortunately, measured and AC intensity measurement on the whole, but still a hack by classmates. Since only the optimization based on the comparison, the performance points obtained 14.00021 / 20.

I think it is very important to beat, but I forgot all about the python.

Mutual Testing

  • By HACK: The ROOM mutual test everyone very polite, just leave, do not deliberately submit homogeneous data. Hack or be a bug, it is toString when printing, a special judge should have special symbols in every sentence, but I was only an expression of the first special judge. indeed a bug in the ring where ORZ modular design complexity and high complexity.

  • HACK:

Manual review, I feel this is the big brother house, code style are good, nothing a manual testing afternoon, bitterly to leave.

Sunday night and then test and found that I missed Saber, manually constructed strange data measured two hours to find even five bug (later found at least three non-homogeneous). In fact, feeling suddenly manually constructed advantages are obvious, if it is automatic evaluation may not necessarily be measured out, after all, some of the data I am also a step by step constructed in accordance with the results of his feedback, kinda tricky.

The third operation

Structure analysis code based on the metrics

This operation adds 表达式因子data, a variety of combinations, support for nested, derivation rules increases, check the legitimacy of data requirements are high, I feel a lot of difficult, I almost thought to be ineffective homework.

Is the reconstruction of the week - the last time decided to use quads realized that the third job will inevitably have to reconstruction, although attempts to architecture a higher level of abstraction, but do not know how to achieve, so only reluctantly use quad. The lesson just talked about inheritance and interfaces, suddenly realized that I had actually thought disorders can achieve with an interface to solve.

The idea of work as follows: followed the advice of the guide book, will these basic factors , and these basic operations as different classes, and then you can build an expression tree implementation. They have achieved a common interface , support and . Here I used the binary tree, which is the basis for calculation only support two operations.sin(x) cos(x) 幂函数因子 常数因子加法``乘法 嵌套Function求导takeDerivativetoString

The general idea of such relatively clear, build a binary tree when parsing a string to build from the bottom up start; output expression trees only need to call an expression toStringmethod can be implemented recursively.

I believe that when dealing with strings need to be careful here, because 表达式因子we can not continue to use the Taisho is determined to extract a string. Here I will replace the outermost parentheses [], []which replaced all the contents E, so you can use regular expressions to extract string, can initially determine the legality of expression; in order to further sub-expressions can be resolved before the content Alternatively back, it can be determined recursively. So check the legality of construction of binary input data and are in a recursive step by step.

  • UML 类图:

 

 

  • Coupling Analysis:

 

 

The work is mainly wanted stability, but to work effectively, all capable of measuring strong AC. Because there is still time so could not resist a brief optimized. Simplification mainly for the operator for example. * If two operands are constants a, b, is a constant return * B; There are other about 0 or +1 or -1 Laid judgment ..... and so on this way to achieve simple, and because it is recursive, in fact, simplification will recursively go on, not only to reduce the burden of recursion, prevent TLE, and simplification of the effect is also very good.

Of course, then a little thought, if the tree is more than an expression tree that addition and multiplication can have multiple operands, the above ideas to simplify the effect may be even better. It was unfortunate that the basic framework has been written, it is difficult major changes, only to give up.

Beta

Hands full measure when debug due plus enough time for python syntax is familiar, no evaluation machine, hand measurement is upset. Complex procedures to take a really good choice, because too many brackets enter slightly more complicated would get a lot of output brackets, the naked eye is difficult to judge right or wrong, manual data structure is really risky. Fortunately, this algorithm may be relatively simple, many are handed over to the recursive auto-complete, the beta does not appear bug, performance score 17.0578 / 20.

Mutual Testing

  • Is HACK: The job is not valid the HACK;

  • HACK: . Since there is no evaluation machine, can only be measured hand, some simple data structure that end, I will focus on the legality of the test level, some of the data that is constructed so that the output should be a legal expression, but he output WF or illegal expression. in this way hack successfully three times.

And comparing experiences

  • Observe the excellent four chiefs of the code, I found that Lin Yujing students achieve my improvement programs, namely the multi-tree. I am most impressed with is his organization was very clear code structure, each method is not more than fifty lines, recursive calls in different ways to the same class; in addition to his simplified approach also impressed me, he after simplification is to build, I build a side edge of simplification, it can not say one is better, I may approach on resource consumption dominant, dominant on his way to code organization, decouple well. In short, by contrast, my organization, architectural design can have a lot to learn.

  • This module allows object-oriented thinking I have a deeper understanding and experience, in general can tell my three jobs are constantly trying to use object-oriented thinking, the average intensity measurement is also steadily this unit learned a lot of useful knowledge, but to learn the lesson alone is not enough, there are many design ideas need to learn to digest. in addition, this work also has some regrets, although such third time I try to use the job factory mode, but it does not seem to play the desired effect; and hand measurements are important to shoot, I should have a good grasp of how to achieve the shot .....

But in general it is good, refueling ~

 

Guess you like

Origin www.cnblogs.com/yzmcoding/p/12537441.html