[Drawkit] For the brave ; -) (was Re: SonoDraw Beta 1 now available)
Graham Cox
graham.cox at bigpond.com
Tue Jul 29 21:37:14 PDT 2008
OK, you know me, I find it hard to resist a bit of neat code or a
knotty problem, so here's a (as yet completely untested, but verified
to compile without problems) attempt at wrapping up the shortest-route
finding algorithm in a Cocoa-friendly way.
Usage couldn't be simpler:
NSArray* sortedObjects = [DKTSP objects:[myLayer objects]
sortedByShortestRouteForKey:@"location"];
Of course you might find at this point it doesn't work, or handle bad
input very gracefully... good luck! (I will be testing it myself also
of course).
cheers, Graham
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DKTSP.h
Type: application/octet-stream
Size: 1341 bytes
Desc: not available
URL: <http://lists.apptree.net/pipermail/drawkit-apptree.net/attachments/20080730/e053fd32/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DKTSP.m
Type: application/octet-stream
Size: 13811 bytes
Desc: not available
URL: <http://lists.apptree.net/pipermail/drawkit-apptree.net/attachments/20080730/e053fd32/attachment-0003.obj>
-------------- next part --------------
On 30 Jul 2008, at 11:58 am, Graham Cox wrote:
>
> On 30 Jul 2008, at 11:30 am, Graham Cox wrote:
>
>> I ported some code from "Numeric Recipes in C" at the time that
>> used simulated annealing to come up with a path that for the most
>> part was very good - the perfect path isn't that important, just
>> one that's good enough and can be computed in a reasonable time.
>> Unfortunately I don't have that source any more but if you can get
>> hold of that book I can vouch for the algorithm!
>
>
> Who knows, maybe DK might end up with something like this built-in
> one day ;-)
More information about the Drawkit
mailing list