5#ifndef LINE_LANG_LQN_LQN_STRUCT_H
6#define LINE_LANG_LQN_LQN_STRUCT_H
46#include <unordered_map>
101 std::vector<std::vector<std::pair<std::size_t, T>>>
row;
105 row.assign(nn + 1, {});
107 void set(std::size_t i, std::size_t j,
const T& v) {
108 for (
auto& e :
row[i])
113 row[i].emplace_back(j, v);
115 T
get(std::size_t i, std::size_t j)
const {
116 for (
const auto& e :
row[i])
117 if (e.first == j)
return e.second;
121 std::vector<std::size_t>
succ(std::size_t i)
const {
122 std::vector<std::size_t> out;
124 for (
const auto& e :
row[i])
125 if (e.second != zero) out.push_back(e.first);
126 std::sort(out.begin(), out.end());
130 std::vector<std::size_t>
pred(std::size_t j)
const {
131 std::vector<std::size_t> out;
133 for (std::size_t i = 1; i <=
n; ++i)
134 for (
const auto& e :
row[i])
135 if (e.first == j && e.second != zero) {
141 void erase(std::size_t i, std::size_t j) {
142 for (std::size_t k = 0; k <
row[i].size(); ++k)
143 if (
row[i][k].first == j) {
144 row[i].erase(
row[i].begin() + k);
153 std::vector<std::vector<std::size_t>>
row;
157 row.assign(nn + 1, {});
159 void set(std::size_t i, std::size_t j) {
160 for (std::size_t v :
row[i])
164 bool get(std::size_t i, std::size_t j)
const {
165 for (std::size_t v :
row[i])
166 if (v == j)
return true;
169 bool any_row(std::size_t i)
const {
return !
row[i].empty(); }
171 for (std::size_t i = 1; i <=
n; ++i)
172 if (
get(i, j))
return true;
175 std::vector<std::size_t>
col(std::size_t j)
const {
176 std::vector<std::size_t> out;
177 for (std::size_t i = 1; i <=
n; ++i)
178 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;
303 std::vector<std::vector<std::size_t>>
tasksof;
305 std::vector<std::vector<std::size_t>>
actsof;
306 std::vector<std::vector<std::size_t>>
callsof;
371 if (
type[idx] == LqnElement::HOST)
return idx;
372 if (
type[idx] == LqnElement::TASK)
return parent[idx];
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.
Number-type abstraction for the templated API port.
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)
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< 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)
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.