This documentation is being rewritten. If something looks off, please cross-check with the Boost 1.91.0 Boost.Graph docs and open an issue.

time_stamper

Stamps a monotonically increasing time value when an event occurs. Commonly used to record discover and finish times during DFS.

Defined in: <boost/graph/visitors.hpp>
Models: EventVisitor
Typical event: on_discover_vertex, on_finish_vertex

Example

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/visitors.hpp>
#include <iostream>
#include <vector>

int main() {
    using namespace boost;
    using Graph = adjacency_list<vecS, vecS, directedS>;

    Graph g(4);
    add_edge(0, 1, g);
    add_edge(0, 2, g);
    add_edge(1, 3, g);

    std::vector<int> dtime(num_vertices(g));
    std::vector<int> ftime(num_vertices(g));
    int t = 0;

    auto vis = make_dfs_visitor(
        std::make_pair(
            stamp_times(dtime.data(), t, on_discover_vertex()),
            stamp_times(ftime.data(), t, on_finish_vertex())
        )
    );
    depth_first_search(g, visitor(vis));

    for (std::size_t v = 0; v < num_vertices(g); ++v) {
        std::cout << "vertex " << v
                  << "  discover=" << dtime[v]
                  << "  finish=" << ftime[v] << "\n";
    }
}
vertex 0  discover=1  finish=8
vertex 1  discover=2  finish=5
vertex 2  discover=6  finish=7
vertex 3  discover=3  finish=4

Synopsis

template <typename TimeMap, typename TimeT, typename EventTag>
struct time_stamper;

template <typename TimeMap, typename TimeT, typename EventTag>
time_stamper<TimeMap, TimeT, EventTag>
stamp_times(TimeMap pa, TimeT& t, EventTag);

Parameters

Parameter Description

TimeMap

WritablePropertyMap. Key type is the vertex or edge descriptor.

TimeT

The time counter type. Passed by reference; incremented on each event.

EventTag

Any event tag (vertex or edge).

Behavior

Increments the counter and stamps the time: put(time_map, x, ++t).