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

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

Detailed description

A GRAPH that tells its changes, beyond the book.

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

Typedef documentation

◆ GraphEvent

template<class W>
using ADS::GraphEvent
Initial value:
std::variant< NodeInserted , NodeDeleted ,
an edge deleted, the weight that it had
Definition Observable.h:180
an edge , or with , inserted with the weight
Definition Observable.h:168
a node deleted, after the deletion of its edges
Definition Observable.h:157
a node inserted
Definition Observable.h:148
the weight of an edge changed from from to to
Definition Observable.h:192

an event, whose kind is its index in the variant, the variant of GraphModifications< W >

◆ GraphModifications

template<class W>
using ADS::GraphModifications
Initial value:
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482

the events of a graph of weights W, in the order of their kinds

◆ Observable

template<Graph G, class... O>
using ADS::Observable
Initial value:
G ,
detail::GraphNotify< typename G::Weight > >... > ,
the graph , whose changes are sent through the subject policy Policy [see Modification....
Definition Observable.h:382
the static observers of St, then those attached at run time
Definition Modification.h:1991
observers attached at run time, the events those of the structure (or the list L, which must be them)
Definition Modification.h:1980
the static observers O... (or mod::Via< O , A >), references called directly in the order of the argu...
Definition Modification.h:1968
the observer O called through the adapter A, an argument of Static
Definition Modification.h:954

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

Function documentation

◆ coalesce()

template<class W>
std::vector< GraphEvent< W > > ADS::coalesce ( std::span< const GraphEvent< W > > E)
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}} \]

◆ endsOf()

template<class W>
std::pair< int, int > ADS::endsOf ( const GraphEvent< W > & e)
nodiscard

the ends of the edge of \( e \), \( ( -1 , -1 ) \) for an event on a node

◆ inverse() [1/3]

template<class W>
EdgeInserted< W > ADS::inverse ( const EdgeDeleted< W > & e)
nodiscardconstexpr

the inverse of a deletion of an edge, its insertion with the weight it had

◆ inverse() [2/3]

template<class W>
EdgeDeleted< W > ADS::inverse ( const EdgeInserted< W > & e)
nodiscardconstexpr

the inverse of an insertion of an edge, its deletion

◆ inverse() [3/3]

template<class W>
WeightChanged< W > ADS::inverse ( const WeightChanged< W > & e)
nodiscardconstexpr

the inverse of a change of a weight, the change back

◆ kindOf()

template<class W>
unsigned ADS::kindOf ( const GraphEvent< W > & e)
nodiscardconstexpr

the bit of the kind of \( e \)