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

the queue of the events, the recompute policy P [see ReoptPolicy] and the counts that the observers share More...

#include <ADS/graph/Reoptimization.h>

Public types

using Event = GraphEvent< W >
 the type of the events
using Policy = P
 the type of the policy

Public member functions

void apply (const Event &e)
 queues \( e \), unless Rebuilt came since the last query
void apply (std::span< const Event > s)
 queues the events of \( s \), unless Rebuilt came
void notify (const Event &e)
 apply( e ), for the Observable
void notify (std::span< const Event > s)
 apply( s ), 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
const P & policy (void) const
 the recompute policy
void setRecomputeRatio (double ratio)
 from scratch when the events coalesced exceed \( \mathit{ratio} \) times the edges: \( \rho \) of the policy

Static public member functions

static constexpr unsigned mask (void)
 all the kinds of event

Protected member functions

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

static ReoptStats stats (std::size_t k, long long m)
 the statistics of \( k \) events on \( m \) edges

Protected attributes

std::vector< Event > f_q
 the events queued
P f_policy {}
 the recompute policy
bool f_stale = false
 whether Rebuilt came
int f_outcome = Reopt::SCRATCH
 the last outcome
int f_cause = Reopt::SCRATCH_BY_EVENT
 the last cause
long long f_count [3] = { 0 , 0 , 0 }
 the solves by outcome
long long f_byCause [Reopt::CAUSES] = {}
 the solves by cause

Detailed description

template<class W, ReoptPolicy P = RatioPolicy>
class ADS::EventQueue< W, P >

the queue of the events, the recompute policy P [see ReoptPolicy] and the counts that the observers share

In pseudocode (beyond the book; Lemma 13 of Changes of the graph and reoptimization and Lemma 17 of The recompute policy of the observers prove it correct), the query of every observer, with \( Q \) the queue and \( p \) the policy:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{solve}() \cr 2 & \quad \textbf{if}\ \text{there is no solution yet, or } \mathrm{Rebuilt}\ \text{came}\ \textbf{then} \ \text{compute it from scratch};\ \textbf{return} \cr 3 & \quad P \gets \mathrm{coalesce}( Q );\ Q \gets \emptyset \cr 4 & \quad \textbf{if}\ p.\mathrm{scratch}( |P| , m )\ \textbf{then} \ \text{compute from scratch};\ \textbf{return} \cr 5 & \quad \textbf{foreach}\ e \in P\ \textbf{do}\ \text{test } e \text{ against the certificate} \cr 6 & \quad \textbf{if}\ \text{an event is fatal, or } p.\mathrm{abandon}( \text{the work})\ \textbf{then}\ \text{compute from scratch} \cr 7 & \quad \textbf{else if}\ \text{an event is repairable} \ \textbf{then}\ \text{repair the solution} \cr 8 & \quad \textbf{else}\ \text{keep it, certified} \cr 9 & \quad p.\mathrm{record}( \text{the cause} , \text{the work} ) \end{array}} \]

Member typedef documentation

◆ Event

template<class W, ReoptPolicy P = RatioPolicy>
using ADS::EventQueue< W, P >::Event = GraphEvent< W >

the type of the events

◆ Policy

template<class W, ReoptPolicy P = RatioPolicy>
using ADS::EventQueue< W, P >::Policy = P

the type of the policy

Member function documentation

◆ apply() [1/2]

template<class W, ReoptPolicy P = RatioPolicy>
void ADS::EventQueue< W, P >::apply ( const Event & e)
inline

queues \( e \), unless Rebuilt came since the last query

◆ apply() [2/2]

template<class W, ReoptPolicy P = RatioPolicy>
void ADS::EventQueue< W, P >::apply ( std::span< const Event > s)
inline

queues the events of \( s \), unless Rebuilt came

◆ byCause()

template<class W, ReoptPolicy P = RatioPolicy>
long long ADS::EventQueue< W, P >::byCause ( int c) const
inlinenodiscard

the solves of each cause so far

Precondition
\( c \in [ 1 , \mathrm{Reopt::CAUSES} ) \)

◆ cause()

template<class W, ReoptPolicy P = RatioPolicy>
int ADS::EventQueue< W, P >::cause ( void ) const
inlinenodiscard

why: the cause of the last outcome [see Reopt]

◆ count()

template<class W, ReoptPolicy P = RatioPolicy>
long long ADS::EventQueue< W, P >::count ( int outcome) const
inlinenodiscard

the solves of each outcome so far

◆ done()

template<class W, ReoptPolicy P = RatioPolicy>
void ADS::EventQueue< W, P >::done ( int cause,
double w )
inlineprotected

