|
1 | 1 | = edge_predecessor_recorder |
2 | 2 |
|
3 | | -Records the predecessor _edge_ (not vertex) for each vertex. Useful when a |
4 | | -graph has parallel edges and you need to know which specific edge the search |
5 | | -used to reach a vertex. |
| 3 | +Records the predecessor _edge_ of each vertex in a property map, an efficient way |
| 4 | +to encode the search tree traversed during a graph search. Use this instead of |
| 5 | +xref:visitors/predecessor_recorder.adoc[`predecessor_recorder`] (which records the |
| 6 | +predecessor vertex) when a graph has parallel edges and you need to know which |
| 7 | +specific edge the search used to reach a vertex. |
6 | 8 |
|
7 | 9 | *Defined in:* `<boost/graph/visitors.hpp>` + |
8 | | -*Models:* EventVisitor + |
9 | | -*Typical event:* `on_tree_edge` or `on_relax_edge` (edge events only) |
| 10 | +*Models:* xref:visitors/EventVisitor.adoc[EventVisitor] + |
| 11 | +*Typical event:* `on_tree_edge` or `on_relax_edge` (edge events only; cannot be |
| 12 | +used with vertex events) |
10 | 13 |
|
11 | | -== Example |
12 | | - |
13 | | -[source,cpp] |
14 | | ----- |
15 | | -include::example$visitors/edge_predecessor_recorder.cpp[] |
16 | | ----- |
17 | | - |
18 | | -[,text] |
19 | | ----- |
20 | | -include::example$visitors/edge_predecessor_recorder.txt[] |
21 | | ----- |
| 14 | +To use it, wrap it in an algorithm adaptor and optionally combine it with other |
| 15 | +event visitors; see the xref:visitors/overview.adoc[visitors overview]. |
22 | 16 |
|
23 | 17 | == Synopsis |
24 | 18 |
|
25 | 19 | [source,cpp] |
26 | 20 | ---- |
27 | 21 | template <typename PredEdgeMap, typename EventTag> |
28 | | -struct edge_predecessor_recorder; |
| 22 | +struct edge_predecessor_recorder { |
| 23 | + typedef EventTag event_filter; |
| 24 | + edge_predecessor_recorder(PredEdgeMap pa); |
| 25 | +
|
| 26 | + template <class Edge, class Graph> |
| 27 | + void operator()(Edge e, const Graph& g); |
| 28 | +}; |
29 | 29 |
|
30 | 30 | template <typename PredEdgeMap, typename EventTag> |
31 | 31 | edge_predecessor_recorder<PredEdgeMap, EventTag> |
32 | 32 | record_edge_predecessors(PredEdgeMap pa, EventTag); |
33 | 33 | ---- |
34 | 34 |
|
35 | | -== Parameters |
| 35 | +== Template Parameters |
36 | 36 |
|
37 | 37 | [cols="1,3",options="header"] |
38 | 38 | |=== |
39 | 39 | | Parameter | Description |
40 | 40 |
|
41 | 41 | | `PredEdgeMap` |
42 | | -| WritablePropertyMap. Key type is vertex descriptor, value type is edge |
43 | | - descriptor. |
| 42 | +| A WritablePropertyMap whose key type is the graph's vertex descriptor and whose |
| 43 | + value type is the graph's edge descriptor. |
44 | 44 |
|
45 | 45 | | `EventTag` |
46 | | -| Must be an edge event tag (e.g. `on_tree_edge`, `on_relax_edge`). |
| 46 | +| The event at which to record. Must be an edge event (e.g. `on_tree_edge`, |
| 47 | + `on_relax_edge`). |
| 48 | +|=== |
| 49 | + |
| 50 | +== Associated Types |
| 51 | + |
| 52 | +[cols="1,3",options="header"] |
47 | 53 | |=== |
| 54 | +| Type | Description |
48 | 55 |
|
49 | | -== Behavior |
| 56 | +| `event_filter` |
| 57 | +| The event tag the visitor responds to. Same type as `EventTag`. |
| 58 | +|=== |
| 59 | + |
| 60 | +== Member Functions |
| 61 | + |
| 62 | +[cols="1,3",options="header"] |
| 63 | +|=== |
| 64 | +| Member | Description |
50 | 65 |
|
51 | | -Given edge `e = (u, v)`, records `e` as the predecessor edge of `v`: |
52 | | -`put(pred_edge_map, v, e)`. |
| 66 | +| `edge_predecessor_recorder(PredEdgeMap pa)` |
| 67 | +| Constructs a recorder writing predecessor edges into the property map `pa`. |
53 | 68 |
|
54 | | -TIP: The source vertex (root of the search tree) will not have a predecessor |
55 | | -edge assigned. Initialize it to a sentinel value before running the algorithm. |
56 | | -For DFS (which creates a forest), do the same for every vertex so that all |
57 | | -roots can be identified. |
| 69 | +| `void operator()(Edge e, const Graph& g)` |
| 70 | +| Given edge `e = (u, v)`, records `e` as the predecessor edge of `v`: |
| 71 | + `put(pa, v, e)`. |
| 72 | +|=== |
| 73 | + |
| 74 | +== Non-Member Functions |
| 75 | + |
| 76 | +[cols="1,3",options="header"] |
| 77 | +|=== |
| 78 | +| Function | Description |
| 79 | + |
| 80 | +| `record_edge_predecessors(PredEdgeMap pa, EventTag)` |
| 81 | +| Convenience factory that creates an `edge_predecessor_recorder`. |
| 82 | +|=== |
| 83 | + |
| 84 | +TIP: The source vertex (the root of the search tree) is not assigned a predecessor |
| 85 | +edge. Initialize it to a sentinel value before running the algorithm to identify |
| 86 | +the root. For DFS (which builds a forest), do the same for every vertex so all |
| 87 | +roots can be distinguished. |
| 88 | + |
| 89 | +== Example |
| 90 | + |
| 91 | +[source,cpp] |
| 92 | +---- |
| 93 | +include::example$visitors/edge_predecessor_recorder.cpp[] |
| 94 | +---- |
| 95 | + |
| 96 | +[,text] |
| 97 | +---- |
| 98 | +include::example$visitors/edge_predecessor_recorder.txt[] |
| 99 | +---- |
0 commit comments