LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
infer_get_qlen_arrival.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_INFER_INFER_GET_QLEN_ARRIVAL_H
6
#define LINE_API_INFER_INFER_GET_QLEN_ARRIVAL_H
7
8
/**
9
* @file
10
* @ingroup api_infer
11
* Per-class queue lengths at arrival for the per-class sample format.
12
*
13
* Templated port of matlab/src/api/infer/infer_get_qlen_arrival.m. No JAR
14
* counterpart.
15
*
16
* MATLAB reads its 6 x (K+1) cell array, taking data{3,k} as the arrival times
17
* of class k IN MILLISECONDS and data{4,k} as the response times in seconds.
18
* The cell container is a MATLAB storage detail with no meaning in C++, so the
19
* port takes the two per-class sample vectors directly; the millisecond to
20
* second conversion of the arrival times is kept, since it is what makes the
21
* two vectors commensurable.
22
*
23
* The classes are concatenated in order, given identity job ids, handed to
24
* infer_compute_ql_at_arrival, and split back per class.
25
*
26
* ARITHMETIC: one division and the event replay of
27
* infer_compute_ql_at_arrival, so a finite field computation. Note that the
28
* division by 1000 is exact in the exact instantiation and only there.
29
*/
30
31
#include <cstddef>
32
#include <vector>
33
34
#include "
line/api/infer/infer_compute_ql_at_arrival.h
"
35
#include "
line/num/number.h
"
36
#include "
line/util/error.h
"
37
#include "
line/util/matrix.h
"
38
39
namespace
line
{
40
namespace
infer
{
41
42
/**
43
* @brief Per-class queue lengths at arrival for the per-class sample format.
44
*
45
* @param at_ms (K) per-class arrival times, in milliseconds
46
* @param rt (K) per-class response times, in seconds
47
* @return (K) per-class (n_k x K) queue lengths at arrival
48
*/
49
template
<
class
T>
50
std::vector<Matrix<T>>
infer_get_qlen_arrival
(
const
std::vector<std::vector<T>>& at_ms,
51
const
std::vector<std::vector<T>>& rt) {
52
const
std::size_t K = at_ms.size();
53
if
(rt.size() != K)
54
throw
InputError
(
"infer_get_qlen_arrival: arrival and response time sets differ in size"
);
55
56
const
T thousand =
num_traits<T>::from_int
(1000);
57
std::vector<T> at, rtall;
58
std::vector<std::size_t> cls;
59
std::vector<std::size_t> nobs(K, 0);
60
for
(std::size_t k = 0; k < K; ++k) {
61
if
(at_ms[k].size() != rt[k].size())
62
throw
InputError
(
"infer_get_qlen_arrival: a class has mismatched sample counts"
);
63
nobs[k] = at_ms[k].size();
64
for
(std::size_t i = 0; i < nobs[k]; ++i) {
65
at.push_back(at_ms[k][i] / thousand);
// ms -> s
66
rtall.push_back(rt[k][i]);
67
cls.push_back(k);
68
}
69
}
70
71
const
std::size_t n = at.size();
72
std::vector<long> jobid(n);
73
for
(std::size_t i = 0; i < n; ++i) jobid[i] = static_cast<long>(i) + 1;
74
75
const
Matrix<T>
ql =
infer_compute_ql_at_arrival
(at, jobid, rtall, jobid, cls, K);
76
77
std::vector<Matrix<T>> out;
78
out.reserve(K);
79
std::size_t counter = 0;
80
for
(std::size_t k = 0; k < K; ++k) {
81
Matrix<T>
qk(nobs[k], K,
num_traits<T>::from_int
(0));
82
for
(std::size_t i = 0; i < nobs[k]; ++i)
83
for
(std::size_t c = 0; c < K; ++c) qk(i, c) = ql(counter + i, c);
84
counter += nobs[k];
85
out.push_back(qk);
86
}
87
return
out;
88
}
89
90
}
// namespace infer
91
}
// namespace line
92
93
#endif
// LINE_API_INFER_INFER_GET_QLEN_ARRIVAL_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::Matrix
Definition
matrix.h:56
error.h
The exception types the port throws.
infer_compute_ql_at_arrival.h
Per-class queue lengths seen by each arriving job, reconstructed from arrival and response time sampl...
matrix.h
Dense matrix and non-owning view.
line::infer
Definition
infer_compute_ql_at_arrival.h:39
line::infer::infer_get_qlen_arrival
std::vector< Matrix< T > > infer_get_qlen_arrival(const std::vector< std::vector< T > > &at_ms, const std::vector< std::vector< T > > &rt)
Per-class queue lengths at arrival for the per-class sample format.
Definition
infer_get_qlen_arrival.h:50
line::infer::infer_compute_ql_at_arrival
Matrix< T > infer_compute_ql_at_arrival(const std::vector< T > &at, const std::vector< long > &at_jobid, const std::vector< T > &rt, const std::vector< long > &rt_jobid, const std::vector< std::size_t > &cls, std::size_t R)
Per-class queue lengths seen by each arriving job, reconstructed from arrival and response time sampl...
Definition
infer_compute_ql_at_arrival.h:54
line
Definition
aoi_dist2ph.h:52
number.h
Number-type abstraction for the templated API port.
line::num_traits
Definition
number.h:111
include
line
api
infer
infer_get_qlen_arrival.h
Generated by
1.18.0