I am tracking locations and their connections to other locations.
I keep locations in an NSArray while each location is represented as a Dictionary. Each location has Dictionary has the attributes (locationName, Connections, latitude, longitude) where Connections is an Array of other locations this location is connected TO (not from). I use lat/lon and a Haversine algorithm to determine the distance between two points.
NEXT, I would like to use dijkstra's shortest path algorithm to find the shortest path between a source and destination location (source and destination are selected by the user)
This is not for commercial use and does not need to support hundreds or thousands of locations.
I am looking for some objective C code that will perform this search.
A quick google found some objective-c code at snyderp / PESGraph which says
PESGraph is a simple graph implementation for Foundation.kit that allows for greating structures of nodes and paths, and then finding the shortest path between them. It includes unit tests that also provide some examples of how to use the code.
Also this question was previously asked on SO theres-an-easy-way-to-apply-a-shortest-path-alghoritm-in-objective-c and the solution pointed to the same git repository that I found through google.
I had to write my own sample code, because I wasn't able to find any good and working example. You can check it here:
https://github.com/aolszak/AOShortestPath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With