Teaching classes:? 005 (Wednesday morning section thirty-four)
Project Address: [email protected]: bingokunkun / rg-homework1.git
PSP2.1 | Personal Software Process Stages | Estimated time consuming (minutes) | The actual time-consuming (minutes) |
---|---|---|---|
Planning | plan | ||
· Estimate | • Estimate how much time this task requires | 10 | 10 |
Development | Develop | ||
· Analysis | · Needs analysis (including learning new technologies) | 200 | 240 |
· Design Spec | Generate design documents | 30 | 30 |
· Design Review | · Design Review (and his colleagues reviewed the design documents) | 10 | 10 |
· Coding Standard | · Code specifications (development of appropriate norms for the current development) | 10 | 10 |
· Design | · Specific design | 40 | 40 |
· Coding | · Specific coding | 30 | 30 |
· Code Review | · Code Review | 30 | 40 |
· Test | · Test (self-test, modify the code, submit modifications) | 200 | 240 |
Reporting | report | ||
· Test Report | · testing report | 20 | 20 |
· Size Measurement | · Computing workload | 20 | 20 |
· Postmortem & Process Improvement Plan | · Hindsight, and propose process improvement plan | 40 | 50 |
- | total | 640 | 730 |
Problem-solving ideas
- After seeing the title first thought is to put all the points calculated, and then compared in turn re-check.
- The first step of course is to record information about all of the straight line. To avoid floating point, a straight line by the following formula I represent:
\ [Y = {\ FRAC KUP} {} {X} + {kdown \ FRAC BUP} {} {} bdown \] - Four storage array is required: kup, kdown, bup, bdown, then allow to work slightly simpler, the need for fraction k and b formalized profile, i.e. factored using GCD () function to complete.
- The second step is to determine the relationship between two lines, since previously been simplified, so here need only compare equal to kdown whether kup and determines whether or not parallel, if no intersection parallel, if there is a point of intersection parallel In this case the intersection coordinates:
\ ((\ FRAC XUP} {} {xdown, \ FRAC ydown} {} {Yup) \) stored. - The final step to traverse the intersection coordinates array, not the same number of points can be calculated
designing process
- The idea of solving, in addition to the main function, a total of three functions, respectively, with the read data (getInput), seeking the greatest common divisor (GCD), functional analysis of the number of intersections (handle).
- Wherein, the primary function calls getInput and handle, both the call gcd.
- Module test:
gcd: simple manual test, the random number input, true or false.
getInput: For the calculated kup, kdown, bup, bdown, the original data x0, y0, x1, y1 into the linear equation, the determination result is zero.
handle: The computed xup, xdown, yup, ydown brought into two straight lines, to determine whether the point on a straight line.
Improvement Process
- Be sure to record the time line information, but the beginning of the recording method need to go through a lot of computation, but also more likely to overflow. So, I spent the latter part of the direct recording x0, x1-x0, y0, y1-y0 way, the one will not overflow, and secondly, to facilitate future computing. At the same time the gcd function may or may not.
- After the change of the storage structure, found after performing several times multiplication, division only once to calculate the coordinates, then records the coordinates of the point of the double floating-point type can be used.
- After changing the storage point coordinates found quad into a tuple hash map easier to use, while the speed is faster, so the use of nested form unordered_map avoid duplication.
- Later I found a better form, using a pair <double, double> point coordinates stored in a manner, which set placed in a container (built-in way to make set free roll).
The picture shows a performance analysis, wherein the handle functions longest wasted
on 40,000 linear map data is randomly generated, wherein a large number of parallel straight configuration, can be seen, most of the resources of the parallel statement determines whether or waste. When there is no large number of parallel carefully constructed, for the most pointSet the insert function.
Code Description
void handleLL() {
long long xu, xd, yu;
for (int i = 0; i < num; i++) {
for (int j = i + 1; j < num; j++) {
xd = (long long)b[j] * d[i] - (long long)b[i] * d[j];
if (xd == 0) {
continue;
}
xu = (long long)b[j] * ad_bc[i] - (long long)b[i] * ad_bc[j];
yu = (long long)d[j] * ad_bc[i] - (long long)d[i] * ad_bc[j];
double px, py;
px = (double)xu / xd;
py = (double)yu / xd;
pair<double,double> p = make_pair(px, py);
pointSet.insert(p);
}
}
}
- Here the whole process is the most critical part, ABCD respectively recorded x0, x1-x0, y0, y1-y0, ad_bc record is the value of the ad-bc, purely to facilitate the calculation. Now want to calculate the coordinates of the intersection between the straight line i and line j (px, py), can be calculated xu, yu, xd mathematical derivation. Wherein, if xd zero, ij two parallel straight lines, there is no intersection; if not zero, then a value can be calculated coordinates (px, py) which will be set in the container, the size of the final output can be stored pointSet.