June 23, 2009 12:56 PM PDT
Line Segments: Test Data. Post your results.
I've attached my test (1MB) input file. The process of generation is following. There are 3 input parameters: count, length, and limit. count is the number of line segments, length is the maximum length of a segment in each dimention, and limit determines range of values for coordinates. Here is piece of code:
My program has found 1622 intersections in 21 sec. However I am not 100% sure in correctness of my program now. Since it's difficult to manually compare output of one program with output of another program, I propose following method for quick verification/comparison of results. The idea is to compute some "hash" of results. Hash must be stable to following reorderings: A B C D must yield the same hash as: D C B A
But not stable to following reorderings: A B C D must not yield the same hash as: A C B D
Here is algorithm I currently use: char hash [4] = {}; for (size_t i = 0; i != results.size(); i += 1) { line_t const* line1 = results[i].line1; line_t const* line2 = results[i].line2; for (int t = 0; t != 4; t += 1) hash[t] ^= (line1->name[t] + line2->name[t]); } } printf("count=%u (%u)\n", results.size(), *(unsigned*)sample);
However I am not 100% sure in correctness of my program now. Since it's difficult to manually compare output of one program with output of another program, I propose following method for quick verification/comparison of results. The idea is to compute some "hash" of results....
Another approach is to run the output through sort and then compare the sorted outputs.
Another approach is to run the output through sort and then compare the sorted outputs.
Well, this will definitely produce better results, however one will have to attach own results and download others results, then pass them through some utility, and somebody has to develop that utility first... What I would prefer is something much more "lightweight". Probably good variant will be to sort results and then calculate SHA1.
Can you post your results please? I want to verify visually whether I've missed any intersections. I'll let you know what I find out. Here's mine (linux)...
For knapsack it was easier, if you have higher value and your solution is feasible then you are on the safe side. For line segments it's unclear which solution is "more right". My first attempt also yield some 4 thousands intersections, however then I re-implement it more carefully and it yield only 1622. It's not to say that my answer is correct, I am totally unsure that it is correct.
I would be nice if somebody will construct input file with several tens of different corner cases and manually calculate correct answer... AMD Threadfest was much contestant-friendlier in this aspect - they initially provide a number of input datasets, pre-calculated correct results, simple reference implementation of the program and precisely describe input data generation process, so that contestants was able to concentrate on the problem itself...
They do not seem to intersect at all. Look at their "y" (second) coordinates: 0 - -16 and 181 - 184. How they can intersect?
Btw, I've found error in my code, now my result is: count=1858 (1699850). I think it's in the common interests to agree on result for at least one problem :)
Btw, I've found error in my code, now my result is: count=1858 (1699850). I think it's in the common interests to agree on result for at least one problem :)
Attached my current output with 1858 intersections.
I believe these are the correct values: k?#!: (3, 181, 10) - (-11, 184, -10) ;:)!: (3, 181, 10) - (-9, 184, -6)
The points intersect at (3, 181, 10)
Damn! Sorry for that. I used case-insensitive search. Then I have to verify why I did not include "k?#! ;:)!" into results. I think for the next input file I will use only alphanum chars ('A-Z', '0-9'), it will be enough to generate up to 1.5M segments.
Attached my current output with 1858 intersections.
All of your solutions were also found by my program. There are additional intersections that you've missed: For example, here's one that I've verified: 4&$! DI&!
All of your solutions were also found by my program. There are additional intersections that you've missed: For example, here's one that I've verified: 4&$! DI&!
All of your solutions were also found by my program. There are additional intersections that you've missed: For example, here's one that I've verified: 4&$! DI&!