Skip to content
Merged
7 changes: 4 additions & 3 deletions doc/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
** xref:property_maps/pitfalls.adoc[Common Mistakes]
* xref:visitors/overview.adoc[Visitors]
** Pre-built Event Visitors
*** xref:visitors/predecessor_recorder.adoc[Predecessor Recorder]
*** xref:visitors/predecessor_recorder.adoc[Vertex Predecessor Recorder]
*** xref:visitors/edge_predecessor_recorder.adoc[Edge Predecessor Recorder]
*** xref:visitors/distance_recorder.adoc[Distance Recorder]
*** xref:visitors/time_stamper.adoc[Time Stamper]
*** xref:visitors/property_put.adoc[Property Put]
*** xref:visitors/property_writer.adoc[Property Writer]
*** xref:visitors/edge_predecessor_recorder.adoc[Edge Predecessor Recorder]
*** xref:visitors/time_stamper.adoc[Time Stamper]
*** xref:visitors/null_visitor.adoc[Null Visitor]
** Algorithm-specific visitors
*** xref:visitors/tsp_tour_visitor.adoc[TSP Tour Visitor]
*** xref:visitors/tsp_tour_len_visitor.adoc[TSP Tour Len Visitor]
*** xref:visitors/astar_heuristic.adoc[A* Heuristic (Zero)]
Expand Down
85 changes: 64 additions & 21 deletions doc/modules/ROOT/pages/visitors/distance_recorder.adoc
Original file line number Diff line number Diff line change
@@ -1,49 +1,92 @@
= distance_recorder

Records the hop distance of each vertex from the source during a graph search.
Records the distance of each vertex from the source vertex into a property map.
When applied to edge `e = (u, v)`, the distance of `v` is recorded as one more
than the distance of `u`.

*Defined in:* `<boost/graph/visitors.hpp>` +
*Models:* EventVisitor +
*Typical event:* `on_tree_edge` (edge events only)
*Models:* xref:visitors/EventVisitor.adoc[EventVisitor] +
*Typical event:* `on_tree_edge` or `on_relax_edge` (edge events only; cannot be
used with vertex events)

== Example

[source,cpp]
----
include::example$visitors/distance_recorder.cpp[]
----

[,text]
----
include::example$visitors/distance_recorder.txt[]
----
To use it, wrap it in an algorithm adaptor and optionally combine it with other
event visitors; see the xref:visitors/overview.adoc[visitors overview].

== Synopsis

[source,cpp]
----
template <typename DistanceMap, typename EventTag>
struct distance_recorder;
struct distance_recorder {
typedef EventTag event_filter;
distance_recorder(DistanceMap pa);

template <class Edge, class Graph>
void operator()(Edge e, const Graph& g);
};

template <typename DistanceMap, typename EventTag>
distance_recorder<DistanceMap, EventTag>
record_distances(DistanceMap pa, EventTag);
----

== Parameters
== Template Parameters

[cols="1,3",options="header"]
|===
| Parameter | Description

| `DistanceMap`
| WritablePropertyMap. Key type is vertex descriptor.
| A WritablePropertyMap whose key type is the graph's vertex descriptor and whose
value type is the distance (a numeric type that supports adding one).

| `EventTag`
| Must be an edge event tag (e.g. `on_tree_edge`).
| The event at which to record. Must be an edge event (e.g. `on_tree_edge`,
`on_relax_edge`).
|===

== Associated Types

[cols="1,3",options="header"]
|===
| Type | Description

== Behavior
| `event_filter`
| The event tag the visitor responds to. Same type as `EventTag`.
|===

== Member Functions

[cols="1,3",options="header"]
|===
| Member | Description

Given edge `e = (u, v)`, sets the distance of `v` to one plus the distance
of `u`: `put(dist_map, v, get(dist_map, u) + 1)`.
| `distance_recorder(DistanceMap pa)`
| Constructs a recorder writing distances into the property map `pa`.

| `void operator()(Edge e, const Graph& g)`
| Given edge `e = (u, v)`, records the distance of `v` as one more than the
distance of `u`: `put(pa, v, get(pa, u) + 1)`.
|===

== Non-Member Functions

[cols="1,3",options="header"]
|===
| Function | Description

| `record_distances(DistanceMap pa, EventTag)`
| Convenience factory that creates a `distance_recorder`.
|===

== Example

[source,cpp]
----
include::example$visitors/distance_recorder.cpp[]
----

[,text]
----
include::example$visitors/distance_recorder.txt[]
----
98 changes: 70 additions & 28 deletions doc/modules/ROOT/pages/visitors/edge_predecessor_recorder.adoc
Original file line number Diff line number Diff line change
@@ -1,57 +1,99 @@
= edge_predecessor_recorder

