Module: RGL::GraphVisitor

### Home Classes Methods

### In Files

- lib/rgl/graph_visitor.rb

### Namespace

- MODULE RGL::GraphVisitor::ClassMethods
- MODULE RGL::GraphVisitor::DistanceMapSupport

### Methods

- ::included
- ::new
- #attach_distance_map
- #finished_vertex?
- #reset

### 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::GraphVisitor

Module GraphVisitor defines the BGL BFS Visitor Concept).

Visitors provide a mechanism for extending an algorithm (i.e., for customizing what is done at each step of the algorithm). They allow users to insert their own operations at various steps within a graph algorithm.

Graph algorithms typically have multiple event points where one may want to insert a call-back. Therefore, visitors have several methods that correspond to the various event points. Each algorithm has a different set of event points. The following are common to both DFS and BFS search.

    * examine_vertex
    * examine_edge
    * tree_edge
    * back_edge
    * forward_edge
    * finish_vertex

These methods are all called handle_* and can be set to appropriate blocks, using the methods set_*_event_handler, which are defined for each event mentioned above.

As an alternative, you can also override the handle_* methods in a subclass, to configure the algorithm (as an example, see TarjanSccVisitor).

During a graph traversal, vertices are colored using the colors :GRAY (when waiting) and :BLACK when finished. All other vertices are :WHITE. The color_map is also maintained in the visitor.

### Attributes

color_map[R]

### Public Class Methods

included(base) click to toggle source

    # File lib/rgl/graph_visitor.rb, line 125
    def self.included(base)
      base.extend ClassMethods # when GraphVisitor is included into a class/module, add class methods as well
    end

new(graph) click to toggle source

Create a new GraphVisitor on graph.

    # File lib/rgl/graph_visitor.rb, line 43
    def initialize(graph)
      super(graph)
      reset
    end

### Public Instance Methods

attach_distance_map(map = Hash.new(0)) click to toggle source

Attach a map to the visitor which records the distance of a visited vertex to the start vertex.

This is similar to BGLs distance_recorder.

After the distance_map is attached, the visitor has a new method distance_to_root, which answers the distance to the start vertex.

    # File lib/rgl/graph_visitor.rb, line 75
    def attach_distance_map(map = Hash.new(0))
      @distance_map = map

      # add distance map support to the current visitor instance
      extend(DistanceMapSupport)
    end

finished_vertex?(v) click to toggle source

Returns true if vertex v is colored :BLACK (i.e. finished).

    # File lib/rgl/graph_visitor.rb, line 56
    def finished_vertex?(v)
      @color_map[v] == :BLACK
    end

reset() click to toggle source

Mark each vertex unvisited (i.e. :WHITE)

    # File lib/rgl/graph_visitor.rb, line 50
    def reset
      @color_map = Hash.new(:WHITE)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.