05-29-2015 04:19 PM
So are all points unique and integers? What is the typical range of values?
Can you at least attach an otherwise empty VI, but containing a typical array of points?
I guess you want to ultimately visit each point, at each step picking the closest new point. This is a much simpler problem than the traveling salesman, which is not solvable with that many points.
05-29-2015 07:20 PM - edited 05-29-2015 07:20 PM
Here's a simple solution (actually looks pretty similar to what you have) and it takes under 800ms for 15k points. I have not implemented the x-preference, so you could simply add your special scaling if needed. Should not change the timing much.
(LabVIEW 2014. There are probably bugs).
05-29-2015 07:33 PM
@GregFreeman wrote:
Thanks guys. We may also try "Binning" x and having some sort of buffer. At that point we can call X values that are sufficiently close on the same plane and sort, then go from there. Just a thought.
This will dramatically increase the speed because you would treat a small subset of points for each slice. Since the full algorithm looks like O(N²), just splitting it in 10 seperate slices will easily give you an order of magnitude. Just start at one end of a slice and patch the transitions to the next slice when you run out of points. Most of my code could be re-used.
05-29-2015 10:27 PM
Sometimes he amazes me. Often, in point of fact
06-01-2015 03:14 PM - edited 06-01-2015 03:15 PM
Altenbach, this worked well. I left the shell of mine the same, such as the in place element structure at the front etc. the only things I changed (per your VI) were:
1) Used imaginary numbers instead of polar
2) The inner for loop I used indexing rather than auto indexing so I didn't have to loop the full 15k iterations every time, even if the interation was a no-op.
I believe the long time was entirely due to the polar conversion, but I didn't go back and verify that in depth. As of now, on my PC, I'm under a second which I'm happy with.
Jeff, give me some credit, I was about 95% of the way there!
06-01-2015 04:05 PM
You can add some x bias by simply adding the RE value to the distance (you can even balance the two by multiplying the RE value by a positive scaling factor. The higher the multiplier the more it does "lowest X first" at a cost of overall path lenght. Note that this does not improve performance, while breaking the problem up into slices would.
As a good control when comparing algorithms, you should calculate the final path lenght (e.g. relative to the original path lenght).
06-01-2015 04:46 PM - edited 06-01-2015 04:47 PM
On my PC, replacing the Addition in the innermost loop with a shift register and a +1 primitive results in a minor minor improvement, takes a couple (literally only a couple) of ms off the total time. But the difference is so small, it might just be an artefact of benchmarking.
But as usual, Altenbach's solutions are pretty much spot on when it comes to performance.
06-01-2015 05:38 PM
@Intaris wrote:
On my PC, replacing the Addition in the innermost loop with a shift register and a +1 primitive results in a minor minor improvement, takes a couple (literally only a couple) of ms off the total time. But the difference is so small, it might just be an artefact of benchmarking.
Yes, shift registers operate in place and one would think that unary operations (+1) should be faster than something with two inputs, such as the addition. However, it is very well possible that the compiler actually generates the same code for both version. 😄 I cannot see a difference in speed here.
06-02-2015 01:09 AM
@altenbach wrote:
@Intaris wrote:
On my PC, replacing the Addition in the innermost loop with a shift register and a +1 primitive results in a minor minor improvement, takes a couple (literally only a couple) of ms off the total time. But the difference is so small, it might just be an artefact of benchmarking.
Yes, shift registers operate in place and one would think that unary operations (+1) should be faster than something with two inputs, such as the addition. However, it is very well possible that the compiler actually generates the same code for both version. 😄 I cannot see a difference in speed here.
That doesnt surprise me. Is probably just my PC messing with my head..... crafty devils those PCs....