LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
snc_perc_backlog.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_SNC_PERC_BACKLOG_H
6#define LINE_API_SNC_PERC_BACKLOG_H
7
8/**
9 * @file
10 * @ingroup api_snc
11 * Backlog quantile at a prescribed violation probability.
12 *
13 * Inverts `snc_bound_backlog` in b: at fixed theta the smallest level for which
14 * the bound certifies P{B > b} <= eps is
15 *
16 * b(theta) = sigmaA + sigmaS - log(eps*(1-exp(-theta*(rhoS-rhoA))))/theta,
17 *
18 * and the reported quantile is its minimum over the feasible thetas. The
19 * minimizing theta differs from the one of the forward bound at a given level,
20 * which is why the inversion is done in closed form and re-optimized.
21 *
22 * Port of matlab/src/api/snc/snc_perc_backlog.m.
23 */
24
25#include <cmath>
26
29#include "line/util/error.h"
30
31namespace line {
32namespace snc {
33
34/**
35 * @brief Backlog quantile at a prescribed violation probability.
36 *
37 * @param arv arrival envelope
38 * @param srv service envelope
39 * @param eps violation probability, 0 < eps < 1
40 * @param thetamax upper end of the theta search
41 */
42inline SncResult snc_perc_backlog(const Envelope& arv, const Envelope& srv, double eps,
43 double thetamax = 1e3) {
44 if (!(eps > 0.0 && eps < 1.0))
45 throw UnsupportedError("snc_perc_backlog: eps must lie in (0,1)");
46 const SncResult r = snc_thetaopt(
47 [&](double theta) {
48 const detail::SncPair p = detail::snc_pair(arv, srv, theta);
49 if (!p.ok) return std::numeric_limits<double>::infinity();
50 return p.a.sigma + p.s.sigma -
51 std::log(eps * (1.0 - std::exp(-theta * (p.s.rho - p.a.rho)))) / theta;
52 },
53 thetamax);
54 return SncResult{std::max(r.value, 0.0), r.theta};
55}
56
57} // namespace snc
58} // namespace line
59
60#endif // LINE_API_SNC_PERC_BACKLOG_H
UnsupportedError(const std::string &what)
Definition error.h:51
The exception types the port throws.
std::function< Env(double)> Envelope
An envelope as a function of the Chernoff parameter.
Definition snc_types.h:48
SncResult snc_thetaopt(const std::function< double(double)> &fun, double thetamax=1e3)
Minimizes a Chernoff bound over the free parameter theta.
SncResult snc_perc_backlog(const Envelope &arv, const Envelope &srv, double eps, double thetamax=1e3)
Backlog quantile at a prescribed violation probability.
Minimizes a Chernoff bound over the free parameter theta.
Shared types of the stochastic network calculus domain.
A bound together with the theta that attains it.
Definition snc_types.h:51
double value
The bound: a violation probability, a quantile or a mean bound.
Definition snc_types.h:53
double theta
The minimizing theta, NaN when no feasible theta exists.
Definition snc_types.h:55