Back to Arangodb

BFS Visitor Concept

3rdParty/boost/1.78.0/libs/graph/doc/BFSVisitor.html

3.12.9.13.7 KB
Original Source

BFS Visitor Concept

This concept defines the visitor interface for breadth_first_search(). Users can define a class with the BFS Visitor interface and pass and object of the class to breadth_first_search(), thereby augmenting the actions taken during the graph search.

Refinement of

Copy Constructible (copying a visitor should be a lightweight operation).

Notation

| V | A type that is a model of BFS Visitor. | | vis | An object of type V. | | G | A type that is a model of Graph. | | g | An object of type G. | | e | An object of type boost::graph_traits<G>::edge_descriptor. | | s,u | An object of type boost::graph_traits<G>::vertex_descriptor. |

Associated Types

none

Valid Expressions

NameExpressionReturn TypeDescription
Initialize Vertexvis.initialize_vertex(s, g)voidThis is invoked on every vertex of the graph before the start of the graph search.
Discover Vertexvis.discover_vertex(u, g)voidThis is invoked when a vertex is encountered for the first time.
Examine Vertexvis.examine_vertex(u, g)voidThis is invoked on a vertex as it is popped from the queue. This happens immediately before examine_edge() is invoked on each of the out-edges of vertex u.
Examine Edgevis.examine_edge(e, g)voidThis is invoked on every out-edge of each vertex after it is discovered.
Tree Edgevis.tree_edge(e, g)voidThis is invoked on each edge as it becomes a member of the edges that form the search tree.
Non-Tree Edgevis.non_tree_edge(e, g)voidThis is invoked on back or cross edges for directed graphs and cross edges for undirected graphs.
Gray Targetvis.gray_target(e, g)voidThis is invoked on the subset of non-tree edges whose target vertex is colored gray at the time of examination. The color gray indicates that the vertex is currently in the queue.
Black Targetvis.black_target(e, g)voidThis is invoked on the subset of non-tree edges whose target vertex is colored black at the time of examination. The color black indicates that the vertex has been removed from the queue.
Finish Vertexvis.finish_vertex(u, g)voidThis invoked on a vertex after all of its out edges have been added to the search tree and all of the adjacent vertices have been discovered (but before the out-edges of the adjacent vertices have been examined).

Models

Python

To implement a model of the BFSVisitor concept in Python, create a new class that derives from the BFSVisitor type of the graph, which will be named GraphType.BFSVisitor. The events and syntax are the same as with visitors in C++. Here is an example for the Python bgl.Graph graph type:

class count_tree_edges_bfs_visitor(bgl.Graph.BFSVisitor):
  def __init__ (self, name_map):
    bgl.Graph.BFSVisitor. __init__ (self)
    self.name_map = name_map

  def tree_edge(self, e, g):
    (u, v) = (g.source(e), g.target(e))
    print "Tree edge ",
    print self.name_map[u],
    print " -> ",
    print self.name_map[v]

See also

Visitor concepts


| Copyright © 2000-2001 | Jeremy Siek, Indiana University ([email protected])
Lie-Quan Lee, Indiana University ([email protected])
Andrew Lumsdaine, Indiana University ([email protected]) |