LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
lqn2pn.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_IO_LQN2PN_H
6#define LINE_IO_LQN2PN_H
7
8/**
9 * @file
10 * @ingroup line_io
11 * LQN2PN: LayeredNetwork to Petri net (GSPN) translator.
12 *
13 * Port of `python/line_solver/io/lqn2pn.py` and `matlab/src/io/LQN2PN.m`; the
14 * three must stay in step and produce the same net: the same node list, class
15 * list, populations and transition modes, in the same order. See
16 * `_kb/06-solver-catalog.md` (LQN2PN) for the construction and its caveats.
17 *
18 * Construction, in brief:
19 *
20 * - Every request travels as a token. A reference task replica is a closed
21 * class whose population is the task multiplicity, waiting in `<T>_think` and
22 * leaving it through a timed, infinite-server transition with the think-time
23 * law. An entry with an open arrival is an open class fed by a Source and
24 * absorbed by a Sink at the reply.
25 * - A finite thread pool is a closed class of thread tokens held in
26 * `<T>_free`; an immediate mode `<E>_acq` takes one with the request and parks
27 * it in `<T>_busy`, and the reply returns it.
28 * - An FCFS or SIRO processor is a closed class of processor tokens in
29 * `<P>_free`, taken by an immediate `<A>_get` and returned by the timed,
30 * infinite-server `<A>_run`. A PS processor has no tokens: its run modes have
31 * the marking-dependent rate `g = min(1, c/n)`, n the jobs at the processor,
32 * read through never-binding inhibitor arcs. An infinite-server processor is
33 * the timed run mode alone.
34 * - Sequence and OR precedences are place merges and weighted immediate modes,
35 * an AND-fork is one immediate mode putting a token on every branch, an
36 * AND-join one immediate mode taking one token from every branch.
37 * - A synchronous call moves the caller's token into a per-call-site copy of
38 * the callee, unrolled into floor(m) stages plus one Bernoulli stage. An
39 * asynchronous call mints a token of a class of its own (population 0). A
40 * forwarding hands the request, with its continuation, to the target entry.
41 * - Phase 2: at the reply the request returns to the caller and the thread
42 * token (or a minted `<T>_ph2` token) walks the phase-2 activities.
43 * - Replication is materialised (one copy per replica, with the fan-out block
44 * rule of LQN2QN) or pooled (r times the tokens).
45 *
46 * Refused by name, as `LINE:unsupported:<kind>`: cache tasks (CacheTask), setup
47 * tasks (SetupTask), admission constraints (AdmissionConstraint), load, class
48 * and joint dependence (LoadDependence), server pools (ServerPools), scheduling
49 * other than FCFS, SIRO, PS and INF, plus REF on tasks (SchedStrategy), an
50 * AND-join quorum below its branch count (AndJoinQuorum), a host demand on a
51 * PS processor that is not a renewal phase-type law (PSNonPhaseType: MAP, ME,
52 * RAP, Det, Uniform, Gamma, ...) and the unrepresentable fork/join shapes
53 * (Structure). A phase-type demand (alpha, S) on a PS processor is expanded
54 * into one place `<A>_ph<k>` per phase, entered by alpha through `<A>_start`
55 * and left through exponential modes `<A>_run<k>` (rates S(k,j) and the exit
56 * rates) scaled by min(1, c/n): exact PS with phase-type service.
57 */
58
59#include <algorithm>
60#include <cctype>
61#include <cmath>
62#include <cstddef>
63#include <cstdio>
64#include <functional>
65#include <iostream>
66#include <limits>
67#include <map>
68#include <set>
69#include <string>
70#include <utility>
71#include <vector>
72
73#include "line/io/lqn2qn.h"
77#include "line/num/number.h"
78#include "line/util/error.h"
79
80namespace line {
81namespace io {
82
83/** A (place, class) pair of the Petri net, by node and class NAME. */
84struct Lqn2PnCell {
85 std::string place;
86 std::string cls;
87};
88
89/**
90 * Where to read a processor replica. An FCFS or SIRO processor is a token
91 * pool: its utilisation is `QLen(busy)/mult`, and `busy` holds the single
92 * (busy place, cpu class) pair while `run` is empty. A PS or INF processor has
93 * no tokens: its utilisation is the sum of `QLen` over the `run` cells divided
94 * by `mult` (Inf for an infinite-server processor), and `busy` is empty.
95 */
97 std::string name; ///< processor name, `_r<k>` suffixed for replica k >= 2
98 std::string sched; ///< scheduling, as the Python enum name (FCFS, SIRO, PS, INF)
99 double mult = 0.0;
100 std::vector<Lqn2PnCell> busy;
101 std::vector<Lqn2PnCell> run;
102};
103
104/**
105 * Where to read a task replica. A thread pool (`has_pool`) has `mult - QLen`
106 * of `free` busy threads; a reference task (`is_ref`) has its idle population
107 * at `think`.
108 */
110 std::string name;
111 double mult = 0.0;
112 bool has_pool = false;
114 bool is_ref = false;
116};
117
118/** The (place, class) copies of an entry or activity whose Tput sums to its throughput. */
120 std::string name;
121 std::vector<Lqn2PnCell> cells;
122};
123
124/** The result map of LQN2PN, the twin of the Python `return_map` dictionary, insertion-ordered. */
125struct Lqn2PnMap {
126 std::vector<Lqn2PnProcessor> processors;
127 std::vector<Lqn2PnTask> tasks;
128 std::vector<Lqn2PnElement> entries;
129 std::vector<Lqn2PnElement> activities;
130};
131
132namespace detail {
133
134template <class T>
135class Lqn2Pn {
136 public:
137 typedef lang::Distrib<T> Dist;
138 typedef std::pair<std::size_t, std::size_t> Key;
139
140 Lqn2Pn(const lqn::LqnStruct<T>& lsn, const std::set<Key>& replies, const std::string& replication,
141 const std::string& name, std::vector<std::string>* warnings, Lqn2PnMap* map)
142 : l_(lsn), replies_(replies), replication_(replication), name_(name), warnings_(warnings),
143 map_(map) {}
144
145 qn::Network<T> run() {
146 if (replication_ != "auto" && replication_ != "materialize" && replication_ != "pool")
147 throw InputError(ErrorKind{"Argument"},
148 "LQN2PN: replication must be 'auto', 'materialize' or 'pool'.");
149 refusals();
150 replication();
151 build();
152 return emit();
153 }
154
155 private:
156 static constexpr std::size_t NOPL = static_cast<std::size_t>(-1); // Python None
157 static constexpr std::size_t SINK = static_cast<std::size_t>(-2); // Python 'sink'
158 static constexpr std::size_t MAXCALLSTAGES = 20;
159 static constexpr std::size_t MAXREPLINSTANCES = 128;
160
161 struct PlaceRec {
162 std::string name;
163 bool pinned;
164 };
165 struct ClassRec {
166 std::string name;
167 bool open;
168 double pop;
169 std::size_t ref;
170 Dist arrival;
171 };
172 struct Arc {
173 std::size_t place, cls;
174 double n;
175 Arc(std::size_t p, std::size_t c, double k = 1.0) : place(p), cls(c), n(k) {}
176 };
177 struct Mode {
178 std::string name;
179 std::vector<Arc> ins, outs, inh;
180 bool immediate;
181 Dist dist;
182 T weight;
183 bool hasPs;
184 Key ps;
185 std::size_t k;
186 };
187 struct TransRec {
188 std::string name;
189 std::vector<Mode> modes;
190 };
191 struct Opt {
192 T w;
193 std::vector<Arc> outs;
194 };
195 struct Res {
196 std::size_t cls, free, busy;
197 double mult;
198 };
199 struct Marking {
200 std::size_t place, cls;
201 double v;
202 };
203 struct Stage {
204 std::size_t target;
205 T prob;
206 bool isasync;
207 };
208 struct Seg {
209 int kind; // 0 demand, 1 think, 2 call
210 Dist d;
211 std::size_t k;
212 Stage st;
213 };
214 struct JoinIn {
215 std::size_t aidx, place, cls;
216 int phase;
217 };
218 struct JoinRec {
219 std::size_t j, owner;
220 std::vector<JoinIn> inputs;
221 bool done;
222 };
223 /** State of one expand_entry call, the closure of the Python walk. */
224 struct Ctx {
225 std::size_t eidx, trep, tok, ret, tidx;
226 Key tkey;
227 std::string ename;
228 bool pool;
229 Res poolRes;
230 std::vector<std::size_t> localActs;
231 std::map<std::pair<std::size_t, int>, std::size_t> visited;
232 std::vector<JoinRec> joins;
233 std::vector<std::size_t> forkStack;
234 bool fwdDone;
235 std::vector<std::pair<T, std::size_t> > fwd;
236 };
237 struct Ordered {
238 std::vector<std::pair<std::string, std::vector<std::pair<std::size_t, std::size_t> > > > rows;
239 std::map<std::string, std::size_t> at;
240 void add(const std::string& k, std::size_t p, std::size_t c) {
241 std::map<std::string, std::size_t>::iterator it = at.find(k);
242 if (it == at.end()) {
243 at[k] = rows.size();
244 rows.push_back(std::make_pair(k, std::vector<std::pair<std::size_t, std::size_t> >()));
245 rows.back().second.push_back(std::make_pair(p, c));
246 } else {
247 rows[it->second].second.push_back(std::make_pair(p, c));
248 }
249 }
250 };
251
252 const lqn::LqnStruct<T>& l_;
253 const std::set<Key>& replies_;
254 std::string replication_;
255 std::string name_;
256 std::vector<std::string>* warnings_;
257 Lqn2PnMap* map_;
258
259 std::vector<double> replRaw_;
260 bool materialize_ = false;
261 std::vector<std::size_t> refTasks_, openEntries_;
262
263 std::vector<PlaceRec> places_;
264 std::vector<std::size_t> uf_;
265 std::vector<ClassRec> classes_;
266 std::vector<TransRec> trans_;
267 std::vector<Marking> marking_;
268 std::map<std::string, int> usedNode_, usedClass_;
269
270 std::map<Key, Res> cpu_;
271 std::map<Key, std::vector<std::pair<std::size_t, std::size_t> > > psPos_, runPos_;
272 std::map<Key, std::vector<std::size_t> > psModes_;
273 std::vector<std::pair<Key, Res> > thr_;
274 std::map<Key, std::size_t> thrIdx_;
275 std::map<Key, std::size_t> ph2cls_;
276 Ordered actMap_, entryMap_;
277 std::vector<Key> entryStack_;
278 std::vector<std::pair<Key, std::size_t> > thinkPlace_;
279 std::vector<std::pair<std::size_t, std::size_t> > openSrc_;
280
281 // ------------------------------------------------------------ small helpers
282
283 static T tnum(double v) { return num_traits<T>::from_double(v); }
284 static double dbl(const T& v) { return num_traits<T>::to_double(v); }
285 /** Renewal phase-type laws a PS processor expands into one place per phase. */
286 static bool psPhaseType(lang::ProcessType t) {
290 }
291 static double tol() { return lang::GlobalConstants::FineTol; }
292
293 void warn(const std::string& msg) {
294 if (warnings_ != nullptr)
295 warnings_->push_back("LQN2PN: " + msg);
296 else
297 std::cerr << "[LINE] Warning: LQN2PN: " << msg << std::endl;
298 }
299
300 [[noreturn]] static void refuse(const std::string& kind, const std::string& msg) {
301 throw UnsupportedError(ErrorKind{kind}, "LQN2PN: " + msg);
302 }
303
304 static std::string fmtG(double v) {
305 char buf[64];
306 std::snprintf(buf, sizeof(buf), "%g", v);
307 return std::string(buf);
308 }
309
310 /** The Python enum name of a discipline, e.g. FCFS, PS, LCFSPR. */
311 static std::string schedName(lang::SchedStrategy s) {
312 std::string out = lang::sched_to_text(s);
313 for (std::size_t i = 0; i < out.size(); ++i)
314 out[i] = static_cast<char>(std::toupper(static_cast<unsigned char>(out[i])));
315 return out;
316 }
317
318 /** A distribution that is declared, not Immediate and above tolerance. */
319 static bool timed(const Dist& d) { return !d.disabled && !d.is_immediate() && dbl(d.mean) > tol(); }
320
321 const std::string& nm(std::size_t idx) const { return l_.names[idx]; }
322 std::size_t parent(std::size_t idx) const { return l_.parent[idx]; }
323 lang::SchedStrategy sched(std::size_t idx) const { return l_.sched[idx]; }
324 double mult(std::size_t idx) const { return l_.mult[idx]; }
325 double imult(std::size_t idx) const { return std::trunc(l_.mult[idx]); } // Python int()
326
327 bool isAndJoinPre(std::size_t aidx) const {
328 return aidx < l_.actpretype.size() && l_.actpretype[aidx] == lang::PrecedenceType::PRE_AND;
329 }
330 bool isAndFork(const std::vector<std::size_t>& succ) const {
331 if (succ.size() < 2) return false;
332 for (std::size_t s : succ)
333 if (!(s < l_.actposttype.size() && l_.actposttype[s] == lang::PrecedenceType::POST_AND))
334 return false;
335 return true;
336 }
337 /** Branch tails feeding an AND-join, i.e. its PRE_AND predecessors. */
338 std::size_t countAndJoinBranches(std::size_t j) const {
339 std::size_t n = 0;
340 for (std::size_t p : l_.graph.pred(j))
341 if (p != j && isAndJoinPre(p)) ++n;
342 return n;
343 }
344
345 static std::string suffixed(const std::string& name, std::size_t rep) {
346 return rep == 0 ? name : name + "_r" + std::to_string(rep + 1);
347 }
348
349 static std::string unique(std::map<std::string, int>& used, const std::string& base) {
350 const int n = ++used[base];
351 return n == 1 ? base : base + "_d" + std::to_string(n);
352 }
353
354 // -------------------------------------------------------------- refusals
355
356 void refusals() {
357 const lqn::LqnStruct<T>& l = l_;
358 for (std::size_t t = l.tshift + 1; t <= l.tshift + l.ntasks; ++t) {
359 if (t < l.iscache.size() && l.iscache[t])
360 refuse("CacheTask", "cache task " + nm(t) + " has no Petri net image.");
361 if (t < l.hassetup.size() && l.hassetup[t])
362 refuse("SetupTask", "setup or function task " + nm(t) + " is not represented.");
363 }
364 for (std::size_t i = 0; i < l.lincon_A.size(); ++i)
365 if (l.lincon_A[i].rows() > 0) refuse("AdmissionConstraint", "admission constraints are not represented.");
366 bool ld = false;
367 for (std::size_t i = 0; i < l.lldscaling.size(); ++i)
368 if (!l.lldscaling[i].empty()) ld = true;
369 for (std::size_t i = 0; i < l.cdscaling.size(); ++i)
370 if (l.cdscaling[i]) ld = true;
371 for (std::size_t i = 0; i < l.jdscaling.size(); ++i)
372 if (l.jdscaling[i]) ld = true;
373 if (ld) refuse("LoadDependence", "load, class or joint dependence is not represented.");
374 for (std::size_t i = 0; i < l.pools.size(); ++i)
375 if (!l.pools[i].empty()) refuse("ServerPools", "heterogeneous server pools are not represented.");
376 for (std::size_t h = 1; h <= l.nhosts; ++h) {
377 const lang::SchedStrategy s = sched(h);
380 refuse("SchedStrategy", "processor " + nm(h) + " has scheduling " + schedName(s) +
381 "; only FCFS, SIRO, PS and INF are represented.");
382 }
383 for (std::size_t t = l.tshift + 1; t <= l.tshift + l.ntasks; ++t) {
384 const lang::SchedStrategy s = sched(t);
387 refuse("SchedStrategy", "task " + nm(t) + " has scheduling " + schedName(s) +
388 "; only FCFS, SIRO, PS, INF and REF are represented.");
389 }
390 for (std::size_t j = l.ashift + 1; j <= l.ashift + l.nacts; ++j) {
391 if (j >= l.actquorum.size()) continue;
392 const std::size_t q = l.actquorum[j];
393 const std::size_t nb = countAndJoinBranches(j);
394 if (q >= 1 && q < nb)
395 refuse("AndJoinQuorum", "AND-join " + nm(j) + " has quorum " + std::to_string(q) + " of " +
396 std::to_string(nb) + " branches.");
397 }
398
399 for (std::size_t t = l.tshift + 1; t <= l.tshift + l.ntasks; ++t)
400 if (t < l.isref.size() && l.isref[t]) refTasks_.push_back(t);
401 for (std::size_t e = l.eshift + 1; e <= l.eshift + l.nentries; ++e) {
402 if (e >= l.arrival.size() || e >= l.has_arrival.size() || !l.has_arrival[e] || l.arrival[e].disabled)
403 continue;
404 const double m = dbl(l.arrival[e].mean);
405 if (m > tol() && m != std::numeric_limits<double>::infinity()) openEntries_.push_back(e);
406 }
407 if (refTasks_.empty() && openEntries_.empty())
408 throw InputError(ErrorKind{"Model"}, "LQN2PN: the LQN has no reference task and no open arrival.");
409 }
410
411 // ------------------------------------------------------------- call rows
412
413 std::vector<Stage> callStages(std::size_t aidx) {
414 std::vector<Stage> stages;
415 if (aidx >= l_.callsof.size()) return stages;
416 const T one = num_traits<T>::from_int(1);
417 for (std::size_t cidx : l_.callsof[aidx]) {
418 const lang::CallType ct = l_.calltype[cidx];
419 if (ct != lang::CallType::SYNC && ct != lang::CallType::ASYNC) continue;
420 const T m = l_.callproc_mean[cidx];
421 double nfull = std::floor(dbl(m) + tol());
422 T frac = T(m - tnum(nfull));
423 if (nfull > double(MAXCALLSTAGES)) {
424 warn("call multiplicity " + fmtG(dbl(m)) + " truncated to " + std::to_string(MAXCALLSTAGES) +
425 " stages.");
426 nfull = double(MAXCALLSTAGES);
427 frac = num_traits<T>::from_int(0);
428 }
429 const std::size_t target = l_.callpair_dst[cidx];
430 const bool isasync = ct == lang::CallType::ASYNC;
431 for (std::size_t k = 0; k < static_cast<std::size_t>(nfull); ++k) stages.push_back(Stage{target, one, isasync});
432 if (dbl(frac) > tol()) stages.push_back(Stage{target, frac, isasync});
433 }
434 return stages;
435 }
436
437 /** Rows (target entry, probability) of the forwarding calls of an entry. */
438 std::vector<std::pair<std::size_t, T> > forwardingOf(std::size_t eidx) const {
439 std::vector<std::pair<std::size_t, T> > fwd;
440 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
441 for (std::size_t c = 1; c <= l_.ncalls; ++c) {
442 if (l_.calltype[c] != lang::CallType::FWD || l_.callpair_src[c] != eidx) continue;
443 T p = l_.callproc_mean[c];
444 if (dbl(p) < 0.0) p = zero;
445 if (dbl(p) > 1.0) p = one;
446 if (dbl(p) > tol()) fwd.push_back(std::make_pair(l_.callpair_dst[c], p));
447 }
448 return fwd;
449 }
450
451 // ----------------------------------------------------------- replication
452
453 std::size_t fanOutOf(std::size_t a, std::size_t b, std::size_t rb) const {
454 if (rb <= 1) return 1;
455 double f = std::trunc(l_.fanout_at(a, b));
456 if (!(f > 0.0)) {
457 const double ra = replRaw_[a];
458 f = double(rb) > ra ? std::max(1.0, std::floor(double(rb) / ra)) : 1.0;
459 }
460 f = std::min(std::max(1.0, f), double(rb));
461 return static_cast<std::size_t>(f);
462 }
463
464 double taskCost(std::size_t tidx, const std::set<std::size_t>& stack, std::map<std::size_t, double>& memo) const {
465 if (stack.count(tidx)) return 1.0;
466 std::map<std::size_t, double>::const_iterator it = memo.find(tidx);
467 if (it != memo.end()) return it->second;
468 std::set<std::size_t> deeper = stack;
469 deeper.insert(tidx);
470 double total = 1.0;
471 if (tidx < l_.entriesof.size())
472 for (std::size_t eidx : l_.entriesof[tidx]) {
473 std::vector<std::size_t> targets;
474 if (eidx < l_.actsof.size())
475 for (std::size_t a : l_.actsof[eidx])
476 if (a < l_.callsof.size())
477 for (std::size_t c : l_.callsof[a])
479 targets.push_back(l_.callpair_dst[c]);
480 const std::vector<std::pair<std::size_t, T> > fwd = forwardingOf(eidx);
481 for (std::size_t f = 0; f < fwd.size(); ++f) targets.push_back(fwd[f].first);
482 for (std::size_t te : targets) {
483 const std::size_t b = parent(te);
484 total += double(fanOutOf(tidx, b, static_cast<std::size_t>(replRaw_[b]))) *
485 taskCost(b, deeper, memo);
486 }
487 }
488 memo[tidx] = total;
489 return total;
490 }
491
492 double instantiations() const {
493 std::map<std::size_t, double> memo;
494 std::set<std::size_t> seeds(refTasks_.begin(), refTasks_.end());
495 for (std::size_t e : openEntries_) seeds.insert(parent(e));
496 double n = 0.0;
497 for (std::size_t t : seeds) n += replRaw_[t] * taskCost(t, std::set<std::size_t>(), memo);
498 return n;
499 }
500
501 void replication() {
502 const std::size_t NT = l_.nhosts + l_.ntasks;
503 replRaw_.assign(NT + 1, 1.0);
504 std::vector<std::size_t> replicated;
505 for (std::size_t i = 1; i <= NT && i < l_.repl.size(); ++i) {
506 replRaw_[i] = std::max(1.0, std::trunc(l_.repl[i]));
507 if (replRaw_[i] > 1.0) replicated.push_back(i);
508 }
509 materialize_ = !replicated.empty() &&
510 (replication_ == "materialize" ||
511 (replication_ == "auto" && instantiations() <= double(MAXREPLINSTANCES)));
512 if (!replicated.empty() && !materialize_)
513 warn("replication of " + nm(replicated[0]) +
514 " is pooled: its replicas become r times the tokens of one processor, thread pool or "
515 "reference population.");
516 }
517
518 std::size_t nrep(std::size_t idx) const {
519 return materialize_ ? static_cast<std::size_t>(replRaw_[idx]) : 1;
520 }
521 double poolFactor(std::size_t idx) const { return materialize_ ? 1.0 : replRaw_[idx]; }
522
523 std::vector<std::size_t> targetReplicas(std::size_t a, std::size_t arep, std::size_t b) const {
524 const std::size_t rb = nrep(b);
525 if (rb <= 1) return std::vector<std::size_t>(1, 0);
526 const std::size_t f = fanOutOf(a, b, rb);
527 std::vector<std::size_t> out;
528 for (std::size_t k = 0; k < f; ++k) out.push_back((arep * f + k) % rb);
529 return out;
530 }
531
532 Key hostKey(std::size_t tidx, std::size_t trep) const {
533 const std::size_t h = parent(tidx);
534 return Key(h, trep % nrep(h));
535 }
536
537 // ----------------------------------------------------------- net records
538
539 std::size_t newPlace(const std::string& base, bool pinned = false) {
540 places_.push_back(PlaceRec{unique(usedNode_, base), pinned});
541 uf_.push_back(uf_.size());
542 return places_.size() - 1;
543 }
544
545 std::size_t find(std::size_t p) {
546 while (uf_[p] != p) {
547 uf_[p] = uf_[uf_[p]];
548 p = uf_[p];
549 }
550 return p;
551 }
552
553 /** The two places are one position: keep the pinned (named resource) one, else the one created first. */
554 void alias(std::size_t a, std::size_t b) {
555 const std::size_t ra = find(a), rb = find(b);
556 if (ra == rb) return;
557 if (places_[ra].pinned && places_[rb].pinned)
558 throw InternalError(ErrorKind{"Invariant"}, "LQN2PN: internal error, two resource places merged (" +
559 places_[ra].name + ", " + places_[rb].name + ").");
560 const bool keepA = places_[ra].pinned || (!places_[rb].pinned && ra < rb);
561 if (keepA)
562 uf_[rb] = ra;
563 else
564 uf_[ra] = rb;
565 }
566
567 std::size_t newClass(const std::string& base, bool open, double pop, std::size_t ref,
568 const Dist& arrival = Dist::disabled_dist()) {
569 classes_.push_back(ClassRec{unique(usedClass_, base), open, pop, ref, arrival});
570 return classes_.size() - 1;
571 }
572
573 std::size_t newTransition(const std::string& base) {
574 trans_.push_back(TransRec{unique(usedNode_, base), std::vector<Mode>()});
575 return trans_.size() - 1;
576 }
577
578 /** dist == nullptr is an immediate mode; a timed mode is infinite-server. */
579 void addMode(std::size_t ti, const std::vector<Arc>& ins, const std::vector<Arc>& outs, const Dist* dist,
580 const T& weight, bool hasPs = false, Key ps = Key(0, 0)) {
581 TransRec& tr = trans_[ti];
582 Mode md;
583 md.name = tr.modes.empty() ? tr.name : tr.name + "_" + std::to_string(tr.modes.size() + 1);
584 md.ins = ins;
585 md.outs = outs;
586 md.immediate = dist == nullptr;
587 md.dist = dist == nullptr ? Dist::disabled_dist() : *dist;
588 md.weight = weight;
589 md.hasPs = hasPs;
590 md.ps = ps;
591 md.k = 0;
592 tr.modes.push_back(md);
593 }
594
595 /** Token tok at src takes one of the options; a single certain option without side outputs is a merge. */
596 void choice(const std::string& tbase, std::size_t src, std::size_t tok, const std::vector<Opt>& options) {
597 std::vector<Opt> opts;
598 for (const Opt& o : options)
599 if (dbl(o.w) > tol()) opts.push_back(o);
600 if (opts.empty()) return;
601 if (opts.size() == 1 && opts[0].outs.size() == 1 && opts[0].outs[0].cls == tok &&
602 opts[0].outs[0].place != SINK) {
603 alias(src, opts[0].outs[0].place);
604 return;
605 }
606 const std::size_t ti = newTransition(tbase);
607 for (const Opt& o : opts) addMode(ti, std::vector<Arc>(1, Arc(src, tok)), o.outs, nullptr, o.w);
608 }
609
610 // ------------------------------------------------------------- resources
611
612 Res cpuOf(const Key& hkey) {
613 typename std::map<Key, Res>::const_iterator it = cpu_.find(hkey);
614 if (it != cpu_.end()) return it->second;
615 const std::size_t h = hkey.first, m = hkey.second;
616 const double c = imult(h) * poolFactor(h);
617 const std::size_t fr = newPlace(suffixed(nm(h) + "_free", m), true);
618 const std::size_t bz = newPlace(suffixed(nm(h) + "_busy", m), true);
619 const std::size_t cls = newClass(suffixed(nm(h) + "_cpu", m), false, c, fr);
620 marking_.push_back(Marking{fr, cls, c});
621 const Res r{cls, fr, bz, c};
622 cpu_[hkey] = r;
623 return r;
624 }
625
626 bool hasPool(std::size_t tidx) const {
627 return !(tidx < l_.isref.size() && l_.isref[tidx]) && mult(tidx) < 1e9 &&
628 sched(tidx) != lang::SchedStrategy::INF;
629 }
630
631 Res thrOf(const Key& tkey) {
632 std::map<Key, std::size_t>::const_iterator it = thrIdx_.find(tkey);
633 if (it != thrIdx_.end()) return thr_[it->second].second;
634 const std::size_t t = tkey.first, m = tkey.second;
635 const double c = imult(t) * poolFactor(t);
636 const std::size_t fr = newPlace(suffixed(nm(t) + "_free", m), true);
637 const std::size_t bz = newPlace(suffixed(nm(t) + "_busy", m), true);
638 const std::size_t cls = newClass(suffixed(nm(t) + "_thread", m), false, c, fr);
639 marking_.push_back(Marking{fr, cls, c});
640 const Res r{cls, fr, bz, c};
641 thrIdx_[tkey] = thr_.size();
642 thr_.push_back(std::make_pair(tkey, r));
643 return r;
644 }
645
646 std::size_t ph2Of(const Key& tkey, std::size_t refPlace) {
647 std::map<Key, std::size_t>::const_iterator it = ph2cls_.find(tkey);
648 if (it != ph2cls_.end()) return it->second;
649 const std::size_t c = newClass(suffixed(nm(tkey.first) + "_ph2", tkey.second), false, 0.0, refPlace);
650 ph2cls_[tkey] = c;
651 return c;
652 }
653
654 void demandSeg(std::size_t aidx, std::size_t tidx, std::size_t trep, std::size_t tok, std::size_t cur,
655 std::size_t nxt, const Dist& dist) {
656 const T one = num_traits<T>::from_int(1);
657 const Key hkey = hostKey(tidx, trep);
658 const std::size_t h = hkey.first;
659 const lang::SchedStrategy s = sched(h);
660 const std::string aname = suffixed(nm(aidx), trep);
661 if (mult(h) >= 1e9 || s == lang::SchedStrategy::INF) {
662 const std::size_t ti = newTransition(aname + "_run");
663 addMode(ti, std::vector<Arc>(1, Arc(cur, tok)), std::vector<Arc>(1, Arc(nxt, tok)), &dist, one);
664 runPos_[hkey].push_back(std::make_pair(cur, tok));
665 } else if (s == lang::SchedStrategy::PS) {
666 if (!psPhaseType(dist.type) || dist.D0.rows() == 0 || dist.D1.rows() != dist.D0.rows())
667 refuse("PSNonPhaseType", "activity " + nm(aidx) + " has a " + lang::process_to_text(dist.type) +
668 " host demand on PS processor " + nm(h) +
669 "; only phase-type demands (Exp, Erlang, HyperExp, PH, APH, Coxian, "
670 "Cox2) have an exact image in the net, fit one first (e.g. "
671 "APH.fitMeanAndSCV).");
672 const Matrix<T>& S = dist.D0;
673 const Matrix<T>& D1 = dist.D1;
674 const std::size_t K = S.rows();
675 std::vector<std::size_t>& pm = psModes_[hkey];
676 psPos_[hkey];
677 if (K == 1) {
678 // One phase: the run mode itself, scaled by min(1, c/n).
679 const Dist d1 = dist.type == lang::ProcessType::EXP ? dist : Dist::exp_rate(-S(0, 0));
680 const std::size_t ti = newTransition(aname + "_run");
681 addMode(ti, std::vector<Arc>(1, Arc(cur, tok)), std::vector<Arc>(1, Arc(nxt, tok)), &d1, one, true,
682 hkey);
683 psPos_[hkey].push_back(std::make_pair(cur, tok));
684 pm.push_back(ti);
685 runPos_[hkey].push_back(std::make_pair(cur, tok));
686 return;
687 }
688 // Phase-type demand (alpha, S): one place per phase, entered by alpha
689 // through immediate modes, and one exponential mode per phase move and
690 // per exit, each scaled by min(1, c/n) with n counted over every phase
691 // place of the processor. Each job's phase then advances at rate
692 // S(j,k)*min(1,c/n), which is the PS queue with phase-type service.
693 // A renewal PH has D1 = s alpha, so alpha is the row of D1 with the
694 // largest exit rate s_j, divided by s_j.
695 std::vector<T> ext(K, num_traits<T>::from_int(0));
696 std::size_t jmax = 0;
697 for (std::size_t j = 0; j < K; ++j) {
698 for (std::size_t k = 0; k < K; ++k) ext[j] = ext[j] - S(j, k);
699 if (dbl(ext[j]) > dbl(ext[jmax])) jmax = j;
700 }
701 std::vector<std::size_t> ph(K);
702 for (std::size_t k = 0; k < K; ++k) ph[k] = newPlace(aname + "_ph" + std::to_string(k + 1));
703 std::vector<Opt> opts;
704 double asum = 0.0;
705 for (std::size_t k = 0; k < K; ++k) {
706 const T a = D1(jmax, k) / ext[jmax];
707 asum += dbl(a);
708 opts.push_back(Opt{a, std::vector<Arc>(1, Arc(ph[k], tok))});
709 }
710 if (1.0 - asum > tol())
711 opts.push_back(Opt{one - num_traits<T>::from_double(asum), std::vector<Arc>(1, Arc(nxt, tok))});
712 choice(aname + "_start", cur, tok, opts);
713 for (std::size_t j = 0; j < K; ++j) {
714 const std::size_t ti = newTransition(aname + "_run" + std::to_string(j + 1));
715 for (std::size_t k = 0; k < K; ++k) {
716 if (k != j && dbl(S(j, k)) > tol()) {
717 const Dist dk = Dist::exp_rate(S(j, k));
718 addMode(ti, std::vector<Arc>(1, Arc(ph[j], tok)), std::vector<Arc>(1, Arc(ph[k], tok)), &dk,
719 one, true, hkey);
720 }
721 }
722 if (dbl(ext[j]) > tol()) {
723 const Dist dx = Dist::exp_rate(ext[j]);
724 addMode(ti, std::vector<Arc>(1, Arc(ph[j], tok)), std::vector<Arc>(1, Arc(nxt, tok)), &dx, one,
725 true, hkey);
726 }
727 pm.push_back(ti);
728 }
729 for (std::size_t k = 0; k < K; ++k) {
730 psPos_[hkey].push_back(std::make_pair(ph[k], tok));
731 runPos_[hkey].push_back(std::make_pair(ph[k], tok));
732 }
733 } else {
734 const Res r = cpuOf(hkey);
735 const std::size_t srv = newPlace(aname + "_srv");
736 const std::size_t tg = newTransition(aname + "_get");
737 std::vector<Arc> gi, go;
738 gi.push_back(Arc(cur, tok));
739 gi.push_back(Arc(r.free, r.cls));
740 go.push_back(Arc(srv, tok));
741 go.push_back(Arc(r.busy, r.cls));
742 addMode(tg, gi, go, nullptr, one);
743 const std::size_t tr = newTransition(aname + "_run");
744 std::vector<Arc> ri, ro;
745 ri.push_back(Arc(srv, tok));
746 ri.push_back(Arc(r.busy, r.cls));
747 ro.push_back(Arc(nxt, tok));
748 ro.push_back(Arc(r.free, r.cls));
749 addMode(tr, ri, ro, &dist, one);
750 }
751 }
752
753 // ---------------------------------------------------------- entry copies
754
755 /**
756 * Copy of the subgraph of entry eidx (replica trep of its task) walked by token class tok, which goes to
757 * ret at the reply: a place, SINK, or NOPL to destroy it. Returns the request place, or NOPL.
758 */
759 std::size_t expandEntry(std::size_t eidx, std::size_t trep, std::size_t tok, std::size_t ret) {
760 const Key key(eidx, trep);
761 if (std::find(entryStack_.begin(), entryStack_.end(), key) != entryStack_.end()) {
762 warn("recursive call cycle at entry " + nm(eidx) + " truncated.");
763 return NOPL;
764 }
765 Ctx c;
766 if (eidx < l_.actsof.size()) c.localActs = l_.actsof[eidx];
767 std::size_t bound = NOPL;
768 for (std::size_t a : c.localActs)
769 if (dbl(l_.graph.get(eidx, a)) != 0.0) {
770 bound = a;
771 break;
772 }
773 if (bound == NOPL) return NOPL;
774 entryStack_.push_back(key);
775 c.eidx = eidx;
776 c.trep = trep;
777 c.tok = tok;
778 c.ret = ret;
779 c.tidx = parent(eidx);
780 c.tkey = Key(c.tidx, trep);
781 c.ename = suffixed(nm(eidx), trep);
782 c.fwdDone = false;
783 const std::size_t req = newPlace(c.ename + "_req");
784 entryMap_.add(trep == 0 ? nm(eidx) : c.ename, req, tok);
785 c.pool = hasPool(c.tidx);
786 if (c.pool) c.poolRes = thrOf(c.tkey);
787 const std::size_t start = walk(c, bound, 1, NOPL);
788 if (c.pool) {
789 const std::size_t ti = newTransition(c.ename + "_acq");
790 std::vector<Arc> ins, outs;
791 ins.push_back(Arc(req, tok));
792 ins.push_back(Arc(c.poolRes.free, c.poolRes.cls));
793 outs.push_back(Arc(start, tok));
794 outs.push_back(Arc(c.poolRes.busy, c.poolRes.cls));
795 addMode(ti, ins, outs, nullptr, num_traits<T>::from_int(1));
796 } else {
797 alias(req, start);
798 }
799 entryStack_.pop_back();
800 return req;
801 }
802
803 bool repliesHere(const Ctx& c, std::size_t aidx) const { return replies_.count(Key(aidx, c.eidx)) > 0; }
804
805 std::size_t tokOf(Ctx& c, int phase, std::size_t refPlace) {
806 if (phase == 1) return c.tok;
807 return c.pool ? c.poolRes.cls : ph2Of(c.tkey, refPlace);
808 }
809
810 const std::vector<std::pair<T, std::size_t> >& forwards(Ctx& c) {
811 if (!c.fwdDone) {
812 std::vector<std::pair<T, std::size_t> > opts;
813 const std::vector<std::pair<std::size_t, T> > rows = forwardingOf(c.eidx);
814 for (std::size_t i = 0; i < rows.size(); ++i) {
815 const std::size_t target = rows[i].first;
816 const std::vector<std::size_t> reps = targetReplicas(c.tidx, c.trep, parent(target));
817 for (std::size_t m : reps) {
818 const std::size_t r2 = expandEntry(target, m, c.tok, c.ret);
819 if (r2 != NOPL) opts.push_back(std::make_pair(T(rows[i].second / tnum(double(reps.size()))), r2));
820 }
821 }
822 c.fwd = opts;
823 c.fwdDone = true;
824 }
825 return c.fwd;
826 }
827
828 /** Reply of the token at x; d2 is the phase-2 place, or NOPL. */
829 void emitReply(Ctx& c, const std::string& aname, std::size_t x, std::size_t d2) {
830 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
831 std::vector<Arc> ins(1, Arc(x, c.tok));
832 std::vector<Arc> tail;
833 if (c.pool) {
834 ins.push_back(Arc(c.poolRes.busy, c.poolRes.cls));
835 tail.push_back(Arc(d2 != NOPL ? d2 : c.poolRes.free, c.poolRes.cls));
836 } else if (d2 != NOPL) {
837 tail.push_back(Arc(d2, ph2Of(c.tkey, d2)));
838 }
839 const std::vector<std::pair<T, std::size_t> > fw = forwards(c);
840 T pf = zero;
841 for (std::size_t i = 0; i < fw.size(); ++i) pf = T(pf + fw[i].first);
842 std::vector<Opt> own;
843 {
844 T w0 = T(one - pf);
845 if (dbl(w0) < 0.0) w0 = zero;
846 Opt o;
847 o.w = w0;
848 if (c.ret != NOPL) o.outs.push_back(Arc(c.ret, c.tok));
849 o.outs.insert(o.outs.end(), tail.begin(), tail.end());
850 own.push_back(o);
851 }
852 for (std::size_t i = 0; i < fw.size(); ++i) {
853 Opt o;
854 o.w = fw[i].first;
855 o.outs.push_back(Arc(fw[i].second, c.tok));
856 o.outs.insert(o.outs.end(), tail.begin(), tail.end());
857 own.push_back(o);
858 }
859 std::vector<Opt> kept;
860 for (const Opt& o : own)
861 if (dbl(o.w) > tol()) kept.push_back(o);
862 if (kept.size() == 1 && ins.size() == 1 && c.ret != NOPL && c.ret != SINK && tail.empty()) {
863 alias(x, c.ret);
864 return;
865 }
866 const std::size_t ti = newTransition(aname + "_reply");
867 for (const Opt& o : kept) addMode(ti, ins, o.outs, nullptr, o.w);
868 }
869
870 void emitEnd(Ctx& c, const std::string& aname, std::size_t x, std::size_t phaseTok) {
871 if (c.pool) {
872 alias(x, c.poolRes.free);
873 } else {
874 const std::size_t ti = newTransition(aname + "_end");
875 addMode(ti, std::vector<Arc>(1, Arc(x, phaseTok)), std::vector<Arc>(), nullptr,
877 }
878 }
879
880 void body(Ctx& c, std::size_t aidx, std::size_t t, std::size_t cur, std::size_t out) {
881 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
882 const std::string aname = suffixed(nm(aidx), c.trep);
883 std::vector<Seg> segs;
884 if (aidx < l_.hostdem.size() && timed(l_.hostdem[aidx])) {
885 Seg s;
886 s.kind = 0;
887 s.d = l_.hostdem[aidx];
888 s.k = 0;
889 segs.push_back(s);
890 }
891 if (aidx < l_.actthink.size() && timed(l_.actthink[aidx])) {
892 Seg s;
893 s.kind = 1;
894 s.d = l_.actthink[aidx];
895 s.k = 0;
896 segs.push_back(s);
897 }
898 const std::vector<Stage> stages = callStages(aidx);
899 for (std::size_t k = 0; k < stages.size(); ++k) {
900 Seg s;
901 s.kind = 2;
902 s.k = k + 1;
903 s.st = stages[k];
904 segs.push_back(s);
905 }
906 if (segs.empty()) {
907 alias(cur, out);
908 return;
909 }
910 for (std::size_t i = 0; i < segs.size(); ++i) {
911 const Seg& sg = segs[i];
912 const std::size_t nxt = i + 1 == segs.size() ? out : newPlace(aname + "_s" + std::to_string(i + 1));
913 if (sg.kind == 0) {
914 demandSeg(aidx, c.tidx, c.trep, t, cur, nxt, sg.d);
915 } else if (sg.kind == 1) {
916 const std::size_t ti = newTransition(aname + "_think");
917 addMode(ti, std::vector<Arc>(1, Arc(cur, t)), std::vector<Arc>(1, Arc(nxt, t)), &sg.d, one);
918 } else {
919 const std::string ks = std::to_string(sg.k);
920 const std::size_t target = sg.st.target;
921 const std::vector<std::size_t> reps = targetReplicas(c.tidx, c.trep, parent(target));
922 const T share = T(sg.st.prob / tnum(double(reps.size())));
923 std::vector<Opt> opts;
924 for (std::size_t m : reps) {
925 if (sg.st.isasync) {
926 const std::size_t acls = newClass(aname + "_async" + ks, false, 0.0, NOPL);
927 const std::size_t r2 = expandEntry(target, m, acls, NOPL);
928 if (r2 == NOPL) {
929 classes_[acls].ref = nxt;
930 continue;
931 }
932 classes_[acls].ref = r2;
933 Opt o;
934 o.w = share;
935 o.outs.push_back(Arc(nxt, t));
936 o.outs.push_back(Arc(r2, acls));
937 opts.push_back(o);
938 } else {
939 const std::size_t r2 = expandEntry(target, m, t, nxt);
940 if (r2 == NOPL) continue;
941 Opt o;
942 o.w = share;
943 o.outs.push_back(Arc(r2, t));
944 opts.push_back(o);
945 }
946 }
947 if (opts.empty()) {
948 alias(cur, nxt);
949 } else {
950 T sum = zero;
951 for (const Opt& o : opts) sum = T(sum + o.w);
952 const T pin = T(one - sum);
953 if (dbl(pin) > tol()) {
954 Opt o;
955 o.w = pin;
956 o.outs.push_back(Arc(nxt, t));
957 opts.push_back(o);
958 }
959 choice(aname + "_call" + ks, cur, t, opts);
960 }
961 }
962 cur = nxt;
963 }
964 }
965
966 std::vector<std::size_t> localSucc(const Ctx& c, std::size_t aidx) const {
967 std::vector<std::size_t> out;
968 for (std::size_t s : c.localActs)
969 if (dbl(l_.graph.get(aidx, s)) != 0.0) out.push_back(s);
970 return out;
971 }
972
973 std::size_t walk(Ctx& c, std::size_t aidx, int phase, std::size_t refPlace) {
974 const std::pair<std::size_t, int> k(aidx, phase);
975 std::map<std::pair<std::size_t, int>, std::size_t>::const_iterator vit = c.visited.find(k);
976 if (vit != c.visited.end()) return vit->second;
977 const std::string aname = suffixed(nm(aidx), c.trep);
978 const std::size_t inP = newPlace(aname);
979 c.visited[k] = inP;
980 const std::size_t t = tokOf(c, phase, refPlace == NOPL ? inP : refPlace);
981 actMap_.add(c.trep == 0 ? nm(aidx) : aname, inP, t);
982 const std::size_t out = newPlace(aname + "_out");
983 body(c, aidx, t, inP, out);
984 const std::vector<std::size_t> succ = localSucc(c, aidx);
985 if (phase == 1 && (repliesHere(c, aidx) || succ.empty())) {
986 if (!c.forkStack.empty() && succ.empty())
987 refuse("Structure", "activity " + nm(aidx) + " ends an AND-fork branch without an AND-join.");
988 if (!succ.empty()) {
989 const std::size_t d2 = newPlace(aname + "_ph2");
990 emitReply(c, aname, out, d2);
991 dispatch(c, aidx, succ, d2, 2);
992 } else {
993 emitReply(c, aname, out, NOPL);
994 }
995 return inP;
996 }
997 if (succ.empty()) {
998 if (!c.forkStack.empty())
999 refuse("Structure", "activity " + nm(aidx) + " ends an AND-fork branch without an AND-join.");
1000 emitEnd(c, aname, out, t);
1001 return inP;
1002 }
1003 dispatch(c, aidx, succ, out, phase);
1004 return inP;
1005 }
1006
1007 std::size_t joinIndex(const Ctx& c, std::size_t j) const {
1008 for (std::size_t i = 0; i < c.joins.size(); ++i)
1009 if (c.joins[i].j == j) return i;
1010 return NOPL;
1011 }
1012
1013 void dispatch(Ctx& c, std::size_t aidx, const std::vector<std::size_t>& succ, std::size_t d, int phase) {
1014 const T one = num_traits<T>::from_int(1);
1015 const std::string aname = suffixed(nm(aidx), c.trep);
1016 const std::size_t t = tokOf(c, phase, d);
1017 if (isAndJoinPre(aidx)) {
1018 const std::size_t j = succ[0];
1019 if (c.forkStack.empty()) {
1020 warn("AND-join at " + nm(j) + " has no enclosing AND-fork; branches are serialised.");
1021 alias(d, walk(c, j, phase, NOPL));
1022 return;
1023 }
1024 std::size_t ri = joinIndex(c, j);
1025 if (ri == NOPL) {
1026 c.joins.push_back(JoinRec{j, c.forkStack.back(), std::vector<JoinIn>(), false});
1027 ri = c.joins.size() - 1;
1028 } else if (c.joins[ri].owner != c.forkStack.back()) {
1029 refuse("Structure", "AND-join at " + nm(j) + " merges branches of different AND-forks.");
1030 }
1031 std::size_t place = NOPL;
1032 for (const JoinIn& in : c.joins[ri].inputs)
1033 if (in.aidx == aidx) place = in.place;
1034 if (place == NOPL) {
1035 place = newPlace(suffixed(nm(j), c.trep) + "_join" + std::to_string(c.joins[ri].inputs.size() + 1));
1036 c.joins[ri].inputs.push_back(JoinIn{aidx, place, t, phase});
1037 }
1038 alias(d, place);
1039 return;
1040 }
1041 if (isAndFork(succ)) {
1042 c.forkStack.push_back(aidx);
1043 std::vector<Arc> outs;
1044 for (std::size_t s : succ) outs.push_back(Arc(walk(c, s, phase, d), t));
1045 c.forkStack.pop_back();
1046 const std::size_t ti = newTransition(aname + "_fork");
1047 addMode(ti, std::vector<Arc>(1, Arc(d, t)), outs, nullptr, one);
1048 std::vector<std::size_t> owned;
1049 for (const JoinRec& r : c.joins)
1050 if (r.owner == aidx && !r.done) owned.push_back(r.j);
1051 for (std::size_t j : owned) finishJoin(c, j);
1052 return;
1053 }
1054 std::vector<std::pair<T, std::size_t> > opts;
1055 for (std::size_t s : succ) {
1056 const T w = l_.graph.get(aidx, s);
1057 if (dbl(w) > 0.0) opts.push_back(std::make_pair(w, s));
1058 }
1059 if (opts.size() == 1) {
1060 alias(d, walk(c, opts[0].second, phase, d));
1061 return;
1062 }
1063 const std::size_t ti = newTransition(aname + "_or");
1064 for (std::size_t i = 0; i < opts.size(); ++i) {
1065 const std::size_t p = walk(c, opts[i].second, phase, d);
1066 addMode(ti, std::vector<Arc>(1, Arc(d, t)), std::vector<Arc>(1, Arc(p, t)), nullptr, opts[i].first);
1067 }
1068 }
1069
1070 void finishJoin(Ctx& c, std::size_t j) {
1071 const std::size_t ri = joinIndex(c, j);
1072 c.joins[ri].done = true;
1073 const std::size_t nb = countAndJoinBranches(j);
1074 const std::vector<JoinIn> inputs = c.joins[ri].inputs;
1075 if (inputs.size() != nb)
1076 refuse("Structure", "AND-join at " + nm(j) + " is reached by " + std::to_string(inputs.size()) +
1077 " of its " + std::to_string(nb) + " branches.");
1078 std::vector<Arc> ins;
1079 std::size_t n2 = 0;
1080 for (const JoinIn& in : inputs) {
1081 ins.push_back(Arc(in.place, in.cls));
1082 if (in.phase == 2) ++n2;
1083 }
1084 if (n2 > 1)
1085 refuse("Structure", "more than one branch of the AND-fork closed at " + nm(j) + " replies.");
1086 const int phase = n2 > 0 ? 2 : 1;
1087 std::size_t ref = NOPL;
1088 for (const JoinIn& in : inputs)
1089 if (in.phase == phase) {
1090 ref = in.place;
1091 break;
1092 }
1093 const std::size_t inJ = walk(c, j, phase, ref);
1094 const std::size_t ti = newTransition(suffixed(nm(j), c.trep) + "_join");
1095 const std::size_t tk = tokOf(c, phase, ref);
1096 addMode(ti, ins, std::vector<Arc>(1, Arc(inJ, tk)), nullptr, num_traits<T>::from_int(1));
1097 }
1098
1099 // ------------------------------------------------- reference tasks, open
1100
1101 void build() {
1102 const T one = num_traits<T>::from_int(1);
1103 for (std::size_t refT : refTasks_) {
1104 for (std::size_t rep = 0; rep < nrep(refT); ++rep) {
1105 const std::string tn = suffixed(nm(refT), rep);
1106 const std::size_t tp = newPlace(tn + "_think", true);
1107 const double pop = imult(refT) * poolFactor(refT);
1108 const std::size_t cls = newClass(tn, false, pop, tp);
1109 marking_.push_back(Marking{tp, cls, pop});
1110 thinkPlace_.push_back(std::make_pair(Key(refT, rep), tp));
1111 std::vector<std::size_t> reqs;
1112 if (refT < l_.entriesof.size())
1113 for (std::size_t eidx : l_.entriesof[refT]) {
1114 const std::size_t r = expandEntry(eidx, rep, cls, tp);
1115 if (r != NOPL) reqs.push_back(r);
1116 }
1117 if (reqs.empty()) continue;
1118 std::size_t post = tp;
1119 if (refT < l_.think.size() && timed(l_.think[refT])) {
1120 post = newPlace(tn + "_ready");
1121 const std::size_t tt = newTransition(tn + "_thinking");
1122 addMode(tt, std::vector<Arc>(1, Arc(tp, cls)), std::vector<Arc>(1, Arc(post, cls)), &l_.think[refT],
1123 one);
1124 }
1125 if (reqs.size() == 1) {
1126 alias(post, reqs[0]);
1127 } else {
1128 const std::size_t tc = newTransition(tn + "_entry");
1129 for (std::size_t r : reqs)
1130 addMode(tc, std::vector<Arc>(1, Arc(post, cls)), std::vector<Arc>(1, Arc(r, cls)), nullptr, one);
1131 }
1132 }
1133 }
1134
1135 for (std::size_t eidx : openEntries_) {
1136 for (std::size_t rep = 0; rep < nrep(parent(eidx)); ++rep) {
1137 const std::size_t cls = newClass(suffixed(nm(eidx) + "_arrival", rep), true, 0.0, NOPL, l_.arrival[eidx]);
1138 const std::size_t r = expandEntry(eidx, rep, cls, SINK);
1139 if (r == NOPL) {
1140 warn("open arrival entry " + nm(eidx) + " has no bound activity; ignored.");
1141 continue;
1142 }
1143 classes_[cls].ref = r;
1144 openSrc_.push_back(std::make_pair(cls, r));
1145 }
1146 }
1147
1148 // PS run modes read the jobs at every run place of their processor through never-binding inhibitor arcs,
1149 // so the rate function sees them in all codebases.
1150 // 1e9, not MaxInt: the JAR's Matrix.set(int) reads Integer.MAX_VALUE as +Inf, so a MaxInt threshold is
1151 // "no arc" there and the net reloaded from JSON loses its reads.
1152 const double big = 1e9;
1153 for (std::size_t ti = 0; ti < trans_.size(); ++ti)
1154 for (std::size_t mi = 0; mi < trans_[ti].modes.size(); ++mi) {
1155 Mode& md = trans_[ti].modes[mi];
1156 if (!md.hasPs) continue;
1157 const std::size_t ownP = find(md.ins[0].place), ownC = md.ins[0].cls;
1158 md.inh.clear();
1159 const std::vector<std::pair<std::size_t, std::size_t> >& cells = psPos_[md.ps];
1160 for (std::size_t q = 0; q < cells.size(); ++q)
1161 if (!(find(cells[q].first) == ownP && cells[q].second == ownC))
1162 md.inh.push_back(Arc(cells[q].first, cells[q].second, big));
1163 }
1164 }
1165
1166 // -------------------------------------------------------------- emission
1167
1168 std::string placeName(std::size_t p) { return p == SINK ? std::string("Sink") : places_[find(p)].name; }
1169
1170 std::vector<Lqn2PnCell> cellsOf(const std::vector<std::pair<std::size_t, std::size_t> >& lst) {
1171 std::vector<Lqn2PnCell> out;
1172 for (std::size_t i = 0; i < lst.size(); ++i) {
1173 Lqn2PnCell cell{placeName(lst[i].first), classes_[lst[i].second].name};
1174 bool seen = false;
1175 for (const Lqn2PnCell& o : out)
1176 if (o.place == cell.place && o.cls == cell.cls) seen = true;
1177 if (!seen) out.push_back(cell);
1178 }
1179 return out;
1180 }
1181
1182 qn::Network<T> emit() {
1183 const T zero = num_traits<T>::from_int(0), one = num_traits<T>::from_int(1);
1184 qn::Network<T> net(name_ + "-PN");
1185 std::set<std::size_t> used;
1186 bool needsSink = false;
1187 for (std::size_t ti = 0; ti < trans_.size(); ++ti)
1188 for (const Mode& md : trans_[ti].modes) {
1189 for (const Arc& a : md.ins)
1190 if (a.place != SINK) used.insert(find(a.place));
1191 for (const Arc& a : md.outs) {
1192 if (a.place != SINK)
1193 used.insert(find(a.place));
1194 else
1195 needsSink = true;
1196 }
1197 for (const Arc& a : md.inh)
1198 if (a.place != SINK) used.insert(find(a.place));
1199 }
1200 for (const ClassRec& c : classes_)
1201 if (c.ref != NOPL) used.insert(find(c.ref));
1202 for (const Marking& m : marking_) used.insert(find(m.place));
1203
1204 const std::size_t src = openSrc_.empty() ? 0 : net.add_source("Source");
1205 const std::size_t snk = (needsSink || !openSrc_.empty()) ? net.add_sink("Sink") : 0;
1206 std::map<std::size_t, std::size_t> pnode;
1207 for (std::size_t p : used) pnode[p] = net.add_place(places_[p].name);
1208 std::vector<std::size_t> tnode(trans_.size(), 0);
1209 for (std::size_t ti = 0; ti < trans_.size(); ++ti)
1210 if (!trans_[ti].modes.empty()) tnode[ti] = net.add_transition(trans_[ti].name);
1211
1212 std::vector<std::size_t> cobj;
1213 for (const ClassRec& c : classes_) {
1214 if (c.open) {
1215 const std::size_t k = net.add_open_class(c.name, 0);
1216 net.set_arrival(src, k, c.arrival);
1217 cobj.push_back(k);
1218 } else {
1219 if (c.ref == NOPL)
1220 throw InternalError(ErrorKind{"Invariant"},
1221 "LQN2PN: internal error, closed class " + c.name + " has no reference place.");
1222 cobj.push_back(net.add_closed_class(c.name, std::trunc(c.pop), nodeOf(pnode, snk, c.ref), 0));
1223 }
1224 }
1225
1227 for (std::size_t ti = 0; ti < trans_.size(); ++ti) {
1228 if (trans_[ti].modes.empty()) continue;
1229 const std::size_t tr = tnode[ti];
1230 for (Mode& md : trans_[ti].modes) {
1231 const std::size_t k = net.add_mode(tr, md.name);
1232 if (md.immediate) {
1234 net.set_firing_weight(tr, k, md.weight);
1235 } else {
1236 net.set_mode_distribution(tr, k, md.dist);
1238 }
1239 for (const Arc& a : md.ins) {
1240 const std::size_t pn = nodeOf(pnode, snk, a.place);
1241 net.set_enabling_conditions(tr, k, cobj[a.cls], pn, tnum(a.n));
1242 R.set(cobj[a.cls], cobj[a.cls], pn, tr, one);
1243 }
1244 for (const Arc& a : md.outs) {
1245 const std::size_t pn = nodeOf(pnode, snk, a.place);
1246 net.set_firing_outcome(tr, k, cobj[a.cls], pn, tnum(a.n));
1247 R.set(cobj[a.cls], cobj[a.cls], tr, pn, one);
1248 }
1249 for (const Arc& a : md.inh)
1250 net.set_inhibiting_conditions(tr, k, cobj[a.cls], nodeOf(pnode, snk, a.place), tnum(a.n));
1251 md.k = k;
1252 }
1253 }
1254 for (std::size_t i = 0; i < openSrc_.size(); ++i)
1255 R.set(cobj[openSrc_[i].first], cobj[openSrc_[i].first], src, nodeOf(pnode, snk, openSrc_[i].second), one);
1256 net.link(R);
1257
1258 // Rate functions need node and class indices, fixed once the net is linked.
1259 const std::size_t K = net.raw_struct().classes.size();
1260 for (typename std::map<Key, std::vector<std::size_t> >::const_iterator it = psModes_.begin();
1261 it != psModes_.end(); ++it) {
1262 if (cpu_.count(it->first)) continue;
1263 const std::size_t h = it->first.first;
1264 const double cap = imult(h) * poolFactor(h);
1265 std::set<std::pair<std::size_t, std::size_t> > cells;
1266 const std::vector<std::pair<std::size_t, std::size_t> >& pos = psPos_[it->first];
1267 for (std::size_t q = 0; q < pos.size(); ++q)
1268 cells.insert(std::make_pair(nodeOf(pnode, snk, pos[q].first), cobj[pos[q].second]));
1269 std::vector<std::size_t> flat;
1270 for (const std::pair<std::size_t, std::size_t>& ce : cells) flat.push_back((ce.first - 1) * K + (ce.second - 1));
1271 const std::function<T(const std::vector<T>&)> g = [flat, cap](const std::vector<T>& mk) -> T {
1272 T n = num_traits<T>::from_int(0);
1273 for (std::size_t q = 0; q < flat.size(); ++q) n = T(n + mk[flat[q]]);
1274 if (num_traits<T>::to_double(n) <= cap) return num_traits<T>::from_int(1);
1275 return T(num_traits<T>::from_double(cap) / n);
1276 };
1277 for (std::size_t ti : it->second)
1278 for (const Mode& md : trans_[ti].modes) net.set_mode_firing_dependence(tnode[ti], md.k, g);
1279 }
1280
1281 for (std::map<std::size_t, std::size_t>::const_iterator it = pnode.begin(); it != pnode.end(); ++it) {
1282 std::vector<T> st(K, zero);
1283 for (const Marking& m : marking_)
1284 if (find(m.place) == it->first) st[cobj[m.cls] - 1] = T(st[cobj[m.cls] - 1] + tnum(std::trunc(m.v)));
1285 net.set_initial_marking(it->second, st);
1286 }
1287
1288 if (map_ != nullptr) fillMap();
1289 return net;
1290 }
1291
1292 std::size_t nodeOf(const std::map<std::size_t, std::size_t>& pnode, std::size_t snk, std::size_t p) {
1293 if (p == SINK) return snk;
1294 return pnode.at(find(p));
1295 }
1296
1297 void fillMap() {
1298 Lqn2PnMap& mp = *map_;
1299 mp = Lqn2PnMap();
1300 for (std::size_t h = 1; h <= l_.nhosts; ++h)
1301 for (std::size_t m = 0; m < nrep(h); ++m) {
1302 const Key hkey(h, m);
1303 Lqn2PnProcessor pr;
1304 pr.name = suffixed(nm(h), m);
1305 pr.sched = schedName(sched(h));
1306 typename std::map<Key, Res>::const_iterator ci = cpu_.find(hkey);
1307 if (ci != cpu_.end()) {
1308 pr.mult = ci->second.mult;
1309 pr.busy.push_back(Lqn2PnCell{placeName(ci->second.busy), classes_[ci->second.cls].name});
1310 mp.processors.push_back(pr);
1311 } else if (runPos_.count(hkey)) {
1312 const double mm = mult(h) * poolFactor(h);
1313 pr.mult = mm >= 1e9 ? std::numeric_limits<double>::infinity() : mm;
1314 pr.run = cellsOf(runPos_[hkey]);
1315 mp.processors.push_back(pr);
1316 }
1317 }
1318 std::map<std::string, std::size_t> tpos;
1319 for (std::size_t i = 0; i < thr_.size(); ++i) {
1320 const Key& tk = thr_[i].first;
1321 const Res& r = thr_[i].second;
1322 Lqn2PnTask tsk;
1323 tsk.name = suffixed(nm(tk.first), tk.second);
1324 tsk.mult = r.mult;
1325 tsk.has_pool = true;
1326 tsk.free = Lqn2PnCell{placeName(r.free), classes_[r.cls].name};
1327 tsk.busy = Lqn2PnCell{placeName(r.busy), classes_[r.cls].name};
1328 upsertTask(mp, tpos, tsk);
1329 }
1330 for (std::size_t i = 0; i < thinkPlace_.size(); ++i) {
1331 const std::size_t t = thinkPlace_[i].first.first, m = thinkPlace_[i].first.second;
1332 Lqn2PnTask tsk;
1333 tsk.name = suffixed(nm(t), m);
1334 tsk.mult = imult(t) * poolFactor(t);
1335 tsk.is_ref = true;
1336 tsk.think = Lqn2PnCell{placeName(thinkPlace_[i].second), suffixed(nm(t), m)};
1337 upsertTask(mp, tpos, tsk);
1338 }
1339 for (std::size_t i = 0; i < entryMap_.rows.size(); ++i)
1340 mp.entries.push_back(Lqn2PnElement{entryMap_.rows[i].first, cellsOf(entryMap_.rows[i].second)});
1341 for (std::size_t i = 0; i < actMap_.rows.size(); ++i)
1342 mp.activities.push_back(Lqn2PnElement{actMap_.rows[i].first, cellsOf(actMap_.rows[i].second)});
1343 }
1344
1345 /** A dict assignment: a repeated key keeps its position and takes the new value. */
1346 static void upsertTask(Lqn2PnMap& mp, std::map<std::string, std::size_t>& tpos, const Lqn2PnTask& tsk) {
1347 std::map<std::string, std::size_t>::const_iterator it = tpos.find(tsk.name);
1348 if (it == tpos.end()) {
1349 tpos[tsk.name] = mp.tasks.size();
1350 mp.tasks.push_back(tsk);
1351 } else {
1352 mp.tasks[it->second] = tsk;
1353 }
1354 }
1355};
1356
1357} // namespace detail
1358
1359/**
1360 * Port of Python `LQN2PN(lqn, replication, return_map)` and MATLAB `LQN2PN`: convert a layered network into a
1361 * Petri net (Place and Transition nodes, a GSPN) that keeps every layer at once.
1362 *
1363 * @param lqn the layered model, from lqn::LqnBuilder::model() or lqn::read_lqnx_model
1364 * @param replication 'auto' (default), 'materialize' or 'pool', as in LQN2QN
1365 * @param name the layered model's name; the network is called `<name>-PN`
1366 * @param warnings when non-null, the warnings are appended here instead of being printed to stderr
1367 * @param map when non-null, filled with the places and classes to read each LQN element from
1368 * @return the Petri net, routed, with its initial marking set
1369 */
1370template <class T>
1371qn::Network<T> lqn2pn(const lqn::LqnModel<T>& lqn, const std::string& replication = "auto",
1372 const std::string& name = "model", std::vector<std::string>* warnings = nullptr,
1373 Lqn2PnMap* map = nullptr) {
1375 const std::set<std::pair<std::size_t, std::size_t> > replies = detail::lqn2qn_replies(lqn, l);
1376 detail::Lqn2Pn<T> conv(l, replies, replication, name, warnings, map);
1377 return conv.run();
1378}
1379
1380/**
1381 * LQN2PN over an already flattened LqnStruct.
1382 *
1383 * The struct carries no replygraph, so only the IMPLICIT replies (leaf activities) are known here; a model with
1384 * an explicit reply on a non-leaf activity (phase 2) must use the LqnModel overload.
1385 */
1386template <class T>
1387qn::Network<T> lqn2pn(const lqn::LqnStruct<T>& lsn, const std::string& replication = "auto",
1388 const std::string& name = "model", std::vector<std::string>* warnings = nullptr,
1389 Lqn2PnMap* map = nullptr) {
1390 const std::set<std::pair<std::size_t, std::size_t> > replies = detail::lqn2qn_replies(lqn::LqnModel<T>(), lsn);
1391 detail::Lqn2Pn<T> conv(lsn, replies, replication, name, warnings, map);
1392 return conv.run();
1393}
1394
1395} // namespace io
1396} // namespace line
1397
1398#endif // LINE_IO_LQN2PN_H
InputError(const std::string &what)
Definition error.h:105
InternalError(const std::string &what)
Definition error.h:133
std::size_t rows() const
Definition matrix.h:89
UnsupportedError(const std::string &what)
Definition error.h:119
A queueing network under construction.
std::size_t add_source(const std::string &nm)
The external arrival station.
void set_enabling_conditions(std::size_t node, std::size_t mode, std::size_t cls, std::size_t place, const T &tokens)
Transition.setEnablingConditions(mode, class, place, tokens): how many class-r tokens the mode needs ...
std::size_t add_open_class(const std::string &nm, int prio=0)
An open class.
void set_mode_timing(std::size_t node, std::size_t mode, lang::TimingStrategy ts)
Transition.setTimingStrategy(mode, strategy): TIMED or IMMEDIATE.
void set_firing_weight(std::size_t node, std::size_t mode, const T &w)
Transition.setFiringWeights(mode, weight): the share among tied modes.
RoutingMatrix< T > init_routing_matrix() const
An empty routing matrix, MATLAB's model.initRoutingMatrix.
void set_mode_distribution(std::size_t node, std::size_t mode, const Distrib< T > &d)
Transition.setDistribution(mode, dist): the mode's firing law.
void set_initial_marking(std::size_t node, const std::vector< T > &tokens)
Place.setState(marking): the initial token count of the place, per class.
void set_inhibiting_conditions(std::size_t node, std::size_t mode, std::size_t cls, std::size_t place, const T &tokens)
Transition.setInhibitingConditions(mode, class, place, tokens): the class-r count at place that BLOCK...
void set_mode_firing_dependence(std::size_t node, std::size_t mode, const std::function< T(const std::vector< T > &)> &g)
Transition.setFiringRateDependence(mode, g): g(marking) scales the rate.
std::size_t add_mode(std::size_t node, const std::string &nm)
Transition.addMode(name): a new firing mode, returning its 1-based index.
std::size_t add_closed_class(const std::string &nm, double njobs, std::size_t refstat_node, int prio=0)
A closed class of the given population, referencing a station node.
std::size_t add_sink(const std::string &nm)
The external departure node.
std::size_t add_place(const std::string &nm)
A Place: an SPN token container.
NetworkStruct< T > & raw_struct()
The struct WITHOUT refreshing it, for a caller that is still building.
void link(const RoutingMatrix< T > &Pm)
model.link(P): install the routing.
void set_mode_servers(std::size_t node, std::size_t mode, double n)
Transition.setNumberOfServers(mode, n); GlobalConstants::MaxInt is infinite.
void set_firing_outcome(std::size_t node, std::size_t mode, std::size_t cls, std::size_t dest, const T &tokens)
Transition.setFiringOutcome(mode, class, node, tokens): the class-r tokens the firing deposits.
std::size_t add_transition(const std::string &nm, const TransitionParam< T > &par)
A Transition: the firing rules of an SPN, as Transition in MATLAB.
void set_arrival(std::size_t node, std::size_t cls, const Distrib< T > &d)
source.setArrival(class, dist): the same table, at the Source.
The routing matrix a model script fills in, MATLAB's P cell array.
void set(std::size_t r, std::size_t s, std::size_t i, std::size_t j, const T &p)
The exception types the port throws.
int dispatch(const Options &in, bool allow_server, bool no_args)
Everything main did, with the arguments already in hand.
Convert a layered queueing network into a single queueing network in which synchronous call blocking ...
.lqnx -> LqnStruct, a port of matlab/src/lang/layered/@LayeredNetwork/parseXML.m followed by ....
LayeredNetworkStruct, the flattened description of a layered queueing network.
qn::Network< T > lqn2pn(const lqn::LqnModel< T > &lqn, const std::string &replication="auto", const std::string &name="model", std::vector< std::string > *warnings=nullptr, Lqn2PnMap *map=nullptr)
Port of Python LQN2PN(lqn, replication, return_map) and MATLAB LQN2PN: convert a layered network into...
Definition lqn2pn.h:1371
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
Definition lang_types.h:194
@ IMMEDIATE
fires with zero delay, resolved by weight and priority
Definition lang_types.h:389
CallType
Call kinds, with the values of MATLAB CallType.
Definition lang_types.h:513
ProcessType
Distribution kinds, with the values of MATLAB ProcessType.
Definition lang_types.h:529
const char * sched_to_text(SchedStrategy s)
Definition lang_types.h:252
const char * process_to_text(ProcessType p)
The MATLAB ProcessType name, as sn.procid prints it.
Definition lang_types.h:660
LqnStruct< T > lqn_finalize(const LqnModel< T > &m)
Port of @LayeredNetwork/getStruct.m: flatten the model into its struct.
Definition lqn_reader.h:501
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
lang::Distrib< double > Dist
Definition nodes.h:54
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...
Number-type abstraction for the templated API port.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
A (place, class) pair of the Petri net, by node and class NAME.
Definition lqn2pn.h:84
std::string cls
Definition lqn2pn.h:86
std::string place
Definition lqn2pn.h:85
The (place, class) copies of an entry or activity whose Tput sums to its throughput.
Definition lqn2pn.h:119
std::vector< Lqn2PnCell > cells
Definition lqn2pn.h:121
The result map of LQN2PN, the twin of the Python return_map dictionary, insertion-ordered.
Definition lqn2pn.h:125
std::vector< Lqn2PnProcessor > processors
Definition lqn2pn.h:126
std::vector< Lqn2PnElement > entries
Definition lqn2pn.h:128
std::vector< Lqn2PnElement > activities
Definition lqn2pn.h:129
std::vector< Lqn2PnTask > tasks
Definition lqn2pn.h:127
Where to read a processor replica.
Definition lqn2pn.h:96
std::vector< Lqn2PnCell > busy
Definition lqn2pn.h:100
std::string sched
scheduling, as the Python enum name (FCFS, SIRO, PS, INF)
Definition lqn2pn.h:98
std::vector< Lqn2PnCell > run
Definition lqn2pn.h:101
std::string name
processor name, _r<k> suffixed for replica k >= 2
Definition lqn2pn.h:97
Where to read a task replica.
Definition lqn2pn.h:109
Lqn2PnCell busy
Definition lqn2pn.h:113
Lqn2PnCell think
Definition lqn2pn.h:115
std::string name
Definition lqn2pn.h:110
Lqn2PnCell free
Definition lqn2pn.h:113
bool is_immediate() const
Matrix< T > D0
The (D0,D1) pair when the type carries one directly.
Definition lang_types.h:926
static Distrib exp_rate(const T &r)
static Distrib disabled_dist()
static constexpr double FineTol
Definition lang_types.h:828
static constexpr double MaxInt
Stand-in for an unbounded COUNT, MATLAB GlobalConstants.MaxInt.
Definition lang_types.h:839
The intermediate model, and the second stage that flattens it.
Definition lqn_reader.h:411
std::vector< Distrib< T > > hostdem
(nidx+1) host demand per activity (Immediate elsewhere)
Definition lqn_struct.h:298
std::vector< CallType > calltype
(ncalls+1)
Definition lqn_struct.h:311
std::vector< std::size_t > callpair_dst
(ncalls+1) called entry
Definition lqn_struct.h:310
std::vector< bool > hassetup
(tshift+ntasks+1)
Definition lqn_struct.h:268
std::vector< Distrib< T > > actthink
(nidx+1) activity think time
Definition lqn_struct.h:300
std::vector< std::vector< T > > lldscaling
Queue-dependent service rates declared on a layer server (a host or a task), by element index,...
Definition lqn_struct.h:237
std::vector< double > mult
(tshift+ntasks+1) declared multiplicity, may be Inf
Definition lqn_struct.h:216
std::vector< SchedStrategy > sched
(tshift+ntasks+1)
Definition lqn_struct.h:215
std::vector< std::size_t > callpair_src
(ncalls+1) calling activity (entry for FWD)
Definition lqn_struct.h:309
std::vector< std::size_t > parent
(nidx+1) host of a task, task of an entry/activity
Definition lqn_struct.h:214
std::vector< ServerPools< T > > pools
(tshift+ntasks+1)
Definition lqn_struct.h:242
std::vector< T > callproc_mean
(ncalls+1) mean number of calls
Definition lqn_struct.h:312
std::vector< std::size_t > actquorum
(nidx+1) AND-join quorum, on the join target
Definition lqn_struct.h:367
std::vector< bool > iscache
(tshift+ntasks+1)
Definition lqn_struct.h:266
std::vector< bool > has_arrival
(nidx+1) entry with an open arrival
Definition lqn_struct.h:301
std::vector< std::vector< std::size_t > > callsof
(nidx+1) call indices issued by an activity
Definition lqn_struct.h:307
std::size_t nentries
Definition lqn_struct.h:208
std::vector< CdScaling< T > > cdscaling
(tshift+ntasks+1)
Definition lqn_struct.h:238
std::vector< std::vector< std::size_t > > entriesof
(tshift+ntasks+1)
Definition lqn_struct.h:305
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.
Definition lqn_struct.h:259
std::vector< double > repl
(tshift+ntasks+1) replication
Definition lqn_struct.h:218
std::vector< std::string > names
(nidx+1) declared name
Definition lqn_struct.h:211
std::vector< Matrix< T > > lincon_A
Admission constraint A n <= b on the layer station of a host or task.
Definition lqn_struct.h:332
std::vector< Distrib< T > > think
(nidx+1) task think time
Definition lqn_struct.h:299
std::vector< bool > isref
(tshift+ntasks+1)
Definition lqn_struct.h:265
std::vector< PrecedenceType > actpretype
(nidx+1)
Definition lqn_struct.h:365
std::vector< std::vector< std::size_t > > actsof
(ashift+1) by task and by entry
Definition lqn_struct.h:306
std::vector< PrecedenceType > actposttype
(nidx+1)
Definition lqn_struct.h:366
std::vector< Distrib< T > > arrival
(nidx+1) open arrival process of an entry
Definition lqn_struct.h:302
std::vector< CdScaling< T > > jdscaling
(tshift+ntasks+1)
Definition lqn_struct.h:240
SparseGraph< T > graph
element call/precedence graph, edge weights are branch shares
Definition lqn_struct.h:316