Sha256: a8864d07dcb1d858f0773cb8fc675827733314f71e15e96e0cc93eb7ec2c85f0

Contents?: true

Size: 749 Bytes

Versions: 17

Compression:

Stored size: 749 Bytes

Contents

require 'rgl/base'
require 'rgl/graph_visitor'

module RGL

  # Dijkstra shortest path algorithm has the following event points:
  #
  #  * examine_vertex
  #  * examine_edge
  #  * edge_relaxed
  #  * edge_not_relaxed
  #  * finish_vertex
  #
  class DijkstraVisitor

    include GraphVisitor

    attr_accessor :distance_map, :parents_map

    def_event_handlers :edge_relaxed, :edge_not_relaxed

    # Returns visitor into initial state.
    #
    def reset
      super

      @distance_map = Hash.new(INFINITY)
      @parents_map  = {}
    end

    # Initializes visitor with a new source.
    #
    def set_source(source)
      reset

      color_map[source]    = :GRAY
      distance_map[source] = 0
    end

  end # DijkstraVisitor

end # RGL

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rgl-0.6.6 lib/rgl/dijkstra_visitor.rb
rgl-0.6.5 lib/rgl/dijkstra_visitor.rb
rgl-0.6.4 lib/rgl/dijkstra_visitor.rb
rgl-0.6.3 lib/rgl/dijkstra_visitor.rb
rgl-0.6.2 lib/rgl/dijkstra_visitor.rb
rgl-0.6.1 lib/rgl/dijkstra_visitor.rb
rgl-0.6.0 lib/rgl/dijkstra_visitor.rb
rgl-0.5.10 lib/rgl/dijkstra_visitor.rb
rgl-0.5.9 lib/rgl/dijkstra_visitor.rb
rgl-0.5.8 lib/rgl/dijkstra_visitor.rb
rgl-0.5.7 lib/rgl/dijkstra_visitor.rb
rgl-0.5.6 lib/rgl/dijkstra_visitor.rb
rgl-0.5.4 lib/rgl/dijkstra_visitor.rb
rgl-0.5.3 lib/rgl/dijkstra_visitor.rb
rgl-0.5.2 lib/rgl/dijkstra_visitor.rb
rgl-0.5.1 lib/rgl/dijkstra_visitor.rb
rgl-0.5.0 lib/rgl/dijkstra_visitor.rb