Class: Doodl::BellmanFord
- Inherits:
-
Object
- Object
- Doodl::BellmanFord
- Includes:
- SingleSourceShortestPath
- Defined in:
- lib/shortest_path/bellman_ford.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 = nil) ⇒ BellmanFord
constructor
A new instance of BellmanFord.
Methods included from SingleSourceShortestPath
Constructor Details
#initialize(graph, source, weight = nil) ⇒ BellmanFord
Returns a new instance of BellmanFord.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/shortest_path/bellman_ford.rb', line 12 def initialize(graph, source, weight = nil) raise ArgumentError unless graph.is_a?(Graph) raise ArgumentError unless graph.contains_node?(source) @dist, @prev = {}, {} @graph, @source, = graph, source if weight @weight = weight else @weight = Hash.new(1) end init_maps main_algorithm check_for_negative_cyles end |
Instance Attribute Details
#dist ⇒ Object (readonly)
Returns the value of attribute dist.
11 12 13 |
# File 'lib/shortest_path/bellman_ford.rb', line 11 def dist @dist end |
#prev ⇒ Object (readonly)
Returns the value of attribute prev.
11 12 13 |
# File 'lib/shortest_path/bellman_ford.rb', line 11 def prev @prev end |