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

the shortest paths from \( r \) in \( g \), kept up to date, by the recompute policy P More...

#include <ADS/graph/Reoptimization.h>

Inheritance diagram for ADS::ShortestPathsObserver< 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

 ShortestPathsObserver (const G &g, int r, Frontier how=Frontier::HEAP)
 the shortest paths from \( r \) in \( g \), computed by how at the first query
void solve (void)
 brings the tree up to date
const ShortestPathTree< Weight > & tree (void)
 the tree, up to date; its order is that of the last computation from scratch
Weight distance (int v)
 the distance of \( v \), infinity() if not reachable
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::ShortestPathsObserver< G, P >

the shortest paths from \( r \) in \( g \), kept up to date, by the recompute policy P

Member typedef documentation

◆ Weight

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

the type of the weights

Constructor and destructor documentation

◆ ShortestPathsObserver()

template<Graph G, ReoptPolicy P = RatioPolicy>
ADS::ShortestPathsObserver< G, P >::ShortestPathsObserver ( const G & g,
int r,
Frontier how = Frontier::HEAP )

the shortest paths from \( r \) in \( g \), computed by how at the first query

Precondition
\( r \) is a node of \( g \)

Member function documentation

◆ distance()

template<Graph G, ReoptPolicy P = RatioPolicy>
Weight ADS::ShortestPathsObserver< G, P >::distance ( int v)
inlinenodiscard

the distance of \( v \), infinity() if not reachable

◆ reoptStats()

template<Graph G, ReoptPolicy P = RatioPolicy>
ReoptStats ADS::ShortestPathsObserver< 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::ShortestPathsObserver< G, P >::solve ( void )

brings the tree up to date

In pseudocode (the algorithms of Ramalingam and Reps for the decreases and the increases, in the batch form of Bauer and Wagner, beyond the book; it is correct by Lemma 14 of Changes of the graph and reoptimization), the events \( P \) coalesced, \( T \) the tree and \( d \) the distances before them:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{solve}() \cr 2 & \quad R \gets \text{the heads } v \text{ of the arcs } ( u , v ) \in T \text{ raised or deleted in } P \cr 3 & \quad L \gets \text{the arcs lowered or inserted in } P \cr 4 & \quad A \gets \text{the nodes of the subtrees of } T \text{ under } R \cr 5 & \quad \textbf{if}\ p.\mathrm{abandon}( |A| , n )\ \textbf{then} \ \text{from scratch};\ \textbf{return} \quad \triangleright\ \text{by default } 2 |A| > n \cr 6 & \quad \textbf{foreach}\ x \in A\ \textbf{do}\ d[ x ] \gets \infty; \ T[ x ] \gets \textbf{nil} \cr 7 & \quad S \gets \emptyset \cr 8 & \quad \textbf{foreach}\ x \in A\ \textbf{do} \cr 9 & \qquad \textbf{foreach}\ ( u , x ) \in E\ \textbf{with} \ d[ u ] + w( u , x ) < d[ x ]\ \textbf{do}\ d[ x ] \gets d[ u ] + w( u , x );\ T[ x ] \gets u \cr 10 & \qquad \textbf{if}\ d[ x ] < \infty\ \textbf{then}\ S \gets S \cup \{ x \} \cr 11 & \quad \textbf{foreach}\ ( u , v ) \in L\ \textbf{with}\ d[ u ] + w( u , v ) < d[ v ]\ \textbf{do}\ S \gets S \cup \{ u \} \cr 12 & \quad \textbf{if}\ S = \emptyset\ \textbf{then}\ \textbf{return} \quad \triangleright\ \text{certified} \cr 13 & \quad H \gets \text{a priority queue of } S \text{ by } d \cr 14 & \quad \textbf{while}\ H \ne \emptyset\ \textbf{do} \cr 15 & \qquad u \gets \mathrm{deleteMin}( H ) \cr 16 & \qquad \textbf{if}\ u \text{ was extracted more than } n \text{ times}\ \textbf{then}\ \text{Bellman-Ford-Moore}; \ \textbf{return} \cr 17 & \qquad \textbf{if}\ u \text{ was extracted before and } p.\mathrm{abandon}\ \text{on its reinsertions}\ \textbf{then} \ \text{from scratch};\ \textbf{return} \cr 18 & \qquad \textbf{foreach}\ ( u , v ) \in E\ \textbf{with} \ d[ u ] + w( u , v ) < d[ v ]\ \textbf{do} \cr 19 & \qquad\quad d[ v ] \gets d[ u ] + w( u , v );\ T[ v ] \gets u; \ \mathrm{insert}( H , v , d[ v ] ) \end{array}} \]

◆ tree()

template<Graph G, ReoptPolicy P = RatioPolicy>
const ShortestPathTree< Weight > & ADS::ShortestPathsObserver< G, P >::tree ( void )
inlinenodiscard

the tree, up to date; its order is that of the last computation from scratch


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