ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
StaticGraph.h

A static GRAPH for the engineered algorithms, beyond the book. More...

Files

file  ADS/graph/StaticGraph.h
 A static GRAPH for the engineered algorithms, beyond the book [see Graph.h]: the compressed sparse rows of ArrayGraph [see ArrayGraph.h] (the format CSR of the sparse matrices), with the arcs of each node sorted by head, which makes the reads of the visits that follow them go forward in memory.

Concepts

concept  ADS::CsrArrays
 a graph whose compressed rows are plain arrays, offsets(), heads() and, if weighted, weightData(), which a library that takes the compressed rows (METIS, KaHIP, GraphBLAS) reads without a copy: a StaticGraph of the separate layout, or an ArrayGraph

Classes

struct  ADS::WeightedArc< W >
 an arc of a weighted StaticGraph, its head with its weight More...
class  ADS::StaticGraph< W, L >
 a static graph in compressed sparse rows, the arcs of each node sorted by head, their heads and their weights in two arrays or, with ArcLayout::Interleaved, in one array of pairs More...

Enumerations

enum class  ADS::ArcLayout { ADS::ArcLayout::Separate , ADS::ArcLayout::Interleaved }
 the layout of the arcs of a weighted StaticGraph More...

Functions

template<class W, ArcLayout L>
std::vector< int > ADS::bfsOrder (const StaticGraph< W, L > &g, int r=0)
 the order of a visit in breadth from \( r \), then from the least node not reached, and so on: the name p[ u ] of each node u in the relabelled graph, a permutation of the nodes

Detailed description

A static GRAPH for the engineered algorithms, beyond the book.

The definitions, the invariants and the costs of the area are in Theory of graphs.

Enumeration type documentation

◆ ArcLayout

enum class ADS::ArcLayout
strong

the layout of the arcs of a weighted StaticGraph

Enumerator
Separate 

the heads and the weights in two arrays of the same places

Interleaved 

the pairs WeightedArc in one array

Function documentation

◆ bfsOrder()

template<class W, ArcLayout L>
std::vector< int > ADS::bfsOrder ( const StaticGraph< W, L > & g,
int r = 0 )

the order of a visit in breadth from \( r \), then from the least node not reached, and so on: the name p[ u ] of each node u in the relabelled graph, a permutation of the nodes

In pseudocode (the ordering of Cuthill and McKee without its sort by degree):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{bfsOrder}( G , r ) \cr 2 & \quad k \gets 0;\ p[ v ] \gets \textbf{nil}\ \text{for each node} \cr 3 & \quad \textbf{foreach}\ s \in ( r , 0 , 1 , \ldots , n - 1 ) \ \textbf{with}\ p[ s ] = \textbf{nil}\ \textbf{do} \cr 4 & \qquad p[ s ] \gets k;\ k \gets k + 1;\ Q \gets ( s ) \cr 5 & \qquad \textbf{while}\ Q \ne \emptyset\ \textbf{do} \cr 6 & \qquad\quad u \gets \mathrm{dequeue}( Q ) \cr 7 & \qquad\quad \textbf{foreach}\ v \in G.\mathrm{adj}( u )\ \textbf{with} \ p[ v ] = \textbf{nil}\ \textbf{do}\ p[ v ] \gets k;\ k \gets k + 1; \ \mathrm{enqueue}( Q , v ) \cr 8 & \quad \textbf{return}\ p \end{array}} \]

Precondition
\( r \) is a node, or the graph has none