Class: RGL::BFSIterator

### Home Classes Methods

### In Files

- lib/rgl/traversal.rb

### Parent

Object

### Methods

- ::new
- #at_end?
- #set_to_begin

### Included Modules

- RGL::GraphIterator
- RGL::GraphVisitor

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

A BFSIterator can be used to traverse a graph from a given start vertex in breath first search order. Since the Iterator also mixins the GraphVisitor, it provides all event points defined there.

The vertices which are not yet visited are held in the queue @waiting. During the traversal, vertices are colored using the colors :GRAY (when waiting) and :BLACK when finished. All other vertices are :WHITE.

For more doc see the BGL BFS Visitor Concept .

See the implementation of bfs_search_tree_from for an example usage.

### Attributes

start_vertex[RW]

### Public Class Methods

new(graph, start = graph.detect { |x| true }) click to toggle source

Create a new BFSIterator on graph, starting at vertex start.

    # File lib/rgl/traversal.rb, line 40
    def initialize(graph, start = graph.detect { |x| true })
      super(graph)
      @start_vertex = start
      set_to_begin
    end

### Public Instance Methods

at_end?() click to toggle source

Returns true if @waiting is empty.

    # File lib/rgl/traversal.rb, line 54
    def at_end?
      @waiting.empty?
    end

set_to_begin() click to toggle source

Reset the iterator to the initial state (i.e. at_beginning? == true).

    # File lib/rgl/traversal.rb, line 60
    def set_to_begin
      color_map[@start_vertex] = :GRAY
      @waiting = [@start_vertex] # a queue
      handle_tree_edge(nil, @start_vertex) # discovers start vertex
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.