Giter Club home page Giter Club logo

jldijkstra's Introduction

JLDijkstra

Get a shortest route based on Dijkstra Algorithm.

Usage

1. Build a Route Map

1-1. example of get a graph from file
- (NSDictionary *)graphFromFile {
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"route" ofType:@"plist"];
    NSDictionary *graphFromFile = [[NSDictionary alloc] initWithContentsOfFile:filePath];
    return graphFromFile;
}

1-2. example of get a graph from code
- (NSDictionary *)graphFromCode {
    return @{@"A":@{@"B":@(4),@"C":@(0.9)},
             @"B":@{@"E":@(4)},
             @"C":@{@"B":@(2),@"D":@(4)},
             @"D":@{@"E":@(4)}
             };
} 

2. Include below 2 files in your project.

JLDijkstra.h
JLDijkstra.m

3. Code like below.

import header

#import "JLDijkstra.h"

create a map graph

NSDictionary *graph = [self graphFromFile];
OR
NSDictionary *graph = [self graphFromCode];

Execute Dijkstra

JLDijkstra *dijkstra = [[JLDijkstra alloc] init];
JLDijkstraResult *result = [dijkstra getRouteFromGraph:graph
                                           startVertex:@"A"
                                             endVertex:@"E"];

See the result

if(result) {
    NSLog(@"route : %@", result.route);
    NSLog(@"distance : %.1f", result.distance);
}
else {
    NSLog(@"no result");
}

Result Sample

route : (
    A,
    C,
    B,
    E
)
distance : 6.9

Demo

A sample project is included. :-D

License

JLDijkstra is available under the MIT license. See the LICENSE file for more info.

jldijkstra's People

Contributors

buhikon avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.