Class: Doodl::DijkstraShortestPath
- Inherits:
-
Object
- Object
- Doodl::DijkstraShortestPath
- Includes:
- SingleSourceShortestPath
- Defined in:
- lib/shortest_path/dijkstra.rb
Instance Attribute Summary collapse
-
#dist ⇒ Object
readonly
Returns the value of attribute dist.
-
#prev ⇒ Object
readonly
Returns the value of attribute prev.
Instance Method Summary collapse
-
#initialize(graph, source, weight_key = nil) ⇒ DijkstraShortestPath
constructor
A new instance of DijkstraShortestPath.
Methods included from SingleSourceShortestPath
Constructor Details
#initialize(graph, source, weight_key = nil) ⇒ DijkstraShortestPath
Returns a new instance of DijkstraShortestPath.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/shortest_path/dijkstra.rb', line 15 def initialize(graph, source, weight_key = nil) raise ArgumentError unless graph.is_a?(Graph) raise ArgumentError unless graph.contains_node?(source) raise ArgumentError if (weight_key and not graph.has_edge_data_key?(weight_key)) @graph, @source, @weight_key = graph, source, weight_key @dist, @color, @prev = {}, {}, {} @queue = PQueue.new { |x, y| @dist[x] < @dist[y] } @weight = @graph.edge_data(@weight_key) init_maps main_algorithm end |
Instance Attribute Details
#dist ⇒ Object (readonly)
Returns the value of attribute dist.
13 14 15 |
# File 'lib/shortest_path/dijkstra.rb', line 13 def dist @dist end |
#prev ⇒ Object (readonly)
Returns the value of attribute prev.
13 14 15 |
# File 'lib/shortest_path/dijkstra.rb', line 13 def prev @prev end |