LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
pfqn_comom.h File Reference

CoMoM (class-oriented method of moments), the general basis formulation, and the original repairman-model implementation that preceded pfqn_comomrm. More...

#include <algorithm>
#include <cstddef>
#include <vector>
#include "line/api/pfqn/pfqn_comb_common.h"
#include "line/api/pfqn/pfqn_comomrm.h"
#include "line/api/pfqn/pfqn_nc_sanitize.h"
#include "line/num/number.h"
#include "line/util/error.h"
#include "line/util/lu.h"
#include "line/util/matrix.h"
Include dependency graph for pfqn_comom.h:

Go to the source code of this file.

Namespaces

namespace  line
namespace  line::pfqn

Functions

template<class T>
ComomResult< T > line::pfqn::pfqn_comom (const Matrix< T > &L, const std::vector< int > &N, const std::vector< T > &Z, const T &atol)
 CoMoM on the general basis (matlab pfqn_comom.m).
template<class T>
ComomResult< T > line::pfqn::pfqn_comom (const Matrix< T > &L, const std::vector< int > &N, const std::vector< T > &Z)
 Overload with the reference's default tolerance.
template<class T>
ComomResult< T > line::pfqn::pfqn_comomrm_orig (const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z, const T &atol)
 Original CoMoM for the finite repairman model (matlab pfqn_comomrm_orig.m).
template<class T>
ComomResult< T > line::pfqn::pfqn_comomrm_orig (const Matrix< T > &L, const std::vector< int > &N, const Matrix< T > &Z)
 Overload with the exact (zero-tolerance) tests.

Detailed Description

CoMoM (class-oriented method of moments), the general basis formulation, and the original repairman-model implementation that preceded pfqn_comomrm.

Templated port of matlab/src/api/pfqn/pfqn_comom.m and matlab/src/api/pfqn/pfqn_comomrm_orig.m. Both accept at most ONE queueing station (plus a delay); the reference raises an error for M > 1 and so does this port.

WHERE THIS DIFFERS FROM pfqn_comomrm. pfqn_comomrm (already ported) writes C^{-1} out in closed form and never forms a linear system. pfqn_comom builds the full (numDn (M+1)) x (numDn (M+1)) matrices A, B and DA of the CoMoM basis from scratch on the first job of each class, updates A by DA on every later job, and SOLVES A h = B h n_r / (sum(n) + M - 1) at each step. It is the slower but structurally general form, and it is a genuinely independent route to the same normalizing constant, which is what makes it worth carrying as a cross-check.

BASIS LAYOUT. Dn = multichoose(R, M) with its LAST column zeroed and the rows reordered by sort_by_nnz_pos. For M = 1 that is the R-row set {0, e_1, ..., e_{R-1}} with the zero row first. The basis position of the moment G(n - d) with "level" index i (i = 1 is the plain constant, i > 1 the per-station moment) is

col(d, 1) = numDn M + pos(d), col(d, i>1) = pos(d) M + i - 2

in zero-based columns, which is the reference's hash() with its 1-based indexing removed. Call sites index into that layout by POSITION, so the enumeration order of multichoose and the bubble sort that follows it are reproduced verbatim in pfqn_comb_common.h rather than replaced.

SCALING. The reference renormalizes h by |sum(h)| after every job and folds the discarded factors into a log accumulator, then also takes abs(h). The basis entries are normalizing constants and are positive, so the abs() is a no-op and the scale factors cancel in the final lG. This port carries the UNSCALED basis, exactly as pfqn_comomrm.h does, which is what makes

G(N) = h[matrixDim - R] * (sum(N) + M - 1)! / prod_r N_r! * prod_r Lmax_r^{N_r}

an exact identity in the field of the inputs.

SORTING IN pfqn_comomrm_orig. The reference sorts the classes by ascending think time AFTER calling pfqn_nc_sanitize, but permutes only L and Z, leaving N in place. That would desynchronize N from its demands, except that pfqn_nc_sanitize has ALREADY ordered the classes by ascending think time, so the second sort is the identity on every input. This port permutes L, Z and N together, which agrees with the reference wherever the reference is defined and is correct if the ordering guarantee were ever to change. Verified identical on L = [0.5 0.25 0.125], N = [1 2 1], Z = [4 0.25 0.5], whose post-sanitize think times [8 1 4] are NOT sorted before the second pass: MATLAB returns lG = -0.439231970578982 against the exact -0.43923197057898189.

Arithmetic: EXACT-CAPABLE. Additions, multiplications, divisions and one linear solve per job, all in the field of the inputs. The reference's logs are only the scale bookkeeping and the factln seeding, both of which are ratios of factorials formed directly here.

REFERENCE DEFECTS: none found in either routine. Both reproduce pfqn_ca to the last few ulps on every model tried, including the non-identity think-time ordering above.

Definition in file pfqn_comom.h.