|
ADS
Algorithms and Data Structures
|
A GRAPH that tells its changes, beyond the book. More...
Files | |
| file | ADS/graph/Observable.h |
| A GRAPH that tells its changes, beyond the book: the wrapper Observable< G , O... > routes the changes of a graph of any model (ListGraph and MatrixGraph, and the weights of ArrayGraph and StaticGraph) and turns each of them into an event, a value of the std::variant GraphEvent< W >, which it sends to the observers that want its kind (see Changes of the graph and reoptimization): | |
Concepts | |
| concept | ADS::GraphObserver |
| an observer of the events of weights W: the kinds that it wants, and the two ways of getting them | |
Classes | |
| struct | ADS::NodeInserted |
| a node inserted More... | |
| struct | ADS::NodeDeleted |
| a node deleted, after the deletion of its edges More... | |
| struct | ADS::EdgeInserted< W > |
| an edge \( ( u , v ) \), or \( [ u , v ] \) with \( u < v \), inserted with the weight \( w \) More... | |
| struct | ADS::EdgeDeleted< W > |
| an edge deleted, \( w \) the weight that it had More... | |
| struct | ADS::WeightChanged< W > |
| the weight of an edge changed from from to to More... | |
| struct | ADS::GraphEvents |
| the kinds of event as bits of a mask More... | |
| struct | ADS::mod::coalesce_traits< GraphModifications< W > > |
| the net effect of a batch of a graph, by coalesce() [see Observable.h] More... | |
| class | ADS::ObservedGraph< G, Policy > |
| the graph \( g \), whose changes are sent through the subject policy Policy [see Modification.h] More... | |
Typedefs | |
| template<class W> | |
| using | ADS::GraphModifications |
| the events of a graph of weights W, in the order of their kinds | |
| template<class W> | |
| using | ADS::GraphEvent |
| an event, whose kind is its index in the variant, the variant of GraphModifications< W > | |
| template<Graph G, class... O> | |
| using | ADS::Observable |
| the graph \( g \), whose changes are sent to the static observers O... of the first form [see GraphObserver] and to those attached later, of either form | |
Functions | |
| template<class W> | |
| constexpr EdgeDeleted< W > | ADS::inverse (const EdgeInserted< W > &e) |
| the inverse of an insertion of an edge, its deletion | |
| template<class W> | |
| constexpr EdgeInserted< W > | ADS::inverse (const EdgeDeleted< W > &e) |
| the inverse of a deletion of an edge, its insertion with the weight it had | |
| template<class W> | |
| constexpr WeightChanged< W > | ADS::inverse (const WeightChanged< W > &e) |
| the inverse of a change of a weight, the change back | |
| template<class W> | |
| constexpr unsigned | ADS::kindOf (const GraphEvent< W > &e) |
| the bit of the kind of \( e \) | |
| template<class W> | |
| std::pair< int, int > | ADS::endsOf (const GraphEvent< W > &e) |
| the ends of the edge of \( e \), \( ( -1 , -1 ) \) for an event on a node | |
| template<class W> | |
| std::vector< GraphEvent< W > > | ADS::coalesce (std::span< const GraphEvent< W > > E) |
| the net effect of the events \( E \), i.e., the nodes inserted, the edges in the order of their first event and the nodes deleted, by (8) of Changes of the graph and reoptimization, in \( O( |E| ) \) expected time | |
A GRAPH that tells its changes, beyond the book.
The definitions, the invariants and the costs of the area are in Theory of graphs.
| using ADS::GraphEvent |
an event, whose kind is its index in the variant, the variant of GraphModifications< W >
| using ADS::GraphModifications |
the events of a graph of weights W, in the order of their kinds
| using ADS::Observable |
the graph \( g \), whose changes are sent to the static observers O... of the first form [see GraphObserver] and to those attached later, of either form
|
nodiscard |
the net effect of the events \( E \), i.e., the nodes inserted, the edges in the order of their first event and the nodes deleted, by (8) of Changes of the graph and reoptimization, in \( O( |E| ) \) expected time
In pseudocode (beyond the book; it is correct by Lemma 6 of Changes of the graph and reoptimization):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{coalesce}( E ) \cr 2 & \quad I \gets \emptyset;\ D \gets \emptyset;\ N \gets \text{an empty} \text{ hash table on the edges} \cr 3 & \quad \textbf{foreach}\ e \in E\ \textbf{do} \cr 4 & \qquad \textbf{if}\ e\ \text{inserts the node } u\ \textbf{then} \ \text{append } u \text{ to } I \cr 5 & \qquad \textbf{else if}\ e\ \text{deletes the node } u\ \textbf{then} \ \textbf{if}\ u \in I\ \textbf{then}\ \text{mark } u \text{ gone}\ \textbf{else}\ \text{append } u \text{ to } D \cr 6 & \qquad \textbf{else if}\ \text{its edge } ( u , v ) \notin N \ \textbf{then}\ N[ ( u , v ) ] \gets ( s_0 , s_1 ) \text{ of } e \cr 7 & \qquad \textbf{else}\ \text{the } s_1 \text{ of } N[ ( u , v ) ] \gets \text{the } s_1 \text{ of } e \cr 8 & \quad \textbf{return}\ \text{the nodes of } I \text{ not gone, the} \text{ events (8) of } N \text{ on no node gone, in order, then } D \end{array}} \]
|
nodiscard |
the ends of the edge of \( e \), \( ( -1 , -1 ) \) for an event on a node
|
nodiscardconstexpr |
the inverse of a deletion of an edge, its insertion with the weight it had
|
nodiscardconstexpr |
the inverse of an insertion of an edge, its deletion
|
nodiscardconstexpr |
the inverse of a change of a weight, the change back
|
nodiscardconstexpr |
the bit of the kind of \( e \)