LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
line::workflow::Workflow< T > Class Template Reference

#include <line/lang/workflow/workflow.h>

Public Member Functions

 Workflow (const std::string &name)
const std::string & name () const
std::size_t add_activity (const std::string &name, const Distrib< T > &host_demand)
 Add an activity; the name must be unique.
std::size_t add_activity (const std::string &name, const T &mean)
 Add an activity with an exponential host demand of the given mean.
void add_precedence (const Precedence< T > &prec)
std::size_t num_activities () const
const std::vector< WorkflowActivity< T > > & activities () const
const std::vector< Precedence< T > > & precedences () const
std::size_t activity_index (const std::string &name) const
WorkflowActivity< T > & activity (const std::string &name)
const WorkflowActivity< T > & activity_at (std::size_t i) const
 Activity by index, the form a series-parallel LEAF node names it in.
void validate () const
 Validate the workflow, throwing on the first defect.
Distrib< T > to_ph ()
 The composed law of the workflow.
Distrib< T > refresh_ph ()
 Recompose the law after a demand change.
void set_activity_demand (const std::string &name, const Distrib< T > &host_demand)
 Change the host demand of one activity.
void set_activity_demand_mean (const std::string &name, const T &mean_value)
 Change only the mean of one activity, preserving its shape.
void invalidate_topology ()
 Discard the cached law and the decomposition.
void invalidate_activity (std::size_t act_idx)
 Mark one activity law dirty, keeping every other cached block.
void rescale_activity_leaf (std::size_t act_idx, const T &factor)
 Time-scale a cached leaf in place: S -> S*FACTOR with alpha fixed.
const SPTree< T > * sp_tree ()
 The cached series-parallel decomposition, or null when the precedence graph is not series-parallel.

Static Public Member Functions

static PhLaw< T > compose_serial (const PhLaw< T > &a, const PhLaw< T > &b)
 Serial composition: the second law starts when the first absorbs.
static PhLaw< T > compose_parallel (const PhLaw< T > &a, const PhLaw< T > &b)
 Parallel (AND-fork/join) composition: the time until BOTH complete.
static PhLaw< T > compose_mixture (const std::vector< PhLaw< T > > &laws, const std::vector< T > &probs)
 Probabilistic mixture: a block-diagonal generator whose initial vector picks branch i with probability PROBS[i].
static PhLaw< T > compose_loop_geometric (const PhLaw< T > &body, const T &count)
 Geometric repetition of a phase-type law, the POST_LOOP semantics.
static PhLaw< T > compose_repeat (const PhLaw< T > &body, long count)
 COUNT-fold convolution of a phase-type law.
static bool is_acyclic_generator (const Matrix< T > &S)
 True when the phase graph of S has no cycle.
static Precedence< T > Serial (const std::string &pre, const std::string &post)
static std::vector< Precedence< T > > SerialSequence (const std::vector< std::string > &acts)
static Precedence< T > AndFork (const std::string &pre, const std::vector< std::string > &posts)
static Precedence< T > AndJoin (const std::vector< std::string > &pres, const std::string &post, const std::vector< T > &quorum=std::vector< T >())
 An empty QUORUM means a full join; a partial one is refused by validate.
static Precedence< T > OrFork (const std::string &pre, const std::vector< std::string > &posts, const std::vector< T > &probs)
static Precedence< T > OrJoin (const std::vector< std::string > &pres, const std::string &post)
static Precedence< T > Loop (const std::string &pre, const std::vector< std::string > &posts, const T &count)
 A loop: PRE runs once, then POSTS[0..n-2] repeat a geometric number of times of mean COUNT and POSTS[n-1] continues after the loop.

Static Public Attributes

static constexpr std::size_t npos = static_cast<std::size_t>(-1)

Detailed Description

template<class T>
class line::workflow::Workflow< T >

Definition at line 223 of file workflow.h.

Constructor & Destructor Documentation

◆ Workflow()

template<class T>
line::workflow::Workflow< T >::Workflow ( const std::string & name)
inlineexplicit

Definition at line 227 of file workflow.h.

References name().

Member Function Documentation

