distance_recorder
Records the hop distance of each vertex from the source during a graph search.
Defined in: <boost/graph/visitors.hpp>
Models: EventVisitor
Typical event: on_tree_edge (edge events only)
Example
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/visitors.hpp>
#include <iostream>
#include <vector>
int main() {
using namespace boost;
using Graph = adjacency_list<vecS, vecS, undirectedS>;
Graph g(5);
add_edge(0, 1, g);
add_edge(0, 2, g);
add_edge(1, 3, g);
add_edge(3, 4, g);
std::vector<int> dist(num_vertices(g), 0);
auto vis = make_bfs_visitor(
record_distances(dist.data(), on_tree_edge())
);
breadth_first_search(g, vertex(0, g), visitor(vis));
for (std::size_t v = 0; v < num_vertices(g); ++v) {
std::cout << "vertex " << v << " distance=" << dist[v] << "\n";
}
}
vertex 0 distance=0
vertex 1 distance=1
vertex 2 distance=1
vertex 3 distance=2
vertex 4 distance=3
Synopsis
template <typename DistanceMap, typename EventTag>
struct distance_recorder;
template <typename DistanceMap, typename EventTag>
distance_recorder<DistanceMap, EventTag>
record_distances(DistanceMap pa, EventTag);
Parameters
| Parameter | Description |
|---|---|
|
WritablePropertyMap. Key type is vertex descriptor. |
|
Must be an edge event tag (e.g. |