5#ifndef LINE_LANG_LQN_LQN_STRUCT_H
6#define LINE_LANG_LQN_LQN_STRUCT_H
45#include <unordered_map>
100 std::vector<std::vector<std::pair<std::size_t, T>>>
row;
104 row.assign(nn + 1, {});
106 void set(std::size_t i, std::size_t j,
const T& v) {
107 for (
auto& e :
row[i])
112 row[i].emplace_back(j, v);
114 T
get(std::size_t i, std::size_t j)
const {
115 for (
const auto& e :
row[i])
116 if (e.first == j)
return e.second;
120 std::vector<std::size_t>
succ(std::size_t i)
const {
121 std::vector<std::size_t> out;
123 for (
const auto& e :
row[i])
124 if (e.second != zero) out.push_back(e.first);
125 std::sort(out.begin(), out.end());
129 std::vector<std::size_t>
pred(std::size_t j)
const {
130 std::vector<std::size_t> out;
132 for (std::size_t i = 1; i <=
n; ++i)
133 for (
const auto& e :
row[i])
134 if (e.first == j && e.second != zero) {
140 void erase(std::size_t i, std::size_t j) {
141 for (std::size_t k = 0; k <
row[i].size(); ++k)
142 if (
row[i][k].first == j) {
143 row[i].erase(
row[i].begin() + k);
152 std::vector<std::vector<std::size_t>>
row;
156 row.assign(nn + 1, {});
158 void set(std::size_t i, std::size_t j) {
159 for (std::size_t v :
row[i])
163 bool get(std::size_t i, std::size_t j)
const {
164 for (std::size_t v :
row[i])
165 if (v == j)
return true;
168 bool any_row(std::size_t i)
const {
return !
row[i].empty(); }
170 for (std::size_t i = 1; i <=
n; ++i)
171 if (
get(i, j))
return true;
174 std::vector<std::size_t>
col(std::size_t j)
const {
175 std::vector<std::size_t> out;
176 for (std::size_t i = 1; i <=
n; ++i)
177 if (
get(i, j)) out.push_back(i);
255 std::map<std::pair<std::size_t, std::size_t>,
double>
fanout;
256 std::map<std::pair<std::size_t, std::size_t>,
double>
fanin;
260 const std::map<std::pair<std::size_t, std::size_t>,
double>::const_iterator it =
261 fanout.find(std::make_pair(i, j));
262 return it ==
fanout.end() ? 0.0 : it->second;
304 std::vector<std::vector<std::size_t>>
tasksof;
306 std::vector<std::vector<std::size_t>>
actsof;
307 std::vector<std::vector<std::size_t>>
callsof;
372 if (
type[idx] == LqnElement::HOST)
return idx;
373 if (
type[idx] == LqnElement::TASK)
return parent[idx];
383 std::size_t cur = idx;
384 for (std::size_t hops = 0; hops <=
nidx; ++hops) {
385 if (cur < 1 || cur >
nidx || cur >=
type.size())
return 1.0;
386 if (
type[cur] == LqnElement::HOST) {
388 if (cur <
sched.size() &&
sched[cur] == SchedStrategy::INF)
return 1.0;
389 double m = cur <
mult.size() ?
mult[cur] : 1.0;
394 const std::size_t p = cur <
parent.size() ?
parent[cur] : 0;
395 if (p == 0 || p == cur)
return 1.0;
The exception types the port throws.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
Dense matrix and non-owning view.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
PrecedenceType
Activity precedence kinds, with the values of MATLAB ActivityPrecedenceType.
LqnElement
LQN element kinds, with the values of MATLAB LayeredNetworkElement.
RoutingStrategy
Routing strategies, with the values of MATLAB RoutingStrategy.
CallType
Call kinds, with the values of MATLAB CallType.
std::function< std::vector< T >(const std::vector< T > &)> CdScaling
A class-dependent scaling map, sn.cdscaling.
ReplacementStrategy
Cache replacement policies, with the values of MATLAB ReplacementStrategy.
Conservation laws of a layered queueing network, enumerated from its structure.
Number-type abstraction for the templated API port.
static constexpr double MaxInt
Stand-in for an unbounded COUNT, MATLAB GlobalConstants.MaxInt.
A boolean sparse relation over element indices, e.g.
void set(std::size_t i, std::size_t j)
bool any_row(std::size_t i) const
std::vector< std::size_t > col(std::size_t j) const
bool any_col(std::size_t j) const
bool get(std::size_t i, std::size_t j) const
void resize(std::size_t nn)
std::vector< std::vector< std::size_t > > row
One routed call group: an activity, the strategy that picks among its targets, and the target ENTRIES...
std::vector< std::size_t > targets
absolute entry indices, in declaration order
lang::RoutingStrategy strategy
std::size_t caller
absolute index of the dispatching activity
One activity precedence of a task, with its activities resolved to indices.
std::vector< std::size_t > preacts
absolute activity indices
std::vector< T > preparams
PRE_OR shares, or a PRE_AND quorum.
std::vector< T > postparams
POST_OR probabilities or the POST_LOOP count.
std::vector< std::size_t > postacts
absolute activity indices
std::vector< Distrib< T > > hostdem
(nidx+1) host demand per activity (Immediate elsewhere)
std::vector< std::vector< T > > jdscalingpeak
(tshift+ntasks+1)
std::vector< int > actphase
(nacts+1) phase of each activity, 1-based by act
std::vector< CallType > calltype
(ncalls+1)
std::vector< std::size_t > callpair_dst
(ncalls+1) called entry
std::vector< std::vector< LqnPrecedence< T > > > precedences
Activity precedences of each task, as DECLARED, indexed by the task's absolute index.
std::size_t host_of(std::size_t idx) const
Index of the host of the element, for a task or anything owned by one.
std::vector< std::string > callhashnames
(ncalls+1)
std::vector< Distrib< T > > setuptime
Setup tasks: the server powers down when idle and pays to restart.
std::map< std::pair< std::size_t, std::size_t >, double > fanout
Fan-out and fan-in, keyed by task element index, absent = 0.
std::vector< bool > hassetup
(tshift+ntasks+1)
std::vector< LqnElement > type
(nidx+1)
std::vector< std::size_t > nitems
Cache tasks and item entries.
std::vector< Distrib< T > > actthink
(nidx+1) activity think time
std::vector< std::vector< T > > lldscaling
Queue-dependent service rates declared on a layer server (a host or a task), by element index,...
std::vector< double > mult
(tshift+ntasks+1) declared multiplicity, may be Inf
std::vector< SchedStrategy > sched
(tshift+ntasks+1)
std::vector< std::size_t > callpair_src
(ncalls+1) calling activity (entry for FWD)
std::vector< std::size_t > parent
(nidx+1) host of a task, task of an entry/activity
std::vector< std::vector< T > > lincon_b
std::vector< ServerPools< T > > pools
(tshift+ntasks+1)
std::vector< T > callproc_mean
(ncalls+1) mean number of calls
std::vector< std::size_t > actquorum
(nidx+1) AND-join quorum, on the join target
std::vector< bool > iscache
(tshift+ntasks+1)
std::vector< bool > has_arrival
(nidx+1) entry with an open arrival
std::vector< std::vector< std::size_t > > callsof
(nidx+1) call indices issued by an activity
std::vector< std::string > hashnames
(nidx+1) name prefixed by kind: P:/T:/R:/E:/A:
std::vector< std::string > callnames
(ncalls+1)
std::vector< CdScaling< T > > cdscaling
(tshift+ntasks+1)
std::vector< std::vector< int > > itemcap
(tshift+ntasks+1)
std::vector< std::vector< std::size_t > > entriesof
(tshift+ntasks+1)
std::vector< bool > hasretrieval
(tshift+ntasks+1) cache task with delayed-hit retrieval
double fanout_at(std::size_t i, std::size_t j) const
fan-out from caller task i to callee task j; 0 when undeclared.
std::vector< double > repl
(tshift+ntasks+1) replication
std::vector< std::string > names
(nidx+1) declared name
std::vector< Matrix< T > > lincon_A
Admission constraint A n <= b on the layer station of a host or task.
SparseGraph< T > dag
graph with entry-task edges reversed and loop back-edges removed
std::vector< Distrib< T > > think
(nidx+1) task think time
std::vector< std::vector< std::size_t > > tasksof
(nhosts+1)
std::vector< bool > isref
(tshift+ntasks+1)
std::vector< PrecedenceType > actpretype
(nidx+1)
std::vector< std::vector< std::size_t > > actsof
(ashift+1) by task and by entry
std::map< std::pair< std::size_t, std::size_t >, double > fanin
std::vector< PrecedenceType > actposttype
(nidx+1)
std::vector< LqnCallGroup > callgroups
Synchronous calls DISPATCHED AS A GROUP, lsn.callgroups.
std::vector< std::vector< T > > cdscalingpeak
(tshift+ntasks+1)
std::vector< Distrib< T > > delayofftime
std::vector< int > prio
(tshift+ntasks+1) task priority, larger first (lqns); 0 on hosts (getStruct.m)
std::vector< Distrib< T > > arrival
(nidx+1) open arrival process of an entry
std::vector< std::vector< T > > itemproc
(nidx+1) popularity pmf
std::vector< CdScaling< T > > jdscaling
(tshift+ntasks+1)
double host_reach_mult(std::size_t idx) const
Servers of the host of element idx that its work can reach: the divisor of every LQN Util column (Sol...
std::vector< ReplacementStrategy > replacestrat
(tshift+ntasks+1)
std::vector< double > maxmult
(tshift+ntasks+1) sustainable multiplicity
SparseGraph< T > graph
element call/precedence graph, edge weights are branch shares
SparseGraph< T > taskgraph
task-to-task calls
Heterogeneous server pools declared on a layer server, the twin of the nservertypes / servertypenames...
Matrix< T > compat
(npools x noperands), nonzero = eligible
std::vector< double > counts
(npools) servers held by each pool
std::vector< std::string > names
(npools) declared pool name
std::vector< T > rates
(npools) per-pool rate multiplier
std::size_t npools() const
A sparse square matrix over element indices, held as a dense vector of rows with an explicit nonzero ...
std::vector< std::size_t > succ(std::size_t i) const
Successors of i in ascending index order, as MATLAB's find() returns them.
void erase(std::size_t i, std::size_t j)
std::vector< std::vector< std::pair< std::size_t, T > > > row
1-based, row[0] unused
void resize(std::size_t nn)
T get(std::size_t i, std::size_t j) const
void set(std::size_t i, std::size_t j, const T &v)
std::vector< std::size_t > pred(std::size_t j) const
Predecessors of j in ascending index order.