[Objc] Dijkstra algorithm

A simple implementation of Dijkstra algorithm using ATM Metro of Milan to find the best route.

Full project on github or ZIP file here.

sshot

How to use

Copy in your project the files:
[code lang=”cpp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]APGraph.h
APGraphVertex.h
APGraphEdge.h
APGraphRoute.h
APGraphRouteStep.h
APGraphPoint.h
APGraphPointGeo.h
APGraphPointPixel.h

libAPGraph.a[/code]

and add an import for:

[code lang=”cpp” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]#import "APGraphLib.h"[/code]

Next, make a graph, adding vertex, edges and point (Geo or Pixel), like in the TestCase.

It’s all based on a custom JSON file, with id linked, containing the Metro info,

[code lang=”xml” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]
{
"id": "14",
"name": "Duomo",
"links": "13,15",
"weight": "1",
"position": [
{
"x": 682,
"y": 500
}
]
},
[/code]

To get best route, set from and to and go!

[code lang=”java” autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]NSString *from = @"Cadorna";
NSString *to   = @"Duomo";
APGraphVertex *fVertex  = [ APGraphVertex vertexWithIdentifier:from ];
APGraphVertex *tVertex  = [ APGraphVertex vertexWithIdentifier:to ];

APGraphRoute *route = [graph shortestRouteFromVertex:fVertex toVertex:tVertex];

NSLog(@"%@", route);[/code]

You can find more detail on the ZIP project, with a full working iPad version of this example, or on github.

®ATM and ATM logo are property of (ATM S.p.a.) – http://www.atm.it/

Ref: albertopasca.it

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.