|
ADS
Algorithms and Data Structures
|
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): More...
#include "ADS/Capabilities.h"#include "ADS/Contract.h"#include "ADS/Modification.h"#include "ADS/Portable.h"#include "ADS/graph/Graph.h"#include <concepts>#include <cstddef>#include <cstdint>#include <optional>#include <span>#include <tuple>#include <type_traits>#include <utility>#include <variant>#include <vector>#include "ADS/graph/impl/Observable.tpp"Go to the source code of this file.
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... | |
Namespaces | |
| namespace | ADS |
| namespace | ADS::mod |
Concepts | |
| concept | ADS::GraphObserver |
| an observer of the events of weights W: the kinds that it wants, and the two ways of getting them | |
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 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):
deleteNode( u ) first sends the deletion of each edge of \( u \), so that an observer never sees an edge whose end is gone, and in an unoriented graph the ends of an edge in an event are in increasing order, \( u < v \).
The wrapper is ObservedGraph< G , Policy >, whose subject is a policy of Modification.h (NoObservers by default, so that a change compiles to the code of the graph), and whose events are the list GraphModifications< W >, and which forwards the queries of Capabilities.h to the graph; an observer of it is any object with an on( e ) for one of the five events (see Modification.h for the optional parts). Observable< G , O... > is the wrapper of the observers of the first form, which have mask(), the set of the kinds of event that they want as a mask of bits (see GraphEvents), and notify( e ) for one event and notify( s ) for a std::span of them (the concept GraphObserver): it is ObservedGraph with the policy Both< Static< O... > , Dynamic<> >, the observers of the first form called through an adapter. Those given to the constructor are static, kept in a std::tuple and called directly, with no indirection; those attached later by attach() are dynamic, kept as a pointer and pointers to functions that restore their type (the erasure of the type with no allocation), and they can leave by detach(). The design follows four rules: (i) no event is built when no one listens, since a change of kind \( k \) tests whether someone wants \( k \) (at compile time, then in the union \( M \) of the masks) before it reads anything that only the event needs (the old weight of an edge, the edges of a node to delete); (ii) each observer gets only the kinds in its mask, also within a batch; (iii) batch() opens a channel of RAII, and the events of the channels, which nest, are collected and sent as one span, coalesced into their net effect per edge by (8) of Changes of the graph and reoptimization, when the outermost one closes; (iv) an observer may defer its work to the next query, as those of Reoptimization.h do, and an observer with a recompute policy may get Rebuilt instead of a batch [see mod::with_policy]. The changes of the edges have their inverses, so that UndoLog undoes them through apply(), and the wrapper with observers is undoable within its batches (checkpoint(), rollback()): a batch that exits by an exception undoes its changes of the edges, and the graph and the observers are as before it, when every kind is listened to and no node was inserted or deleted (otherwise its events are sent, as on a structure that cannot be undone). A change sent at once costs \( O( 1 ) \) per observer that wants it, and a batch of \( k \) events costs \( O( k ) \) expected time to coalesce, plus \( O( k ) \) for each observer that does not want all its kinds (a filtered copy).
The dynamic algorithms of the literature take a sequence of updates (see the survey of Hanauer, Henzinger and Schulz), and a library that has them (e.g., the dynamic algorithms of NetworKit, whose update() and updateBatch() the caller feeds after changing the graph) leaves it to the caller to tell each of them what changed; here the wrapper does it, with the sets of interest of an event service and the coalescing of the batches of Acar et al. and of Tseng, Dhulipala and Shun.
The contracts [see Contract.h]: the changes of the graph go through the wrapper (a change made on the graph directly is not seen); an observer is neither attached nor detached while a channel is open, nor from within a notify(); close() is idempotent. The operations are defined in Observable.tpp.