...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

// named paramter versiontemplate <class VertexListGraph, class Param, class Tag, class Rest> void dag_shortest_paths(const VertexListGraph& g, typename graph_traits<VertexListGraph>::vertex_descriptor s, const bgl_named_params<Param,Tag,Rest>& params)// non-named parameter versiontemplate <class VertexListGraph, class DijkstraVisitor, class DistanceMap, class WeightMap, class ColorMap, class PredecessorMap, class Compare, class Combine, class DistInf, class DistZero> void dag_shortest_paths(const VertexListGraph& g, typename graph_traits<VertexListGraph>::vertex_descriptor s, DistanceMap distance, WeightMap weight, ColorMap color, PredecessorMap pred, DijkstraVisitor vis, Compare compare, Combine combine, DistInf inf, DistZero zero)

This algorithm [8] solves the single-source shortest-paths problem on a weighted, directed acyclic graph (DAG). This algorithm is more efficient for DAG's than either the Dijkstra or Bellman-Ford algorithm. Use breadth-first search instead of this algorithm when all edge weights are equal to one. For the definition of the shortest-path problem see Section Shortest-Paths Algorithms for some background to the shortest-path problem.

There are two main options for obtaining output from the
`dag_shortest_paths()` function. If you provide a
distance property map through the `distance_map()` parameter
then the shortest distance from the source vertex to every other
vertex in the graph will be recorded in the distance map. Also you can
record the shortest paths tree in a predecessor map: for each vertex
*u in V*, *p[u]* will be the predecessor of *u* in
the shortest paths tree (unless *p[u] = u*, in which case *u* is
either the source or a vertex unreachable from the source). In
addition to these two options, the user can provide there own
custom-made visitor that can takes actions during any of the
algorithm's event points.

The graph object on which the algorithm will be applied. The typeIN:VertexListGraphmust be a model of \concept{VertexListGraph}.

Python: The parameter is namedgraph.

The source vertex. All distance will be calculated from this vertex, and the shortest paths tree will be rooted at this vertex.

Python: The parameter is namedroot_vertex.

The weight or ``length'' of each edge in the graph. The typeIN:WeightMapmust be a model of Readable Property Map. The edge descriptor type of the graph needs to be usable as the key type for the weight map. The value type for the map must beAddablewith the value type of the distance map.

Default:get(edge_weight, g)

Python: Must be anedge_double_mapfor the graph.

Python default:graph.get_edge_double_map("weight")

This maps each vertex to an integer in the rangeOUT:[0, num_vertices(g)). This is necessary for efficient updates of the heap data structure when an edge is relaxed. The typeVertexIndexMapmust be a model of Readable Property Map. The value type of the map must be an integer type. The vertex descriptor type of the graph needs to be usable as the key type of the map.

Default:get(vertex_index, g)

Python: Unsupported parameter.

The predecessor map records the edges in the minimum spanning tree. Upon completion of the algorithm, the edgesUTIL/OUT:(p[u],u)for allu in Vare in the minimum spanning tree. Ifp[u] = uthenuis either the source vertex or a vertex that is not reachable from the source. ThePredecessorMaptype must be a Read/Write Property Map which key and vertex types the same as the vertex descriptor type of the graph.

Default:dummy_property_map

Python: Must be avertex_vertex_mapfor the graph.

The shortest path weight from the source vertexIN:sto each vertex in the graphgis recorded in this property map. The shortest path weight is the sum of the edge weights along the shortest path. The typeDistanceMapmust be a model of Read/Write Property Map. The vertex descriptor type of the graph needs to be usable as the key type of the distance map. The value type of the distance map is the element type of a Monoid formed with thecombinefunction object and thezeroobject for the identity element. Also the distance value type must have a StrictWeakOrdering provided by thecomparefunction object.

Default:iterator_property_mapcreated from astd::vectorof theWeightMap's value type of sizenum_vertices(g)and using thei_mapfor the index map.

Python: Must be avertex_double_mapfor the graph.

This function is use to compare distances to determine which vertex is closer to the source vertex. TheIN:CompareFunctiontype must be a model of Binary Predicate and have argument types that match the value type of theDistanceMapproperty map.

Default:std::less<D>withD=typename property_traits<DistanceMap>::value_type

Python: Unsupported parameter.

This function is used to combine distances to compute the distance of a path. TheIN:CombineFunctiontype must be a model of Binary Function. The first argument type of the binary function must match the value type of theDistanceMapproperty map and the second argument type must match the value type of theWeightMapproperty map. The result type must be the same type as the distance value type.

Default:std::plus<D>withD=typename property_traits<DistanceMap>::value_type

Python: Unsupported parameter.

TheIN:infobject must be the greatest value of anyDobject. That is,compare(d, inf) == truefor anyd != inf. The typeDis the value type of theDistanceMap.

Default:std::numeric_limits<D>::max()

Python: Unsupported parameter.

TheUTIL/OUT:zerovalue must be the identity element for the Monoid formed by the distance values and thecombinefunction object. The type \code{D} is the value type of the \code{DistanceMap}Default:D()

Python: Unsupported parameter.

This is used during the execution of the algorithm to mark the vertices. The vertices start out white and become gray when they are inserted in the queue. They then turn black when they are removed from the queue. At the end of the algorithm, vertices reachable from the source vertex will have been colored black. All other vertices will still be white. The typeOUT:ColorMapmust be a model of Read/Write Property Map. A vertex descriptor must be usable as the key type of the map, and the value type of the map must be a model of Color Value.

Default:aniterator_property_mapcreated from astd::vectorofdefault_color_typeof sizenum_vertices(g)and using thei_mapfor the index map.

Python: The color map must be avertex_color_mapfor the graph.

Use this to specify actions that you would like to happen during certain event points within the algorithm. The typeDijkstraVisitormust be a model of the Dijkstra Visitor concept. The visitor object is passed by value [1].

Default:dijkstra_visitor<null_visitor>

Python: The parameter should be an object that derives from theDijkstraVisitortype of the graph.

The time complexity is *O(V + E)*.

is invoked on each vertex in the graph before the start of the algorithm.`vis.initialize_vertex(u, g)`is invoked on a vertex as it is added to set`vis.examine_vertex(u, g)`*S*. At this point we know that*(p[u],u)*is a shortest-paths tree edge so*d[u] = delta(s,u) = d[p[u]] + w(p[u],u)*. Also, the distances of the examined vertices is monotonically increasing*d[u*._{1}] <= d[u_{2}] <= d[u_{n}]is invoked on each out-edge of a vertex immediately after it has been added to set`vis.examine_edge(e, g)`*S*.is invoked on edge`vis.edge_relaxed(e, g)`*(u,v)*if*d[u] + w(u,v) < d[v]*. The edge*(u,v)*that participated in the last relaxation for vertex*v*is an edge in the shortest paths tree.is invoked on vertex`vis.discover_vertex(v, g)`*v*when the edge*(u,v)*is examined and*v*is WHITE. Since a vertex is colored GRAY when it is discovered, each reacable vertex is discovered exactly once.is invoked if the edge is not relaxed (see above).`vis.edge_not_relaxed(e, g)`is invoked on a vertex after all of its out edges have been examined.`vis.finish_vertex(u, g)`

See
`example/dag_shortest_paths.cpp` for an example of using this
algorithm.

[1]
Since the visitor parameter is passed by value, if your visitor
contains state then any changes to the state during the algorithm
will be made to a copy of the visitor object, not the visitor object
passed in. Therefore you may want the visitor to hold this state by
pointer or reference.

Copyright © 2000-2001 | Jeremy Siek, Indiana University (jsiek@osl.iu.edu) |