Class: RGL::DijkstraAlgorithm

### Home Classes Methods

### In Files

- lib/rgl/dijkstra.rb

### Parent

Object

### Methods

- ::new
- #find_shortest_paths
- #shortest_path
- #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::DijkstraAlgorithm

### Constants

DEFAULT_DISTANCE_COMBINATOR

  Distance combinator is a lambda that accepts the distance (usually from the source) to vertex u and the weight of the edge connecting vertex u to another vertex v and returns the distance to vertex v if it's reached through the vertex u. By default, the distance to vertex u and the edge's weight are summed.

### Public Class Methods

new(graph, edge_weights_map, visitor, distance_combinator = nil) click to toggle source

Initializes Dijkstra's algorithm for a graph with provided edges weights map.

    # File lib/rgl/dijkstra.rb, line 19
    def initialize(graph, edge_weights_map, visitor, distance_combinator = nil)
      @graph               = graph
      @edge_weights_map    = build_edge_weights_map(edge_weights_map)
      @visitor             = visitor
      @distance_combinator = distance_combinator || DEFAULT_DISTANCE_COMBINATOR
    end

### Public Instance Methods

find_shortest_paths(source) click to toggle source

Finds the shortest path from the source to every other vertex.

    # File lib/rgl/dijkstra.rb, line 48
    def find_shortest_paths(source)
      init(source)
      relax_edges
    end

shortest_path(source, target) click to toggle source

Finds the shortest path from the source to the target in the graph.

Returns the shortest path, if it exists, as an Array of vertices. Otherwise, returns nil.

    # File lib/rgl/dijkstra.rb, line 30
    def shortest_path(source, target)
      init(source)
      relax_edges(target, true)
      PathBuilder.new(source, @visitor.parents_map).path(target)
    end

shortest_paths(source) click to toggle source

Finds the shortest path form the source to every other vertex of the graph and builds shortest paths map.

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/dijkstra.rb, line 41
    def shortest_paths(source)
      find_shortest_paths(source)
      PathBuilder.new(source, @visitor.parents_map).paths(@graph.vertices)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.