◆ activities()

template<class T>
const std::vector< WorkflowActivity< T > > & line::workflow::Workflow< T >::activities ( ) const
inline

Definition at line 253 of file workflow.h.

◆ activity()

template<class T>
WorkflowActivity< T > & line::workflow::Workflow< T >::activity ( const std::string & name)
inline

Definition at line 261 of file workflow.h.

References activity_index(), line::InputError::InputError(), name(), and npos.

◆ activity_at()

template<class T>
const WorkflowActivity< T > & line::workflow::Workflow< T >::activity_at ( std::size_t i) const
inline

Activity by index, the form a series-parallel LEAF node names it in.

Definition at line 268 of file workflow.h.

References line::InputError::InputError().

◆ activity_index()

template<class T>
std::size_t line::workflow::Workflow< T >::activity_index ( const std::string & name) const
inline

Definition at line 256 of file workflow.h.

References name(), and npos.

Referenced by activity(), set_activity_demand(), set_activity_demand_mean(), and validate().

◆ add_activity() [1/2]

template<class T>
std::size_t line::workflow::Workflow< T >::add_activity ( const std::string & name,
const Distrib< T > & host_demand )
inline

Add an activity; the name must be unique.

Definition at line 232 of file workflow.h.

References line::InputError::InputError(), invalidate_topology(), and name().

Referenced by add_activity().

◆ add_activity() [2/2]

template<class T>
std::size_t line::workflow::Workflow< T >::add_activity ( const std::string & name,
const T & mean )
inline

Add an activity with an exponential host demand of the given mean.

Definition at line 243 of file workflow.h.

References add_activity(), line::workflow::Distrib< T >::exp_mean(), and name().

◆ add_precedence()

template<class T>
void line::workflow::Workflow< T >::add_precedence ( const Precedence< T > & prec)
inline

Definition at line 247 of file workflow.h.

References invalidate_topology().

◆ AndFork()

template<class T>
Precedence< T > line::workflow::Workflow< T >::AndFork ( const std::string & pre,
const std::vector< std::string > & posts )
inlinestatic

◆ AndJoin()

template<class T>
Precedence< T > line::workflow::Workflow< T >::AndJoin ( const std::vector< std::string > & pres,
const std::string & post,
const std::vector< T > & quorum = std::vector<T>() )
inlinestatic

◆ compose_loop_geometric()

template<class T>
PhLaw< T > line::workflow::Workflow< T >::compose_loop_geometric ( const PhLaw< T > & body,
const T & count )
inlinestatic

Geometric repetition of a phase-type law, the POST_LOOP semantics.

For COUNT >= 1 the body runs at least once and repeats on absorption with probability P = 1-1/COUNT, so

S_out = S + P/D (-S e) alpha, alpha_out = alpha / D

with D = 1 - P(1 - alpha e) the correction for an atom at zero in alpha. The ORDER is that of the body, unlike the COUNT-fold convolution, and the mean is COUNT times the body mean in both cases.

For COUNT < 1 the body runs at most once, with probability COUNT; the skipped branch is an immediate phase.

Definition at line 585 of file workflow.h.

References line::workflow::PhLaw< T >::alpha, line::workflow::GlobalConstants::FineTol, line::workflow::GlobalConstants::Immediate, line::Matrix< T >::Matrix(), and line::workflow::PhLaw< T >::S.

◆ compose_mixture()

template<class T>
PhLaw< T > line::workflow::Workflow< T >::compose_mixture ( const std::vector< PhLaw< T > > & laws,
const std::vector< T > & probs )
inlinestatic

Probabilistic mixture: a block-diagonal generator whose initial vector picks branch i with probability PROBS[i].

aph_simplify pattern 3, generalised to any number of branches.

Definition at line 548 of file workflow.h.

References line::workflow::PhLaw< T >::alpha, line::Matrix< T >::Matrix(), and line::workflow::PhLaw< T >::S.

◆ compose_parallel()

template<class T>
PhLaw< T > line::workflow::Workflow< T >::compose_parallel ( const PhLaw< T > & a,
const PhLaw< T > & b )
inlinestatic

