Module: DijkstraFast::ShortestPath
- Included in:
- Graph
- Defined in:
- lib/dijkstra_fast/shortest_path.rb
Overview
Interface to allow arbitrary classes to calculate the shortest path between two "items" using a native implementation of Dijkstra's algorithm.
Instance Method Summary collapse
-
#connections(source) {|Object, int| ... } ⇒ nil
Returns the edges originating at source.
-
#shortest_distance(source, dest, progress: false) ⇒ int
Finds the shortest distance between items.
-
#shortest_path(source, dest, progress: false) ⇒ Array<int, Array>
Finds the shortest path between items, returning both the path as well as the total distance travelled.
Instance Method Details
#connections(source) {|Object, int| ... } ⇒ nil
Returns the edges originating at source
64 65 66 |
# File 'lib/dijkstra_fast/shortest_path.rb', line 64 def connections(source) # Does nothing by default but should be implemented by class end |
#shortest_distance(source, dest, progress: false) ⇒ int
Finds the shortest distance between items
91 92 93 |
# File 'lib/dijkstra_fast/shortest_path.rb', line 91 def shortest_distance(source, dest, progress: false) shortest_path(source, dest, progress: progress).first end |
#shortest_path(source, dest, progress: false) ⇒ Array<int, Array>
Finds the shortest path between items, returning both the path as well as the total distance travelled.
78 79 80 |
# File 'lib/dijkstra_fast/shortest_path.rb', line 78 def shortest_path(source, dest, progress: false) Native.new(self).send(:shortest_path, source, dest, progress: progress) end |