ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::SpanningForestObserver< G, P > Class Template Reference

the minimum spanning forest of an unoriented \( g \), kept up to date, by the recompute policy P More...

#include <ADS/graph/Reoptimization.h>

Inheritance diagram for ADS::SpanningForestObserver< G, P >:
ADS::EventQueue< G::Weight, RatioPolicy >

Public types

using Weight = typename G::Weight
 the type of the weights
Public types inherited from ADS::EventQueue< G::Weight, RatioPolicy >
using Event
 the type of the events
using Policy
 the type of the policy

Public member functions

 SpanningForestObserver (const G &g)
 the forest of \( g \), computed by Kruskal at the first query; \( \alpha = 1 \) if the policy is a RatioPolicy
void solve (void)
 brings the forest up to date
std::vector< WeightedEdge< Weight > > forest (void)
 the edges of the forest, up to date, in no given order
Weight weight (void)
 the total weight of the forest, kept as it changes when the weights subtract, \( O( 1 ) \) after the query, and summed otherwise; a floating total is summed again after period times \( |F| \) changes, and compensated if compensated, when the policy has them [see RatioPolicy]
bool inForest (int u, int v)
 whether \( [ u , v ] \) is in the forest
ReoptStats reoptStats (std::size_t k) const
 the statistics of a query after \( k \) more events, for the policy: the events queued and the edges
Public member functions inherited from ADS::EventQueue< G::Weight, RatioPolicy >
void apply (const Event &e)
 queues \( e \), unless Rebuilt came since the last query
void notify (const Event &e)
 apply( e ), for the Observable
void on (const mod::Rebuilt &) noexcept
 forgets the queue, and takes no event until the next query, which computes the solution from scratch
std::size_t pending (void) const
 the events waiting for the next query
int outcome (void) const
 how the last solve() with events to apply, or with no solution yet, did it [see Reopt]
int cause (void) const
 why: the cause of the last outcome [see Reopt]
long long count (int outcome) const
 the solves of each outcome so far
long long byCause (int c) const
 the solves of each cause so far
P & policy (void)
 the recompute policy
void setRecomputeRatio (double ratio)
 from scratch when the events coalesced exceed \( \mathit{ratio} \) times the edges: \( \rho \) of the policy

Additional Inherited Members

Static public member functions inherited from ADS::EventQueue< G::Weight, RatioPolicy >
static constexpr unsigned mask (void)
 all the kinds of event
Protected member functions inherited from ADS::EventQueue< G::Weight, RatioPolicy >
std::vector< Event > take (void)
 the queue coalesced, emptied
bool tooMany (std::size_t k, long long m)
 whether the policy wants \( k \) events on \( m \) edges from scratch
bool fresh (bool ready)
 whether a solve from scratch is due before any event: no solution yet, or Rebuilt; the queue then emptied
void tally (int cause)
 the cause of a solve() counted, not told to the policy
void done (int cause, double w)
 the cause of a solve() counted and told to the policy with the work \( w \)
Static protected member functions inherited from ADS::EventQueue< G::Weight, RatioPolicy >
static ReoptStats stats (std::size_t k, long long m)
 the statistics of \( k \) events on \( m \) edges
Protected attributes inherited from ADS::EventQueue< G::Weight, RatioPolicy >
std::vector< Event > f_q
 the events queued
P f_policy
 the recompute policy
bool f_stale
 whether Rebuilt came
int f_outcome
 the last outcome
int f_cause
 the last cause
long long f_count [3]
 the solves by outcome
long long f_byCause [Reopt::CAUSES]
 the solves by cause

Detailed description

template<Graph G, ReoptPolicy P = RatioPolicy>
class ADS::SpanningForestObserver< G, P >

the minimum spanning forest of an unoriented \( g \), kept up to date, by the recompute policy P

Member typedef documentation

◆ Weight

template<Graph G, ReoptPolicy P = RatioPolicy>
using ADS::SpanningForestObserver< G, P >::Weight = typename G::Weight

the type of the weights

Constructor and destructor documentation

◆ SpanningForestObserver()

