Class: RGL::BellmanFordAlgorithm

### Home Classes Methods

### In Files

- lib/rgl/bellman_ford.rb

### Parent

Object

### Methods

- ::new
- #shortest_paths

### Class/Module Index

Quicksearch

- RGL
- RGL::AdjacencyGraph
- RGL::BFSIterator
- RGL::BellmanFordAlgorithm
- RGL::BellmanFordVisitor
- RGL::BidirectionalGraph
- RGL::BipartiteBFSIterator
- RGL::DFSIterator
- RGL::DFSVisitor
- RGL::DOT
- RGL::DOT::Digraph
- RGL::DOT::DirectedEdge
- RGL::DOT::Edge
- RGL::DOT::Element
- RGL::DOT::Graph
- RGL::DOT::Node
- RGL::DOT::Port
- RGL::DOT::Subgraph
- RGL::DijkstraAlgorithm
- RGL::DijkstraVisitor
- RGL::DirectedAdjacencyGraph
- RGL::Edge
- RGL::Edge::DirectedEdge
- RGL::Edge::UnDirectedEdge
- RGL::EdgePropertiesMap
- RGL::EdmondsKarpAlgorithm
- RGL::EdmondsKarpAlgorithm::EdmondsKarpBFSIterator
- RGL::Graph
- RGL::Graph::TarjanSccVisitor
- RGL::GraphIterator
- RGL::GraphVisitor
- RGL::GraphVisitor::ClassMethods
- RGL::GraphVisitor::DistanceMapSupport
- RGL::ImplicitGraph
- RGL::MutableGraph
- RGL::MutableGraph::MutableGraphParser
- RGL::NoEdgeError
- RGL::NoVertexError
- RGL::NonNegativeEdgePropertiesMap
- RGL::NotDirectedError
- RGL::NotUndirectedError
- RGL::PrimAlgorithm
- RGL::TopsortIterator
- Enumerable
- Object

No matching classes.

# RGL::BellmanFordAlgorithm

### Public Class Methods

new(graph, edge_weights_map, visitor) click to toggle source

Initializes Bellman-Ford algorithm for a graph with provided edges weights map.

    # File lib/rgl/bellman_ford.rb, line 37
    def initialize(graph, edge_weights_map, visitor)
      @graph            = graph
      @edge_weights_map = EdgePropertiesMap.new(edge_weights_map, @graph.directed?)
      @visitor          = visitor
    end

### Public Instance Methods

shortest_paths(source) click to toggle source

Finds the shortest path form the source to every other vertex of the graph.

Returns the shortest paths map that contains the shortest path (if it exists) from the source to any vertex of the graph.

    # File lib/rgl/bellman_ford.rb, line 48
    def shortest_paths(source)
      init(source)
      relax_edges
      PathBuilder.new(source, @visitor.parents_map).paths(@graph.vertices)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.