Forum Jump

Select Group :
Select Forum :
Sorted By :
Sort Order :
From The :
 
Thread Tools  Search this thread 
Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
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:

int coord [6];
for (int n = 0; n != count; n += 1)
{
for (int j = 0; j != 3; j += 1)
coord[j] = (int)(rand_gen() * limit);
for (int j = 0; j != 3; j += 1)
coord[j + 3] = coord[j] + (int)(rand_gen() * length * 2) - length;
fprintf(f, "%s %d %d %d %d %d %d\n", name, coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]);
}

Parameters for attached file are: count = 100'000, limit = 200, length = 20.

 Attachments 
Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 23, 2009 1:12 PM PDT
Rate
 
#1
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);

My output is:
count=1622 (1711155)



Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 23, 2009 1:33 PM PDT
Rate
 
#2 Reply to #1
Post your time and result (number of intersections and hash).

Suggestions on how to improve input data generation process and hash calculation are welcome.




Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 23, 2009 2:18 PM PDT
Rate
 
#3 Reply to #1
Quoting - Dmitriy Vyukov
My program has found 1622 intersections in 21 sec.

Simple optimization reduced time to 6247ms.



Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 23, 2009 2:49 PM PDT
Rate
 
#4 Reply to #3
Quoting - Dmitriy Vyukov
Simple optimization reduced time to 6247ms.

Drop in single pragma omp. Time is 1731ms.



BradleyKuszmaul
June 24, 2009 8:25 AM PDT
Rate
 
#5 Reply to #1
Quoting - Dmitriy Vyukov

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.



邓辉
Total Points:
3,850
Status Points:
3,350
Brown Belt
June 24, 2009 9:56 AM PDT
Rate
 
#6 Reply to #2
hi Dmitriy Vyukov

My program has found 5352 intersections in 6 sec.

--------
写字楼里写字间,写字间里程序员
程序人员写程序,又拿程序换酒钱
酒醒只在网上坐,酒醉还来网下眠
酒醉酒醒日复日,网上网下年复年


akki
Total Points:
2,720
Status Points:
2,220
Brown Belt
June 24, 2009 10:30 AM PDT
Rate
 
#7 Reply to #3
Quoting - Dmitriy Vyukov

Simple optimization reduced time to 6247ms.


My brute force implementation says there are 4788 intersections...


Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 10:31 AM PDT
Rate
 
#8 Reply to #5
Quoting - BradleyKuszmaul
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.



akki
Total Points:
2,720
Status Points:
2,220
Brown Belt
June 24, 2009 10:38 AM PDT
Rate
 
#9 Reply to #6
Quoting - 邓辉
hi Dmitriy Vyukov

My program has found 5352 intersections in 6 sec.


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)...

Thanks.


 Attachments 
Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 10:44 AM PDT
Rate
 
#10 Reply to #7
Quoting - Dmitriy Vyukov
My program has found 1622 intersections in 21 sec.


Quoting - akki
My brute force implementation says there are 4788 intersections...

Quoting - 邓辉
My program has found 5352 intersections in 6 sec.


Cool! I like this :)

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...



akki
Total Points:
2,720
Status Points:
2,220
Brown Belt
June 24, 2009 10:48 AM PDT
Rate
 
#11 Reply to #5
Quoting - BradleyKuszmaul
Another approach is to run the output through sort and then compare the sorted outputs.


that won't work if one implementation prints
AAAA BBBB

and another prints
BBBB AAAA

Maybe you can use this...


 Attachments 
Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 11:39 AM PDT
Rate
 
#12 Reply to #7
Quoting - akki
My brute force implementation says there are 4788 intersections...


I found in your output following intersection:
k?#! ;:)!

The coordinates are:
k?#!      3 0 37          -10 -16 20
;:)!      3 181 10        -9 184 -6

They do not seem to intersect at all. Look at their "y" (second) coordinates: 0 - -16 and 181 - 184. How they can intersect?




Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 11:44 AM PDT
Rate
 
#13 Reply to #12
Quoting - Dmitriy Vyukov

I found in your output following intersection:
k?#! ;:)!

The coordinates are:
k?#!      3 0 37          -10 -16 20
;:)!      3 181 10        -9 184 -6

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 :)



Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 11:45 AM PDT
Rate
 
#14 Reply to #13
Quoting - Dmitriy Vyukov


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.



 Attachments 