template<Graph G, ReoptPolicy P = RatioPolicy>
ADS::SpanningForestObserver< G, P >::SpanningForestObserver ( const G & g)
explicit

the forest of \( g \), computed by Kruskal at the first query; \( \alpha = 1 \) if the policy is a RatioPolicy

Precondition
\( g \) is unoriented

Member function documentation

◆ forest()

template<Graph G, ReoptPolicy P = RatioPolicy>
std::vector< WeightedEdge< Weight > > ADS::SpanningForestObserver< G, P >::forest ( void )
nodiscard

the edges of the forest, up to date, in no given order

◆ inForest()

template<Graph G, ReoptPolicy P = RatioPolicy>
bool ADS::SpanningForestObserver< G, P >::inForest ( int u,
int v )
nodiscard

whether \( [ u , v ] \) is in the forest

◆ reoptStats()

template<Graph G, ReoptPolicy P = RatioPolicy>
ReoptStats ADS::SpanningForestObserver< G, P >::reoptStats ( std::size_t k) const
nodiscard

the statistics of a query after \( k \) more events, for the policy: the events queued and the edges

◆ solve()

template<Graph G, ReoptPolicy P = RatioPolicy>
void ADS::SpanningForestObserver< G, P >::solve ( void )

brings the forest up to date

In pseudocode (Sleator and Tarjan for the cycles, beyond the book), the events \( P \) coalesced applied one at a time to the forest \( F \) kept by a link-cut tree [see LinkCutTree.h], each by (10) of Changes of the graph and reoptimization, as follows:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{solve}() \cr 2 & \quad \textbf{foreach}\ e = [ u , v ] \text{ from } w \text{ to } w' \text{ in } P\ \textbf{do} \cr 3 & \qquad \textbf{if}\ e \in F \textbf{ and } w' \le w\ \textbf{then} \ \text{set its weight in } F \quad \triangleright \ \text{harmless} \cr 4 & \qquad \textbf{else if}\ e \in F\ \textbf{then} \cr 5 & \qquad\quad \mathrm{cut}( u , v );\ X \gets \text{the smaller of} \text{ the two trees, by two visits of } F \text{ in turn} \cr 6 & \qquad\quad f \gets \text{the lightest edge out of } X \text{ ($e$ with } w' \text{ among them, unless deleted)} \cr 7 & \qquad\quad \textbf{if}\ f \ne \textbf{nil}\ \textbf{then} \ \mathrm{link}( f ) \cr 8 & \qquad \textbf{else if}\ w' \ne \bot \textbf{ and } ( w' < w \textbf{ or } w = \bot )\ \textbf{then} \cr 9 & \qquad\quad \textbf{if}\ \textbf{not}\ \mathrm{connected}( u , v ) \ \textbf{then}\ \mathrm{link}( e ) \cr 10 & \qquad\quad \textbf{else}\ f \gets \text{the heaviest edge of } F( u , v ) \text{ by } \mathrm{aggregate}( u , v ) \cr 11 & \qquad\qquad \textbf{if}\ w' < w( f )\ \textbf{then} \ \mathrm{cut}( f );\ \mathrm{link}( e ) \end{array}} \]

When the cuts of \( P \) (the edges of \( F \) raised or deleted) are many, i.e., when the policy abandons the replacements one at a time on their work, the number of the cuts times the mean work of the replacements so far, against that of join(), \( n \) plus the edges off \( F \) (by default with \( \alpha = 1 \), which this observer sets), the lines 5 to 7 only cut, the edges of the lines 8 to 11 wait, and join() joins the trees again before those edges are taken one at a time.

◆ weight()

template<Graph G, ReoptPolicy P = RatioPolicy>
Weight ADS::SpanningForestObserver< G, P >::weight ( void )
nodiscard

the total weight of the forest, kept as it changes when the weights subtract, \( O( 1 ) \) after the query, and summed otherwise; a floating total is summed again after period times \( |F| \) changes, and compensated if compensated, when the policy has them [see RatioPolicy]


The documentation for this class was generated from the following file: