ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::Chooser Class Reference

the simulation of choice(), success and failure More...

#include <ADS/complexity/Nondeterminism.h>

Public member functions

int choice (int k)
 the choice among \( \{ 0 , \ldots , k - 1 \} \) that the current sequence makes at this depth, 0 the first time the depth is reached
template<class A>
bool run (A &&alg, long *runs=nullptr)
 whether some sequence of choices makes alg( *this ) return true; the runs made go to *runs, if given
std::vector< int > choices (void) const
 the choices of the last run, the successful one after a YES

Detailed description

the simulation of choice(), success and failure

Member function documentation

◆ choice()

int ADS::Chooser::choice ( int k)

the choice among \( \{ 0 , \ldots , k - 1 \} \) that the current sequence makes at this depth, 0 the first time the depth is reached

In pseudocode (section 18.3), \( P \) the sequence of the pairs (choice, alternatives) and \( t \) the choices made in this run:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{choice}( k )\quad \triangleright\ P \text{ the pairs (choice, arity) of the run, } t \text{ the next} \cr 2 & \quad \textbf{if}\ t = |P|\ \textbf{then}\ \text{append } ( 0 , k ) \text{ to } P\quad \triangleright\ \text{a new choice starts from } 0 \cr 3 & \quad t \gets t + 1;\ \textbf{return}\ \text{the choice of } P[ t ] \end{array}} \]

Precondition
\( k \ge 1 \)
Postcondition
the result is in \( [ 0 , k ) \)

◆ choices()

std::vector< int > ADS::Chooser::choices ( void ) const
nodiscard

the choices of the last run, the successful one after a YES

◆ run()

template<class A>
bool ADS::Chooser::run ( A && alg,
long * runs = nullptr )

whether some sequence of choices makes alg( *this ) return true; the runs made go to *runs, if given

In pseudocode (section 18.3), the sequences in lexicographic order, the next one obtained by dropping the choices with no alternative left and advancing the last one:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{run}( \mathit{alg} )\quad \triangleright \ \text{the runs in the lexicographic order of their choices} \cr 2 & \quad P \gets () \cr 3 & \quad \textbf{loop} \cr 4 & \qquad t \gets 0;\ \textbf{if}\ \mathit{alg}() \ \textbf{then return true} \cr 5 & \qquad \text{keep the first } t \text{ pairs of } P \text{, then drop from its end the pairs } ( k - 1 , k ) \text{ already at their last choice} \cr 6 & \qquad \textbf{if}\ P = ()\ \textbf{then return false}\quad \triangleright\ \text{every run failed} \cr 7 & \qquad \text{raise by one the choice of the last pair of } P \end{array}} \]


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