the cause of a solve() counted and told to the policy with the work \( w \)

◆ fresh()

template<class W, ReoptPolicy P = RatioPolicy>
bool ADS::EventQueue< W, P >::fresh ( bool ready)
inlinenodiscardprotected

whether a solve from scratch is due before any event: no solution yet, or Rebuilt; the queue then emptied

◆ mask()

template<class W, ReoptPolicy P = RatioPolicy>
constexpr unsigned ADS::EventQueue< W, P >::mask ( void )
inlinestaticnodiscardconstexpr

all the kinds of event

◆ notify() [1/2]

template<class W, ReoptPolicy P = RatioPolicy>
void ADS::EventQueue< W, P >::notify ( const Event & e)
inline

apply( e ), for the Observable

◆ notify() [2/2]

template<class W, ReoptPolicy P = RatioPolicy>
void ADS::EventQueue< W, P >::notify ( std::span< const Event > s)
inline

apply( s ), for the Observable

◆ on()

template<class W, ReoptPolicy P = RatioPolicy>
void ADS::EventQueue< W, P >::on ( const mod::Rebuilt & )
inlinenoexcept

forgets the queue, and takes no event until the next query, which computes the solution from scratch

◆ outcome()

template<class W, ReoptPolicy P = RatioPolicy>
int ADS::EventQueue< W, P >::outcome ( void ) const
inlinenodiscard

how the last solve() with events to apply, or with no solution yet, did it [see Reopt]

◆ pending()

template<class W, ReoptPolicy P = RatioPolicy>
std::size_t ADS::EventQueue< W, P >::pending ( void ) const
inlinenodiscard

the events waiting for the next query

◆ policy() [1/2]

template<class W, ReoptPolicy P = RatioPolicy>
P & ADS::EventQueue< W, P >::policy ( void )
inlinenodiscard

the recompute policy

◆ policy() [2/2]

template<class W, ReoptPolicy P = RatioPolicy>
const P & ADS::EventQueue< W, P >::policy ( void ) const
inlinenodiscard

the recompute policy

◆ setRecomputeRatio()

template<class W, ReoptPolicy P = RatioPolicy>
void ADS::EventQueue< W, P >::setRecomputeRatio ( double ratio)
inline

from scratch when the events coalesced exceed \( \mathit{ratio} \) times the edges: \( \rho \) of the policy

Precondition
\( \mathit{ratio} \ge 0 \)

◆ stats()

template<class W, ReoptPolicy P = RatioPolicy>
ReoptStats ADS::EventQueue< W, P >::stats ( std::size_t k,
long long m )
inlinestaticnodiscardprotected

the statistics of \( k \) events on \( m \) edges

◆ take()

template<class W, ReoptPolicy P = RatioPolicy>
std::vector< Event > ADS::EventQueue< W, P >::take ( void )
inlineprotected

the queue coalesced, emptied

◆ tally()

template<class W, ReoptPolicy P = RatioPolicy>
void ADS::EventQueue< W, P >::tally ( int cause)
inlineprotected

the cause of a solve() counted, not told to the policy

◆ tooMany()

template<class W, ReoptPolicy P = RatioPolicy>
bool ADS::EventQueue< W, P >::tooMany ( std::size_t k,
long long m )
inlinenodiscardprotected

whether the policy wants \( k \) events on \( m \) edges from scratch

Member data documentation

◆ f_byCause

template<class W, ReoptPolicy P = RatioPolicy>
long long ADS::EventQueue< W, P >::f_byCause[Reopt::CAUSES] = {}
protected

the solves by cause

◆ f_cause

template<class W, ReoptPolicy P = RatioPolicy>
int ADS::EventQueue< W, P >::f_cause = Reopt::SCRATCH_BY_EVENT
protected

the last cause

◆ f_count

template<class W, ReoptPolicy P = RatioPolicy>
long long ADS::EventQueue< W, P >::f_count[3] = { 0 , 0 , 0 }
protected

the solves by outcome

◆ f_outcome

template<class W, ReoptPolicy P = RatioPolicy>
int ADS::EventQueue< W, P >::f_outcome = Reopt::SCRATCH
protected

the last outcome

◆ f_policy

template<class W, ReoptPolicy P = RatioPolicy>
P ADS::EventQueue< W, P >::f_policy {}
protected

the recompute policy

◆ f_q

template<class W, ReoptPolicy P = RatioPolicy>
std::vector< Event > ADS::EventQueue< W, P >::f_q
protected

the events queued

◆ f_stale

template<class W, ReoptPolicy P = RatioPolicy>
bool ADS::EventQueue< W, P >::f_stale = false
protected

whether Rebuilt came


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