|
ADS
Algorithms and Data Structures
|
The GRAPH of chapter 9 and its realizations. More...
#include "ADS/Contract.h"#include "ADS/Iterators.h"#include "ADS/sequence/List.h"#include <concepts>#include <cstddef>#include <optional>#include <ranges>#include <string>#include <tuple>#include <type_traits>#include <utility>#include <variant>#include <vector>#include "ADS/graph/impl/Graph.tpp"Go to the source code of this file.
Classes | |
| class | ADS::GraphNodes< T > |
| the nodes, their labels and the counts shared by the realizations More... | |
| struct | ADS::GraphNodes< T >::Alive |
| the names in use, for SlotIterator More... | |
Namespaces | |
| namespace | ADS |
Concepts | |
| concept | ADS::Graph |
| GRAPH (section 9.2), as far as the visits need it: the nodes, the adjacent nodes of a node, the range \( [ 0 , \mathrm{bound}() ) \) of the names. | |
| concept | ADS::DynamicGraph |
| a GRAPH with the insertions and the deletions of its specification | |
Functions | |
| template<Graph G> | |
| std::vector< std::vector< int > > | ADS::incidence (const G &g) |
| the matrix of incidence nodes-edges, the edges in the order of V() and of adj(), an unoriented one when met from its smaller end | |
| std::vector< int > | ADS::adjFromIncidence (const std::vector< std::vector< int > > &B, int u, bool directed) |
| the adjacent nodes of \( u \) from the matrix of incidence \( B \) of a graph, oriented or not, in the order of the columns | |
The GRAPH of chapter 9 and its realizations.
A graph G = ( V , E ) has n nodes, named by integers, and m edges, ordered pairs ( u , v ) if it is oriented and unordered pairs [ u , v ] otherwise; an unoriented graph is the oriented one with both ( u , v ) and ( v , u ) (section 9.2), and so adj( u ) gives v for each edge [ u , v ]. The edges may have a weight of type W and the nodes a label of type T, both std::monostate if absent; there are no loops ( u , u ), so \( 0 \leq m \leq n ( n - 1 ) \).
The nodes of a graph are the integers in [ 0 , bound() ): insertNode() gives the next one and deleteNode() leaves its name unused, so that the vectors indexed by the nodes of the visits have bound() places, and n() = |V()| is the G.n of the book. The concept Graph asks for V(), adj( u ), which gives the adjacent nodes in a vector, as the SET of the book, and forEachAdj( u , f ), which calls f on them without building it.
incidence() gives the n x m matrix B of incidence nodes-edges (section 9.3): \( b_{uk} = -1 \) if the edge k leaves u and +1 if it enters it, for an oriented graph, and 1 if the edge k touches u, for an unoriented one.
adjFromIncidence() reads the adjacent nodes of u back from the matrix: in the row u, each column k of an edge leaving u (or touching it, if the graph is unoriented) leads to the other row with a nonzero entry.
The contracts [see Contract.h]: a graph has n >= 0 nodes, the operations on a node need one of the graph, and an edge needs two distinct nodes of the graph (no loops); the invariant of the nodes is that n() counts the names in use. The realizations relax some preconditions of the specification, which asks for an edge not there in insertEdge(), for one there in deleteEdge() and for an isolated node in deleteNode(): instead, insertEdge() of an edge already there replaces its weight, deleteEdge() of one not there does nothing, and deleteNode() also deletes the edges of the node (PointerGraph [see PointerGraph.h] keeps the strict deleteNode()). The operations are defined in Graph.tpp.