Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dijkstra's algorithm on iOS

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.

like image 981
user1278974 Avatar asked Jun 06 '12 18:06

user1278974


2 Answers

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.

like image 190
Peter M Avatar answered Sep 19 '22 23:09

Peter M


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

like image 33
ArturOlszak Avatar answered Sep 18 '22 23:09

ArturOlszak