Parallel (AND-fork/join) composition: the time until BOTH complete.

States (i,j) with both active carry the Kronecker sum S1 (+) S2; when one branch absorbs the chain moves into that branch's own survivor block, so the law is the maximum of the two.

Definition at line 496 of file workflow.h.

References line::workflow::PhLaw< T >::alpha, line::Matrix< T >::Matrix(), and line::workflow::PhLaw< T >::S.

◆ compose_repeat()

template<class T>
PhLaw< T > line::workflow::Workflow< T >::compose_repeat ( const PhLaw< T > & body,
long count )
inlinestatic

COUNT-fold convolution of a phase-type law.

The DETERMINISTIC repetition, kept for a caller that genuinely wants an exact number of executions. POST_LOOP is geometric and uses compose_loop_geometric instead.

Definition at line 638 of file workflow.h.

References line::workflow::PhLaw< T >::alpha, compose_serial(), line::workflow::GlobalConstants::Immediate, line::Matrix< T >::Matrix(), and line::workflow::PhLaw< T >::S.

◆ compose_serial()

template<class T>
PhLaw< T > line::workflow::Workflow< T >::compose_serial ( const PhLaw< T > & a,
const PhLaw< T > & b )
inlinestatic

Serial composition: the second law starts when the first absorbs.

S = [S1, (-S1 e) alpha2; 0, S2]

A defective alpha1 carries an atom at zero, which starts the second law immediately; this is aph_simplify pattern 1.

Definition at line 463 of file workflow.h.

References line::workflow::PhLaw< T >::alpha, line::Matrix< T >::Matrix(), and line::workflow::PhLaw< T >::S.

Referenced by compose_repeat().

◆ invalidate_activity()

template<class T>
void line::workflow::Workflow< T >::invalidate_activity ( std::size_t act_idx)
inline

Mark one activity law dirty, keeping every other cached block.

Definition at line 407 of file workflow.h.

References invalidate_topology(), and npos.

Referenced by set_activity_demand(), and set_activity_demand_mean().

◆ invalidate_topology()

template<class T>
void line::workflow::Workflow< T >::invalidate_topology ( )
inline

Discard the cached law and the decomposition.

Definition at line 396 of file workflow.h.

References npos.

Referenced by add_activity(), add_precedence(), invalidate_activity(), and rescale_activity_leaf().

◆ is_acyclic_generator()

template<class T>
bool line::workflow::Workflow< T >::is_acyclic_generator ( const Matrix< T > & S)
inlinestatic

True when the phase graph of S has no cycle.

A geometric loop over a body of two or more phases closes a cycle, so the composed law is a PH and not an APH.

Definition at line 657 of file workflow.h.

References line::workflow::GlobalConstants::ArcTol, and line::Matrix< T >::rows().

Referenced by to_ph().

◆ Loop()

template<class T>
Precedence< T > line::workflow::Workflow< T >::Loop ( const std::string & pre,
const std::vector< std::string > & posts,
const T & count )
inlinestatic

A loop: PRE runs once, then POSTS[0..n-2] repeat a geometric number of times of mean COUNT and POSTS[n-1] continues after the loop.

Definition at line 753 of file workflow.h.

References line::workflow::Precedence< T >::post_acts, line::workflow::Precedence< T >::post_params, line::workflow::Precedence< T >::post_type, line::workflow::Precedence< T >::pre_acts, and line::workflow::Precedence< T >::pre_type.

◆ name()

template<class T>
const std::string & line::workflow::Workflow< T >::name ( ) const
inline

◆ num_activities()

template<class T>
std::size_t line::workflow::Workflow< T >::num_activities ( ) const
inline

Definition at line 252 of file workflow.h.

◆ OrFork()

template<class T>
Precedence< T > line::workflow::Workflow< T >::OrFork ( const std::string & pre,
const std::vector< std::string > & posts,
const std::vector< T > & probs )
inlinestatic

◆ OrJoin()

template<class T>
Precedence< T > line::workflow::Workflow< T >::OrJoin ( const std::vector< std::string > & pres,
const std::string & post )
inlinestatic

◆ precedences()

