https://github.com/username0x0a/dijkstra
Simple objective implementation of Dijkstra algorithm (shortest path search) written in Objective-C
https://github.com/username0x0a/dijkstra
dijkstra dijkstra-algorithm objc objective-c shortest-path-problem shortest-paths
Last synced: 5 days ago
JSON representation
Simple objective implementation of Dijkstra algorithm (shortest path search) written in Objective-C
- Host: GitHub
- URL: https://github.com/username0x0a/dijkstra
- Owner: username0x0a
- License: mit
- Created: 2020-04-23T21:51:11.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-23T22:03:43.000Z (about 5 years ago)
- Last Synced: 2025-03-01T16:22:43.708Z (4 months ago)
- Topics: dijkstra, dijkstra-algorithm, objc, objective-c, shortest-path-problem, shortest-paths
- Language: Objective-C
- Size: 41 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dijkstra
Example _Dijkstra_ algorithm (shortest path problem) implementation written in Objective-C.
## Usage

```swift
#import// Define the nodes
DJKNode *Brno = [DJKNode nodeWithID:@"Brno"];
DJKNode *Praha = [DJKNode nodeWithID:@"Praha"];
DJKNode *Ostrava = [DJKNode nodeWithID:@"Ostrava"];
DJKNode *Pardubice = [DJKNode nodeWithID:@"Pardubice"];
DJKNode *Kolin = [DJKNode nodeWithID:@"Kolin"];
DJKNode *Plzen = [DJKNode nodeWithID:@"Plzen"];
DJKNode *Adamov = [DJKNode nodeWithID:@"Adamov"];// Define the graph edges
NSArray *edges = @[
[DJKEdge edgeFromNode:Ostrava toNode:Brno cost:180],
[DJKEdge edgeFromNode:Praha toNode:Ostrava cost:420],
[DJKEdge edgeFromNode:Pardubice toNode:Brno cost:110],
[DJKEdge edgeFromNode:Pardubice toNode:Praha cost:90],
[DJKEdge edgeFromNode:Pardubice toNode:Plzen cost:140],
[DJKEdge edgeFromNode:Pardubice toNode:Ostrava cost:290],
[DJKEdge edgeFromNode:Plzen toNode:Praha cost:70],
[DJKEdge edgeFromNode:Adamov toNode:Adamov cost:0],
];// Initialize the graph itself
DJKGraph *G = [DJKGraph graphWithEdges:edges];
// Look for shortest paths and print'em
NSLog(@"%@", [G shortestPathFromNode:Praha toNode:Ostrava]);
// [Praha, Pardubice, Ostrava]
NSLog(@"%@", [G shortestPathFromNode:Ostrava toNode:Plzen]);
// [Ostrava, Pardubice, Plzen]
NSLog(@"%@", [G shortestPathFromNode:Ostrava toNode:Ostrava]);
// [Ostrava]
NSLog(@"%@", [G shortestPathFromNode:Brno toNode:Kolin]);
// []
```## License
Dijkstra example is released under the MIT license. See the LICENSE file for details.