https://github.com/alejandrodevs/dijkstra
My own Dijkstra's Algorithm implementation.
https://github.com/alejandrodevs/dijkstra
Last synced: 11 months ago
JSON representation
My own Dijkstra's Algorithm implementation.
- Host: GitHub
- URL: https://github.com/alejandrodevs/dijkstra
- Owner: alejandrodevs
- Created: 2014-05-19T15:47:53.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-01-14T21:08:55.000Z (about 11 years ago)
- Last Synced: 2025-01-25T21:56:21.658Z (about 1 year ago)
- Language: Ruby
- Size: 133 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dijkstra's Algorithm
## Getting Started
```
$ git clone git@github.com:alejandrogutierrez/dijkstra.git
$ cd dijkstra
```
## Usage
```ruby
# irb (shell)
require './dijkstra'
graph = Dijkstra::Graph.new
# Graph nodes.
graph.nodes.add('A')
graph.nodes.add('B')
graph.nodes.add('C')
graph.nodes.add('D')
graph.nodes.add('E')
# Graph edges and weights.
graph.nodes.edge('A', 'B', 10)
graph.nodes.edge('A', 'C', 25)
graph.nodes.edge('A', 'D', 10)
graph.nodes.edge('B', 'C', 20)
graph.nodes.edge('D', 'C', 10)
# Examples.
graph.dijkstra('A', 'C') # => { path: ['A', 'D', 'C'], distance: 20 }
graph.dijkstra('B', 'D') # => { path: ['B', 'A', 'D'], distance: 20 }
graph.dijkstra('A', 'E') # => { path: [], distance: Float::INFINITY }
```
## Testing
```
ruby -Ilib:test test/dijkstra_test.rb
```