template<class T>
const std::vector< Precedence< T > > & line::workflow::Workflow< T >::precedences ( ) const
inline

Definition at line 254 of file workflow.h.

◆ refresh_ph()

template<class T>
Distrib< T > line::workflow::Workflow< T >::refresh_ph ( )
inline

Recompose the law after a demand change.

Only the series-parallel nodes on the path from a dirty leaf to the root recompose; nodes whose subtree is unchanged keep their cached law. The topology is not rebuilt.

Definition at line 353 of file workflow.h.

References to_ph().

◆ rescale_activity_leaf()

template<class T>
void line::workflow::Workflow< T >::rescale_activity_leaf ( std::size_t act_idx,
const T & factor )
inline

Time-scale a cached leaf in place: S -> S*FACTOR with alpha fixed.

Ancestors still recompose, because they mix phases of several leaves, but the tree keeps its shape and no acyclic phase-type is refitted.

Definition at line 424 of file workflow.h.

References invalidate_topology(), line::workflow::SPNode< T >::law, npos, and line::workflow::SPNode< T >::valid.

Referenced by set_activity_demand_mean().

◆ Serial()

template<class T>
Precedence< T > line::workflow::Workflow< T >::Serial ( const std::string & pre,
const std::string & post )
inlinestatic

◆ SerialSequence()

template<class T>
std::vector< Precedence< T > > line::workflow::Workflow< T >::SerialSequence ( const std::vector< std::string > & acts)
inlinestatic

Definition at line 698 of file workflow.h.

References Serial().

◆ set_activity_demand()

template<class T>
void line::workflow::Workflow< T >::set_activity_demand ( const std::string & name,
const Distrib< T > & host_demand )
inline

Change the host demand of one activity.

Marks only that leaf dirty, which is the entry point an iterative solver uses when it updates call-response laws at each iteration.

Definition at line 361 of file workflow.h.

References activity_index(), line::InputError::InputError(), invalidate_activity(), name(), and npos.

◆ set_activity_demand_mean()

template<class T>
void line::workflow::Workflow< T >::set_activity_demand_mean ( const std::string & name,
const T & mean_value )
inline

Change only the mean of one activity, preserving its shape.

The law is scaled in time rather than refitted, so its SCV, its skewness and its order are preserved and the cached tree keeps its shape.

Definition at line 374 of file workflow.h.

References activity_index(), line::lang::dist_scale_rate(), line::workflow::Distrib< T >::exp_mean(), line::workflow::GlobalConstants::FineTol, line::InputError::InputError(), invalidate_activity(), line::lang::Distrib< T >::mean, name(), npos, rescale_activity_leaf(), and line::lang::Distrib< T >::type.

◆ sp_tree()

template<class T>
const SPTree< T > * line::workflow::Workflow< T >::sp_tree ( )
inline

The cached series-parallel decomposition, or null when the precedence graph is not series-parallel.

Definition at line 446 of file workflow.h.

◆ to_ph()

template<class T>
Distrib< T > line::workflow::Workflow< T >::to_ph ( )
inline

The composed law of the workflow.

The generator is acyclic unless a geometric loop closes a cycle over a multi-phase body, which is_acyclic_generator reports; the returned Distrib is typed APH or PH accordingly.

Definition at line 331 of file workflow.h.

References line::workflow::PhLaw< T >::alpha, is_acyclic_generator(), line::workflow::Distrib< T >::phase_type(), line::workflow::PhLaw< T >::S, and validate().

Referenced by refresh_ph().

◆ validate()

template<class T>
void line::workflow::Workflow< T >::validate ( ) const
inline

Validate the workflow, throwing on the first defect.

A quorum AND-join is refused here rather than composed as a full join.

Definition at line 278 of file workflow.h.

References activity_index(), line::workflow::GlobalConstants::FineTol, line::InputError::InputError(), npos, and line::UnsupportedError::UnsupportedError().

Referenced by to_ph().

Member Data Documentation

◆ npos

template<class T>
std::size_t line::workflow::Workflow< T >::npos = static_cast<std::size_t>(-1)
staticconstexpr

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