Dijkstra Visitor Adaptor :: Boost.Graph Documentation

# Dijkstra Visitor Adaptor

Converts a list of event visitors into a DijkstraVisitor for use with `dijkstra_shortest_paths`.

Defined in: `<boost/graph/dijkstra_shortest_paths.hpp>`
Models: DijkstraVisitor

## Example

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

    struct Road { double km; };

    int main() {
        using namespace boost;
        using Graph = adjacency_list<vecS, vecS, directedS, no_property, Road>;
        using Vertex = graph_traits<Graph>::vertex_descriptor;

        Graph g(5);
        add_edge(0, 1, Road{1.0}, g);
        add_edge(0, 2, Road{4.0}, g);
        add_edge(1, 2, Road{2.0}, g);
        add_edge(1, 3, Road{6.0}, g);
        add_edge(2, 3, Road{3.0}, g);
        add_edge(3, 4, Road{1.0}, g);

        std::vector<Vertex> pred(num_vertices(g));
        std::vector<double> dist(num_vertices(g));
        auto weight = get(&Road::km, g);
        auto index = get(vertex_index, g);
        auto pred_map = make_iterator_property_map(pred.begin(), index);
        auto dist_map = make_iterator_property_map(dist.begin(), index);

        auto vis = make_dijkstra_visitor(
            record_predecessors(pred_map, on_edge_relaxed())
        );

        dijkstra_shortest_paths(g, vertex(0, g),
            pred_map, dist_map, weight, index,
            std::less<double>(), std::plus<double>(),
            (std::numeric_limits<double>::max)(), 0.0,
            vis);

        for (std::size_t v = 0; v < num_vertices(g); ++v) {
            std::cout << "vertex " << v
                      << "  dist=" << dist[v]
                      << "  pred=" << pred[v] << "\n";
        }
    }

    vertex 0  dist=0  pred=0
    vertex 1  dist=1  pred=0
    vertex 2  dist=3  pred=1
    vertex 3  dist=6  pred=2
    vertex 4  dist=7  pred=3

## Synopsis

    template <typename EventVisitorList = null_visitor>
    class dijkstra_visitor;

    template <typename EventVisitorList>
    dijkstra_visitor<EventVisitorList>
    make_dijkstra_visitor(EventVisitorList ev_list);

## Parameters

Parameter | Description | Default
--- | --- | ---
`EventVisitorList` | One or more EventVisitors combined with `std::pair`. | `null_visitor`

## Behavior

Implements all DijkstraVisitor event points. Each event is dispatched to the matching EventVisitor in the list. Events with no matching visitor are ignored.