Records the predecessor _edge_ (not vertex) for each vertex. Useful when a
graph has parallel edges and you need to know which specific edge the search
used to reach a vertex.
Records the predecessor _edge_ of each vertex in a property map, an efficient way
to encode the search tree traversed during a graph search. Use this instead of
xref:visitors/predecessor_recorder.adoc[`predecessor_recorder`] (which records the
predecessor vertex) when a graph has parallel edges and you need to know which
specific edge the search used to reach a vertex.

*Defined in:* `<boost/graph/visitors.hpp>` +
*Models:* EventVisitor +
*Typical event:* `on_tree_edge` or `on_relax_edge` (edge events only)
*Models:* xref:visitors/EventVisitor.adoc[EventVisitor] +
*Typical event:* `on_tree_edge` or `on_relax_edge` (edge events only; cannot be
used with vertex events)

== Example

[source,cpp]
----
include::example$visitors/edge_predecessor_recorder.cpp[]
----

[,text]
----
include::example$visitors/edge_predecessor_recorder.txt[]
----
To use it, wrap it in an algorithm adaptor and optionally combine it with other
event visitors; see the xref:visitors/overview.adoc[visitors overview].

== Synopsis

[source,cpp]
----
template <typename PredEdgeMap, typename EventTag>
struct edge_predecessor_recorder;
struct edge_predecessor_recorder {
typedef EventTag event_filter;
edge_predecessor_recorder(PredEdgeMap pa);

template <class Edge, class Graph>
void operator()(Edge e, const Graph& g);
};

template <typename PredEdgeMap, typename EventTag>
edge_predecessor_recorder<PredEdgeMap, EventTag>
record_edge_predecessors(PredEdgeMap pa, EventTag);
----

== Parameters
== Template Parameters

[cols="1,3",options="header"]
|===
| Parameter | Description

| `PredEdgeMap`
| WritablePropertyMap. Key type is vertex descriptor, value type is edge
descriptor.
| A WritablePropertyMap whose key type is the graph's vertex descriptor and whose
value type is the graph's edge descriptor.

| `EventTag`
| Must be an edge event tag (e.g. `on_tree_edge`, `on_relax_edge`).
| The event at which to record. Must be an edge event (e.g. `on_tree_edge`,
`on_relax_edge`).
|===

== Associated Types

[cols="1,3",options="header"]
|===
| Type | Description

== Behavior
| `event_filter`
| The event tag the visitor responds to. Same type as `EventTag`.
|===

== Member Functions

[cols="1,3",options="header"]
|===
| Member | Description

Given edge `e = (u, v)`, records `e` as the predecessor edge of `v`:
`put(pred_edge_map, v, e)`.
| `edge_predecessor_recorder(PredEdgeMap pa)`
| Constructs a recorder writing predecessor edges into the property map `pa`.

TIP: The source vertex (root of the search tree) will not have a predecessor
edge assigned. Initialize it to a sentinel value before running the algorithm.
For DFS (which creates a forest), do the same for every vertex so that all
roots can be identified.
| `void operator()(Edge e, const Graph& g)`
| Given edge `e = (u, v)`, records `e` as the predecessor edge of `v`:
`put(pa, v, e)`.
|===

== Non-Member Functions

[cols="1,3",options="header"]
|===
| Function | Description

| `record_edge_predecessors(PredEdgeMap pa, EventTag)`
| Convenience factory that creates an `edge_predecessor_recorder`.
|===

TIP: The source vertex (the root of the search tree) is not assigned a predecessor
edge. Initialize it to a sentinel value before running the algorithm to identify
the root. For DFS (which builds a forest), do the same for every vertex so all
roots can be distinguished.

== Example

[source,cpp]
----
include::example$visitors/edge_predecessor_recorder.cpp[]
----

[,text]
----
include::example$visitors/edge_predecessor_recorder.txt[]
----
33 changes: 27 additions & 6 deletions doc/modules/ROOT/pages/visitors/null_visitor.adoc
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
= null_visitor

A no-op event visitor that does nothing. Used as a placeholder or default when
combining event visitors and one slot is not needed.
A no-op event visitor that does nothing. Useful as a placeholder or default when
an algorithm requires a visitor but no action is needed, or to fill an unused slot
when combining event visitors.

*Defined in:* `<boost/graph/visitors.hpp>` +
*Models:* EventVisitor
*Models:* xref:visitors/EventVisitor.adoc[EventVisitor]

== Synopsis

[source,cpp]
----
struct null_visitor {
using event_filter = void;
typedef on_no_event event_filter;

template <typename X, typename Graph>
void operator()(X, const Graph&) {}
template <class T, class Graph>
void operator()(T x, Graph& g);
};
----

== Associated Types

[cols="1,3",options="header"]
|===
| Type | Description

| `event_filter`
| `on_no_event`. The visitor is not associated with any algorithm event.
|===

== Member Functions

[cols="1,3",options="header"]
|===
| Member | Description

| `void operator()(T x, Graph& g)`
| Does nothing.
|===
Loading
Loading