akki
Total Points:
2,720
Status Points:
2,220
Brown Belt
June 24, 2009 1:40 PM PDT
Rate
 
#15 Reply to #12
Quoting - Dmitriy Vyukov


I found in your output following intersection:
k?#! ;:)!

The coordinates are:
k?#!      3 0 37          -10 -16 20
;:)!      3 181 10        -9 184 -6

They do not seem to intersect at all. Look at their "y" (second) coordinates: 0 - -16 and 181 - 184. How they can intersect?




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)


Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 1:52 PM PDT
Rate
 
#16 Reply to #15
Quoting - akki
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.



akki
Total Points:
2,720
Status Points:
2,220
Brown Belt
June 24, 2009 1:58 PM PDT
Rate
 
#17 Reply to #14
Quoting - Dmitriy Vyukov

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&!

4&$!: (34, 115, 36) - (48, 125, 50)
DI&!: (68, 113, 32) - (48, 125, 50)




akki
Total Points:
2,720
Status Points:
2,220
Brown Belt
June 24, 2009 2:04 PM PDT
Rate
 
#18 Reply to #17
Quoting - akki

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&!

4&$!: (34, 115, 36) - (48, 125, 50)
DI&!: (68, 113, 32) - (48, 125, 50)



Looks to me like you've missed the ones that have common end-points...


Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 2:05 PM PDT
Rate
 
#19 Reply to #17
Quoting - akki

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&!

4&$!: (34, 115, 36) - (48, 125, 50)
DI&!: (68, 113, 32) - (48, 125, 50)

Thank you!
I will verify why my program misses it, as well as "k?#! ;:)!".
Hope will get at least 2 people with equal results.


Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 2:18 PM PDT
Rate
 
#20 Reply to #7
Quoting - akki
My brute force implementation says there are 4788 intersections...


Cool! I get: count=4788 (1047121)




akki
Total Points:
2,720
Status Points:
2,220
Brown Belt
June 24, 2009 2:22 PM PDT
Rate
 
#21 Reply to #20
Quoting - Dmitriy Vyukov


Cool! I get: count=4788 (1047121)



Excellent! :)


Dmitriy Vyukov
Total Points:
25,382
Status Points:
25,382
Black Belt
June 24, 2009 2:26 PM PDT
Rate
 
#22 Reply to #20
Quoting - Dmitriy Vyukov
Cool! I get: count=4788 (1047121)

It was float tolerance error. I made tolerance in the wrong direction, so all corner cases (segment end is intersection point) were stripped.




邓辉
Total Points:
3,850
Status Points:
3,350
Brown Belt
June 25, 2009 6:59 AM PDT
Rate
 
#23 Reply to #21
=C)! 199 164 110 199 174 106
^9)! 199 156 110 199 166 94

This will lead to the straight-line bugs me。
My answer now is 4788 too。 thanks。



--------
写字楼里写字间,写字间里程序员
程序人员写程序,又拿程序换酒钱
酒醒只在网上坐,酒醉还来网下眠
酒醉酒醒日复日,网上网下年复年


Ruben Penalva
Total Points:
480
Status Points:
430
Green Belt
June 25, 2009 5:19 PM PDT
Rate
 
#24 Reply to #23
Quoting - 邓辉
=C)! 199 164 110 199 174 106
^9)! 199 156 110 199 166 94

This will lead to the straight-line bugs me。
My answer now is 4788 too。 thanks。


Here too: 4788 hits :D

But with my serial brute force algorithm I get 351.508s...... thats depressing! :P


--------
http:///www.rpenalva.com


 Attachments 
Ruben Penalva
Total Points:
480
Status Points:
430
Green Belt
June 25, 2009 5:49 PM PDT
Rate
 
#25 Reply to #24
Quoting - Ruben Penalva
Here too: 4788 hits :D

But with my serial brute force algorithm I get 351.508s...... thats depressing! :P

Allright! I removed a push_back operation to store the intersection and it goes down to ~6secs.

--------
http:///www.rpenalva.com




Intel Software Network Forums Statistics

8442 users have contributed to 31547 threads and 100373 posts to date.
In the past 24 hours, we have 11 new thread(s) 33 new posts(s), and 44 new user(s).

In the past 3 days, the most popular thread for everyone has been /fpp interferes with breakpoints/stepping through code - again The most posts were made to Help with hitting maximum record length in the compiler with debug info? The post with the most views is You could save the pre-proce

Please welcome our newest member mrnm