Skip to content
François Hamonic edited this page Aug 28, 2024 · 7 revisions

Graph views

Reverse

The reverse class template provides a view of a graph where the direction of each arc is reversed. It is designed to work with any input that satisfies the graph concept. This view allows you to easily access the reverse structure of a given graph without modifying the original graph itself.

Subgraph

The subgraph class template is a view that represents a subgraph of a given graph. This subgraph is defined by filtering vertices and arcs based on the provided filters. It allows selective access and manipulation of the underlying graph elements (vertices and arcs) while adhering to the original graph's structure.

Undirect

The undirect class template provides a view that treats a directed graph as an undirected graph. This is achieved by exposing the underlying directed graph's arcs (edges) as undirected edges, making it easier to work with algorithms that require undirected graphs without modifying the original graph structure.

Reference and owning views

When writing generic code, graph_ref_view and graph_owning_view are used to manage the ownership of graphs:

  • graph_ref_view: Creates a non-owning reference to a graph, allowing you to operate on the graph without extending its lifetime.
  • graph_owning_view: Wraps a graph and takes ownership of it, ensuring the graph is kept alive for the duration of the view's use.

In practice, you should use the function views::graph_all to wrap a graph to either graph_ref_view or graph_owning_view depending on its type. This mecanism is used to manage the ownership of graphs under the hood, allowing to safely manipulate views like :

static_digraph graph = ...;
vertex_t<static_digraph> s = ...; 

for(auto && [u, dist] : dijkstra(views::reverse(graph), length_map, s)) {
    ...;
}

Mapping views

Reference and owning views

mapping_ref_view, mapping_owning_view and mapping_all provide essentially the same mechanism that graph_ref_view etc... for mappings.

Additionally, mapping_ref_view and mapping_owning_view can wrap lambdas into viable mapping allowing to write :

for(auto && [u, dist] : dijkstra(graph, [](auto && a) { return 1; }, s)) {
    ...;
}

Utility views

Clone this wiki locally