LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
mam_map_network.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_LANG_LAL_MAM_MAP_NETWORK_H
6#define LINE_LANG_LAL_MAM_MAP_NETWORK_H
7
8/**
9 * @file
10 * @ingroup line_lang
11 * LINE Agent Language (LAL): lowering of a restricted open MAP/PH network to
12 * the native MAM `dec.source` decomposition (solver_mam/lal_map_network.py),
13 * plus the structural recogniser the parallel QBD shares
14 * (solver_mam/lal_parallel_qbd.py `recognize`).
15 *
16 * The native decomposition is the C++ `mam::mam_dispatch` with method
17 * `dec.source`, the port of the MATLAB reference analyzer, where Python runs
18 * its own native SolverMAM.
19 */
20
21#include <cmath>
22#include <functional>
23#include <map>
24#include <optional>
25#include <set>
26#include <string>
27#include <utility>
28#include <vector>
29
35
36namespace line {
37namespace lal {
38
39/** One routed completion mark of a PH service clock. */
40struct ClockRoute {
41 std::string input;
42 std::vector<Endpoint> partners;
43 std::optional<std::string> target;
44 double probability = 0.0;
45};
46
47/** A PH service clock driving a queue (the `clocks[q]` dictionary). */
49 std::size_t agent = 0; ///< agent index of the clock
50 std::vector<std::pair<std::string, ClockRoute>> routes; ///< mark -> route, in service-input order
52 std::vector<double> alpha;
53 double mean = 0.0;
54 std::vector<double> busy_phases;
56 bool correlated_reset = false;
57};
58
59/** The recognised MAP network (`lal_map_network.recognize` tuple). */
60struct MapMatch {
61 std::vector<std::size_t> queues;
62 std::vector<std::size_t> sources;
63 std::map<std::string, std::vector<std::string>> marks;
64 std::map<Endpoint, std::string> sync;
65 std::optional<std::string> target;
66 std::map<std::string, ServiceClock> clocks; ///< keyed by queue name
67};
68
69namespace detail {
70
71inline bool contains_str(const std::vector<std::string>& v, const std::string& x) {
72 return std::find(v.begin(), v.end(), x) != v.end();
73}
74
75inline bool phase_named(const AgentRecord& a) {
76 for (std::size_t i = 0; i < a.states.size(); ++i)
77 if (a.states[i] != "phase_" + std::to_string(i)) return false;
78 return true;
79}
80
81inline bool all_active(const AgentRecord& a) {
82 for (const Transition& t : a.transitions)
83 if (t.role != Role::Active) return false;
84 return true;
85}
86
87inline const std::string* find_route(const QueueInfo& info, const std::string& action, double* probability = nullptr) {
88 for (const auto& r : info.routes)
89 if (r.first == action) {
90 if (probability) *probability = r.second;
91 return &r.first;
92 }
93 return nullptr;
94}
95
96} // namespace detail
97
98/** Recognise a restricted open MAP/PH network (`lal_map_network.recognize`). */
99inline std::pair<std::optional<MapMatch>, std::string> recognize_map(const Model& snapshot, bool allow_split = false) {
100 typedef std::pair<std::optional<MapMatch>, std::string> Out;
101 if (!snapshot.min_syncs.empty()) return Out{std::nullopt, "MAP network lowering does not support minimum synchronizations."};
102 MapMatch m;
103 std::set<std::string> queue_names;
104 for (std::size_t a = 0; a < snapshot.agents.size(); ++a)
105 if (snapshot.agents[a].queue_info) {
106 m.queues.push_back(a);
107 queue_names.insert(snapshot.agents[a].name);
108 }
109 bool bad = m.queues.size() < 2;
110 for (std::size_t q : m.queues)
111 if (snapshot.agents[q].queue_info->capacity) bad = true;
112 if (bad) return Out{std::nullopt, "MAP network lowering requires at least two unbounded queues."};
113 for (std::size_t q : m.queues)
114 if (!snapshot.agents[q].queue_info->service_inputs.empty() && snapshot.agents[q].queue_info->servers != 1)
115 return Out{std::nullopt, "MAP network PH-service lowering requires a single server per PH station."};
116 if (m.queues.size() > 100) return Out{std::nullopt, "MAP network lowering supports at most 100 queues."};
117 std::map<Endpoint, std::pair<Endpoint, std::vector<Endpoint>>> passive_bindings;
118 for (const Sync& s : snapshot.syncs)
119 for (const Endpoint& e : s.passive) passive_bindings[e] = {s.active, s.passive};
120 std::set<std::string> clock_names;
121 for (std::size_t qi : m.queues) {
122 const AgentRecord& q = snapshot.agents[qi];
123 const QueueInfo& info = *q.queue_info;
124 const std::vector<std::string>& inputs = info.service_inputs;
125 if (inputs.empty()) continue;
126 std::vector<std::pair<std::string, std::pair<Endpoint, std::vector<Endpoint>>>> bindings;
127 for (const std::string& action : inputs) {
128 auto it = passive_bindings.find(Endpoint(q.name, action));
129 if (it == passive_bindings.end()) return Out{std::nullopt, "PH service completions must synchronize with their queue."};
130 bindings.push_back({action, it->second});
131 }
132 std::set<std::string> names;
133 for (const auto& b : bindings) names.insert(b.second.first.first);
134 if (names.size() != 1) return Out{std::nullopt, "Each PH queue needs one service clock agent."};
135 const std::string name = *names.begin();
136 if (queue_names.count(name) || clock_names.count(name) || !snapshot.has_agent(name))
137 return Out{std::nullopt, "Each PH queue needs its own service clock agent."};
138 const AgentRecord& clock = snapshot.agent(name);
139 if (!detail::phase_named(clock) || !detail::all_active(clock))
140 return Out{std::nullopt, "PH service clocks must be matrix-valued phase agents."};
141 std::set<std::string> marks, actions;
142 for (const Transition& t : clock.transitions)
143 if (t.action != "_phase") marks.insert(t.action);
144 for (const auto& b : bindings) actions.insert(b.second.first.second);
145 if (marks != actions || actions.size() != bindings.size())
146 return Out{std::nullopt, "Every PH completion mark must have one queue service input."};
147 ServiceClock c;
148 c.agent = snapshot.index_of(name);
149 for (const auto& b : bindings) {
150 const std::string& input_name = b.first;
151 const Endpoint& active = b.second.first;
152 const std::vector<Endpoint>& partners = b.second.second;
153 std::vector<Endpoint> arrivals;
154 for (const Endpoint& e : partners)
155 if (e != Endpoint(q.name, input_name)) arrivals.push_back(e);
156 bool ok = arrivals.size() <= 1;
157 for (const Endpoint& e : arrivals)
158 if (!queue_names.count(e.first) || !detail::contains_str(snapshot.agent(e.first).queue_info->arrivals, e.second))
159 ok = false;
160 if (!ok) return Out{std::nullopt, "A PH completion may route to at most one queue."};
161 ClockRoute r;
162 r.input = input_name;
163 r.partners = partners;
164 if (!arrivals.empty()) r.target = arrivals[0].first;
165 bool replaced = false;
166 for (auto& kv : c.routes)
167 if (kv.first == active.second) {
168 kv.second = r;
169 replaced = true;
170 }
171 if (!replaced) c.routes.push_back({active.second, r});
172 }
173 bool has_phase = false;
174 for (const Transition& t : clock.transitions)
175 if (t.action == "_phase" && t.value > 0) has_phase = true;
176 if (has_phase) {
177 bool ok = static_cast<bool>(info.service_phase);
178 if (ok) {
179 auto it = passive_bindings.find(Endpoint(q.name, *info.service_phase));
180 ok = it != passive_bindings.end() && it->second.first == Endpoint(name, "_phase") &&
181 it->second.second == std::vector<Endpoint>{Endpoint(q.name, *info.service_phase)};
182 }
183 if (!ok) return Out{std::nullopt, "PH service phase transitions must be enabled only while its queue is busy."};
184 }
185 const std::size_t n = clock.states.size();
186 if (n > 256) return Out{std::nullopt, "PH service clock exceeds the 256-phase inspection limit."};
187 Matrix<double> T(n, n, 0.0), D1(n, n, 0.0);
188 std::map<std::string, Matrix<double>> marked;
189 for (const auto& kv : c.routes) marked[kv.first] = Matrix<double>(n, n, 0.0);
190 for (const Transition& t : clock.transitions) {
191 const std::size_t i = clock.state_index(t.source), j = clock.state_index(t.target);
192 if (t.action == "_phase") {
193 if (i != j) T(i, j) += t.value;
194 } else {
195 marked[t.action](i, j) += t.value;
196 }
197 }
198 for (const auto& kv : c.routes) D1 = detail::add(D1, marked[kv.first]);
199 const std::vector<double> exits = detail::row_sums(D1);
200 const std::vector<double> trow = detail::row_sums(T);
201 for (std::size_t i = 0; i < n; ++i) T(i, i) = -(trow[i] + exits[i]);
202 bool any_exit = false;
203 for (double e : exits)
204 if (e > 0) any_exit = true;
205 if (!any_exit) return Out{std::nullopt, "PH service must eventually complete."};
206 std::vector<double> visits;
207 try {
208 const Matrix<double> negT = detail::scaled(T, -1.0);
209 Matrix<double> lu = negT;
210 const std::vector<std::size_t> piv = lu_factor(lu);
211 Matrix<double> embedded(n, n, 0.0);
212 for (std::size_t col = 0; col < n; ++col) {
213 std::vector<double> b(n);
214 for (std::size_t i = 0; i < n; ++i) b[i] = D1(i, col);
215 lu_solve(lu, piv, b);
216 for (std::size_t i = 0; i < n; ++i) embedded(i, col) = b[i];
217 }
218 double emin = std::numeric_limits<double>::infinity();
219 bool stochastic = detail::all_finite(embedded);
220 for (std::size_t k = 0; k < embedded.size(); ++k) emin = std::min(emin, embedded[k]);
221 const std::vector<double> esum = detail::row_sums(embedded);
222 for (double s : esum)
223 if (!(std::fabs(s - 1.0) <= 1e-10)) stochastic = false;
224 if (!stochastic || emin < -1e-10)
225 return Out{std::nullopt, "Service completion phase transitions must form a stochastic matrix."};
226 for (std::size_t i = 0; i < n; ++i) {
227 double rs = 0.0;
228 for (std::size_t j = 0; j < n; ++j) {
229 embedded(i, j) = std::max(embedded(i, j), 0.0);
230 rs += embedded(i, j);
231 }
232 for (std::size_t j = 0; j < n; ++j) embedded(i, j) /= rs;
233 }
234 std::vector<std::vector<std::size_t>> adj(n);
235 for (std::size_t i = 0; i < n; ++i)
236 for (std::size_t j = 0; j < n; ++j)
237 if (i != j && embedded(i, j) > 0) adj[i].push_back(j);
238 if (!detail::unique_closed_class(adj))
239 return Out{std::nullopt, "The service completion phase chain must have one closed class."};
240 Matrix<double> gen = embedded;
241 for (std::size_t i = 0; i < n; ++i) gen(i, i) -= 1.0;
242 c.alpha = detail::stationary(gen);
243 double amin = std::numeric_limits<double>::infinity(), asum = 0.0;
244 for (double v : c.alpha) {
245 amin = std::min(amin, v);
246 asum += v;
247 }
248 if (!std::isfinite(asum) || !std::isfinite(amin) || amin < -1e-10 || !(asum > 0))
249 return Out{std::nullopt, "Service completion phase probabilities are invalid."};
250 asum = 0.0;
251 for (double& v : c.alpha) {
252 v = std::max(v, 0.0);
253 asum += v;
254 }
255 for (double& v : c.alpha) v /= asum;
256 visits = detail::lu_solve_vec(negT.transpose(), c.alpha);
257 } catch (const NumericError&) {
258 return Out{std::nullopt, "PH service subgenerator must be transient."};
259 }
260 double mean = 0.0, vmin = std::numeric_limits<double>::infinity();
261 for (double v : visits) {
262 mean += v;
263 vmin = std::min(vmin, v);
264 }
265 if (!std::isfinite(mean) || mean <= 0 || vmin < -1e-10)
266 return Out{std::nullopt, "PH service subgenerator must be transient."};
267 bool phase_dependent = false;
268 const double marking_scale = std::max(detail::max_abs(D1), detail::tiny());
269 for (auto& kv : c.routes) {
270 const Matrix<double>& matrix = marked[kv.first];
271 const std::vector<double> rs = detail::row_sums(matrix);
272 double probability = 0.0;
273 for (std::size_t i = 0; i < n; ++i) probability += visits[i] * rs[i];
274 if (probability < -1e-10 || probability > 1 + 1e-10)
275 return Out{std::nullopt, "PH completion routing probabilities are invalid."};
276 kv.second.probability = std::max(0.0, std::min(1.0, probability));
277 if (detail::max_abs(detail::add(matrix, detail::scaled(D1, -probability))) > 1e-10 * marking_scale)
278 phase_dependent = true;
279 }
280 Matrix<double> outer(n, n, 0.0);
281 for (std::size_t i = 0; i < n; ++i)
282 for (std::size_t j = 0; j < n; ++j) outer(i, j) = exits[i] * c.alpha[j];
283 c.T = T;
284 c.mean = mean;
285 c.busy_phases = visits;
286 for (double& v : c.busy_phases) v /= mean;
287 c.phase_dependent_routing = phase_dependent;
288 c.correlated_reset = detail::max_abs(detail::add(D1, detail::scaled(outer, -1.0))) > 1e-10 * marking_scale;
289 m.clocks[q.name] = c;
290 clock_names.insert(name);
291 }
292 for (std::size_t a = 0; a < snapshot.agents.size(); ++a) {
293 const std::string& name = snapshot.agents[a].name;
294 if (!queue_names.count(name) && !clock_names.count(name)) m.sources.push_back(a);
295 }
296 if (m.sources.empty()) return Out{std::nullopt, "MAP network lowering requires independent MAP or MMAP sources."};
297 for (std::size_t a : m.sources) {
298 const AgentRecord& source = snapshot.agents[a];
299 if (!detail::phase_named(source) || !detail::all_active(source))
300 return Out{std::nullopt, "MAP network lowering requires MAP or MMAP source agents."};
301 std::vector<std::string> ms;
302 for (const Transition& t : source.transitions)
303 if (t.action != "_phase" && !detail::contains_str(ms, t.action)) ms.push_back(t.action);
304 m.marks[source.name] = ms;
305 if (ms.empty()) return Out{std::nullopt, "Every MAP network source must have a mark."};
306 }
307 for (const Sync& s : snapshot.syncs) {
308 const Endpoint& active = s.active;
309 const std::vector<Endpoint>& partners = s.passive;
310 if (clock_names.count(active.first)) {
311 std::string qname;
312 for (const auto& kv : m.clocks)
313 if (snapshot.agents[kv.second.agent].name == active.first) qname = kv.first;
314 const ServiceClock& clock_entry = m.clocks.at(qname);
315 const QueueInfo& qinfo = *snapshot.agent(qname).queue_info;
316 const ClockRoute* route = nullptr;
317 for (const auto& kv : clock_entry.routes)
318 if (kv.first == active.second) route = &kv.second;
319 if (route) {
320 if (partners != route->partners) return Out{std::nullopt, "Unsupported PH completion synchronization."};
321 if (route->target) m.sync[active] = *route->target;
322 } else if (active.second == "_phase") {
323 if (!qinfo.service_phase || partners != std::vector<Endpoint>{Endpoint(qname, *qinfo.service_phase)})
324 return Out{std::nullopt, "Unsupported PH progress synchronization."};
325 } else {
326 return Out{std::nullopt, "Unsupported PH clock action."};
327 }
328 continue;
329 }
330 if (partners.size() != 1 || !queue_names.count(partners[0].first))
331 return Out{std::nullopt, "MAP network routing requires one queue input per synchronized event."};
332 const std::string& target = partners[0].first;
333 if (!detail::contains_str(snapshot.agent(target).queue_info->arrivals, partners[0].second))
334 return Out{std::nullopt, "MAP network routing can only target queue arrivals."};
335 if (m.marks.count(active.first)) {
336 if (!detail::contains_str(m.marks[active.first], active.second))
337 return Out{std::nullopt, "The MAP phase action must not be synchronized."};
338 } else if (queue_names.count(active.first)) {
339 if (!detail::find_route(*snapshot.agent(active.first).queue_info, active.second))
340 return Out{std::nullopt, "MAP network routing must use declared queue departures."};
341 } else {
342 return Out{std::nullopt, "Unsupported MAP network synchronization."};
343 }
344 m.sync[active] = target;
345 }
346 std::set<std::string> targets;
347 for (std::size_t a : m.sources)
348 for (const std::string& mark : m.marks[snapshot.agents[a].name]) {
349 auto it = m.sync.find(Endpoint(snapshot.agents[a].name, mark));
350 if (it == m.sync.end()) return Out{std::nullopt, "Every MAP source mark must feed a queue."};
351 targets.insert(it->second);
352 }
353 if (targets.size() != 1 && !allow_split)
354 return Out{std::nullopt, "All source marks must feed the same queue to preserve their shared phases."};
355 if (targets.size() == 1) m.target = *targets.begin();
356 return Out{m, ""};
357}
358
359/** Recognise independent stations with shared marked sources (`lal_parallel_qbd.recognize`). */
360inline std::pair<std::optional<MapMatch>, std::string> recognize_parallel(const Model& snapshot) {
361 typedef std::pair<std::optional<MapMatch>, std::string> Out;
362 auto mm = recognize_map(snapshot, true);
363 if (!mm.first) {
364 // Outside the MAP-network form the parallel lowering takes exponential
365 // (possibly multiserver) queues only, so it names its own constraint.
366 MapMatch m;
367 std::set<std::string> queue_names;
368 for (std::size_t a = 0; a < snapshot.agents.size(); ++a)
369 if (snapshot.agents[a].queue_info) {
370 m.queues.push_back(a);
371 queue_names.insert(snapshot.agents[a].name);
372 }
373 bool bad = m.queues.size() < 2;
374 for (std::size_t q : m.queues)
375 if (snapshot.agents[q].queue_info->capacity) bad = true;
376 if (bad) return Out{std::nullopt, "Parallel QBD requires at least two unbounded queues."};
377 std::vector<std::string> clocked;
378 for (std::size_t q : m.queues)
379 if (!snapshot.agents[q].queue_info->service_inputs.empty()) clocked.push_back(snapshot.agents[q].name);
380 std::sort(clocked.begin(), clocked.end());
381 if (!clocked.empty()) {
382 std::string joined;
383 for (std::size_t k = 0; k < clocked.size(); ++k) joined += (k ? ", " : "") + clocked[k];
384 return Out{std::nullopt,
385 "Parallel QBD supports a queue driven by a PH service clock only in the MAP-network form, which "
386 "requires unbounded queues, single-server PH clocks and no minimum synchronizations; PH-clocked queue(s): " +
387 joined + ". MAP-network form refused: " + mm.second};
388 }
389 for (std::size_t a = 0; a < snapshot.agents.size(); ++a)
390 if (!queue_names.count(snapshot.agents[a].name)) m.sources.push_back(a);
391 bool src_bad = m.sources.empty();
392 for (std::size_t a : m.sources)
393 if (snapshot.agents[a].unbounded_queue) src_bad = true;
394 if (src_bad) return Out{std::nullopt, "Parallel QBD requires finite autonomous background agents."};
395 auto arrival_ok = [&](const Endpoint& e) {
396 return !queue_names.count(e.first) || detail::contains_str(snapshot.agent(e.first).queue_info->arrivals, e.second);
397 };
398 for (const Sync& s : snapshot.syncs) {
399 if (queue_names.count(s.active.first)) return Out{std::nullopt, "Parallel QBD requires no synchronized queue departures."};
400 for (const Endpoint& e : s.passive)
401 if (!arrival_ok(e)) return Out{std::nullopt, "Parallel QBD can only synchronize queue arrivals."};
402 }
403 for (const MinSync& s : snapshot.min_syncs) {
404 for (const Endpoint& e : s.active)
405 if (queue_names.count(e.first)) return Out{std::nullopt, "Parallel QBD requires autonomous active background agents."};
406 for (const Endpoint& e : s.passive)
407 if (!arrival_ok(e)) return Out{std::nullopt, "Parallel QBD can only synchronize queue arrivals."};
408 }
409 return Out{m, ""};
410 }
411 const MapMatch& m = *mm.first;
412 for (std::size_t qi : m.queues) {
413 const AgentRecord& q = snapshot.agents[qi];
414 auto it = m.clocks.find(q.name);
415 if (it != m.clocks.end()) {
416 for (const auto& kv : it->second.routes)
417 if (kv.second.target) return Out{std::nullopt, "Parallel QBD requires no routing between queues."};
418 } else {
419 for (const auto& r : q.queue_info->routes)
420 if (m.sync.count(Endpoint(q.name, r.first))) return Out{std::nullopt, "Parallel QBD requires no routing between queues."};
421 }
422 }
423 return mm;
424}
425
426namespace detail {
427
428/** Routing matrix of a recognised MAP network, with PH completions at their mean probabilities. */
429inline Matrix<double> map_routing(const Model& snapshot, const MapMatch& m, const std::map<std::string, std::size_t>& qidx) {
430 const std::size_t n = m.queues.size();
431 Matrix<double> routing(n, n, 0.0);
432 for (std::size_t i = 0; i < n; ++i) {
433 const AgentRecord& q = snapshot.agents[m.queues[i]];
434 auto it = m.clocks.find(q.name);
435 if (it != m.clocks.end()) {
436 for (const auto& kv : it->second.routes)
437 if (kv.second.target) routing(i, qidx.at(*kv.second.target)) += kv.second.probability;
438 } else {
439 for (const auto& r : q.queue_info->routes) {
440 auto s = m.sync.find(Endpoint(q.name, r.first));
441 if (s != m.sync.end()) routing(i, qidx.at(s->second)) += r.second;
442 }
443 }
444 }
445 return routing;
446}
447
448/** Source phase matrices `[D0, D1, D1_mark...]` plus the `_phase` reward of a MAP/MMAP agent. */
449inline MarkedMatrices source_stream(const AgentRecord& source, const std::vector<std::string>& marks,
450 std::vector<double>& phase_reward) {
451 const std::size_t n = source.states.size();
452 Matrix<double> d0(n, n, 0.0);
453 std::vector<Matrix<double>> marked(marks.size(), Matrix<double>(n, n, 0.0));
454 phase_reward.assign(n, 0.0);
455 for (const Transition& t : source.transitions) {
456 const std::size_t i = source.state_index(t.source), j = source.state_index(t.target);
457 if (t.action == "_phase") {
458 phase_reward[i] += t.value;
459 if (i != j) d0(i, j) += t.value;
460 } else {
461 const std::size_t k = static_cast<std::size_t>(std::find(marks.begin(), marks.end(), t.action) - marks.begin());
462 marked[k](i, j) += t.value;
463 }
464 }
465 Matrix<double> d1(n, n, 0.0);
466 for (const auto& mk : marked) d1 = add(d1, mk);
467 const std::vector<double> r0 = row_sums(d0), r1 = row_sums(d1);
468 for (std::size_t i = 0; i < n; ++i) d0(i, i) = -(r0[i] + r1[i]);
469 MarkedMatrices out{d0, d1};
470 out.insert(out.end(), marked.begin(), marked.end());
471 return out;
472}
473
474/**
475 * Native `dec.source` mean queue length at every queue of an open network with
476 * one MAP source (`SolverMAM(network, method='dec.source', space_max=...)`).
477 */
478inline std::pair<std::vector<double>, std::vector<double>> native_dec_source(
479 const Matrix<double>& d0, const Matrix<double>& d1,
480 const std::vector<std::pair<std::optional<std::pair<std::vector<double>, Matrix<double>>>, double>>& services,
481 const std::vector<long>& servers, const Matrix<double>& routing, std::size_t entry, const std::string& name,
482 const std::string& qprefix, double tol, long max_iter, double max_phases) {
483 typedef lang::Distrib<double> Dist;
484 qn::Network<double> network(name);
485 const std::size_t n = services.size();
486 const std::size_t src = network.add_source(n == 1 && qprefix == "Queue" ? "Source" : "LALSource");
487 std::vector<std::size_t> nodes;
488 for (std::size_t i = 0; i < n; ++i)
489 nodes.push_back(network.add_queue(n == 1 && qprefix == "Queue" ? "Queue" : qprefix + std::to_string(i), lang::SchedStrategy::FCFS));
490 const std::size_t sink = network.add_sink(n == 1 && qprefix == "Queue" ? "Sink" : "LALSink");
491 const std::size_t job = network.add_open_class(n == 1 && qprefix == "Queue" ? "Class" : "LALClass");
492 network.set_arrival(src, job, Dist::map_dist(d0, d1, lang::ProcessType::MAP));
493 for (std::size_t i = 0; i < n; ++i) {
494 network.set_number_of_servers(nodes[i], static_cast<double>(servers[i]));
495 if (services[i].first)
496 network.set_service(nodes[i], job, Dist::phase_type(services[i].first->first, services[i].first->second, false));
497 else
498 network.set_service(nodes[i], job, Dist::exp_rate(services[i].second));
499 }
500 qn::RoutingMatrix<double> route;
501 route.set(job, job, src, nodes[entry], 1.0);
502 for (std::size_t i = 0; i < n; ++i) {
503 double out = 0.0;
504 for (std::size_t j = 0; j < n; ++j) out += routing(i, j);
505 const double exit_probability = 1.0 - out;
506 for (std::size_t j = 0; j < n; ++j)
507 if (routing(i, j) != 0) route.set(job, job, nodes[i], nodes[j], routing(i, j));
508 if (exit_probability > 1e-14) route.set(job, job, nodes[i], sink, exit_probability);
509 }
510 network.link(route);
511 const qn::NetworkStruct<double> sn = network.get_struct();
512 mam::MamOptions opt;
513 opt.method = "dec.source";
514 opt.tol = tol;
515 opt.iter_max = static_cast<int>(max_iter);
516 opt.space_max = static_cast<std::size_t>(std::min(max_phases, 1e18));
517 const mam::MamSolution<double> sol = mam::mam_dispatch(sn, opt);
518 std::vector<double> q, x;
519 for (std::size_t i = 0; i < n; ++i) {
520 q.push_back(sol.sol.Q(sn.nodes[nodes[i] - 1].station - 1, 0));
521 x.push_back(sol.sol.Tp(sn.nodes[nodes[i] - 1].station - 1, 0));
522 }
523 return {q, x};
524}
525
526} // namespace detail
527
528/// Per-queue service law handed to the native `dec.source` solve: a PH
529/// (alpha, T) or, when empty, an exponential with the given rate.
530typedef std::vector<std::pair<std::optional<std::pair<std::vector<double>, Matrix<double>>>, double>> NativeServices;
531
532/**
533 * The native `dec.source` solve behind `map_network` and `marked_thinning`
534 * (Python's `SolverMAM(network, method='dec.source').getAvgTable()`), with the
535 * arguments of `detail::native_dec_source`, returning per-queue (QLen, Tput).
536 * Replaceable so a test can intercept it; an empty function keeps the native
537 * solver.
538 */
539typedef std::function<std::pair<std::vector<double>, std::vector<double>>(
540 const Matrix<double>&, const Matrix<double>&, const NativeServices&, const std::vector<long>&, const Matrix<double>&,
541 std::size_t, const std::string&, const std::string&, double, long, double)>
543
544namespace detail {
545
546/** `backend` when set, else the native `dec.source` solve. */
547inline std::pair<std::vector<double>, std::vector<double>> run_native_dec_source(
548 const NativeDecSourceBackend& backend, const Matrix<double>& d0, const Matrix<double>& d1, const NativeServices& services,
549 const std::vector<long>& servers, const Matrix<double>& routing, std::size_t entry, const std::string& name,
550 const std::string& qprefix, double tol, long max_iter, double max_phases) {
551 if (backend) return backend(d0, d1, services, servers, routing, entry, name, qprefix, tol, max_iter, max_phases);
552 return native_dec_source(d0, d1, services, servers, routing, entry, name, qprefix, tol, max_iter, max_phases);
553}
554
555/** Per-queue state rows and action rates shared by dec.source and marked.thinning. */
556inline void clock_rows_and_rates(const Model& snapshot, const MapMatch& m, const std::vector<double>& traffic,
557 const std::map<std::string, std::size_t>& qidx,
558 const std::map<std::string, std::vector<double>>& source_distributions,
559 std::map<std::string, double>& action_rates, StateTable& states) {
560 std::map<std::string, std::string> clock_queue;
561 for (const auto& kv : m.clocks) clock_queue[snapshot.agents[kv.second.agent].name] = kv.first;
562 for (const AgentRecord& agent : snapshot.agents) {
563 auto sd = source_distributions.find(agent.name);
564 if (sd != source_distributions.end()) {
565 for (std::size_t i = 0; i < agent.states.size(); ++i)
566 states.rows.push_back(StateRow{agent.name, agent.states[i], sd->second[i]});
567 } else if (!clock_queue.count(agent.name)) {
568 states.rows.push_back(StateRow{agent.name, "unavailable", std::numeric_limits<double>::quiet_NaN()});
569 } else {
570 const std::string& qname = clock_queue[agent.name];
571 const ServiceClock& clock = m.clocks.at(qname);
572 const double utilization = traffic[qidx.at(qname)] * clock.mean; // PH stations have one server
573 const bool unavailable = clock.correlated_reset || clock.phase_dependent_routing;
574 for (std::size_t i = 0; i < agent.states.size(); ++i)
575 states.rows.push_back(StateRow{agent.name, agent.states[i],
576 unavailable ? std::numeric_limits<double>::quiet_NaN()
577 : (1 - utilization) * clock.alpha[i] + utilization * clock.busy_phases[i]});
578 }
579 }
580 for (std::size_t i = 0; i < m.queues.size(); ++i) {
581 const AgentRecord& queue = snapshot.agents[m.queues[i]];
582 auto it = m.clocks.find(queue.name);
583 if (it != m.clocks.end()) {
584 const ServiceClock& clock = it->second;
585 const AgentRecord& cagent = snapshot.agents[clock.agent];
586 for (const auto& kv : clock.routes) action_rates[cagent.name + "." + kv.first] = traffic[i] * kv.second.probability;
587 std::vector<double> reward(cagent.states.size(), 0.0);
588 for (const Transition& t : cagent.transitions)
589 if (t.action == "_phase") reward[cagent.state_index(t.source)] += t.value;
590 double x = 0.0;
591 for (std::size_t j = 0; j < reward.size(); ++j) x += clock.busy_phases[j] * reward[j];
592 action_rates[cagent.name + "._phase"] = traffic[i] * clock.mean * x;
593 } else {
594 for (const auto& r : queue.queue_info->routes) action_rates[queue.name + "." + r.first] = traffic[i] * r.second;
595 }
596 }
597}
598
599/** The clock fidelity fields shared by dec.source and marked.thinning. */
600inline void clock_fidelity(const Model& snapshot, const MapMatch& m, MamResult& res) {
601 for (std::size_t qi : m.queues) {
602 const std::string& qname = snapshot.agents[qi].name;
603 auto it = m.clocks.find(qname);
604 if (it == m.clocks.end()) continue;
605 if (it->second.phase_dependent_routing) res.phase_dependent_routing.push_back(qname);
606 if (it->second.correlated_reset) res.correlated_service_reset.push_back(qname);
607 if (it->second.correlated_reset || it->second.phase_dependent_routing)
608 res.unavailable_clock_phases.push_back(snapshot.agents[it->second.agent].name);
609 }
610 if (!res.phase_dependent_routing.empty())
611 *res.approximation += " Service-phase-dependent routing is replaced by its mean probabilities.";
612 if (!res.correlated_service_reset.empty())
613 *res.approximation += " Correlated service resets are replaced by independent PH services.";
614}
615
616inline nlohmann::json matrices_json(const MarkedMatrices& ms) {
617 nlohmann::json out = nlohmann::json::array();
618 for (const Matrix<double>& x : ms) out.push_back(matrix_json(x));
619 return out;
620}
621
622} // namespace detail
623
624/** Native MAM decomposition of a recognised MAP network (`lal_map_network.solve_composition`). */
625inline MamResult map_network(const Composition& model, double tol = 1e-4, long max_iter = 100, double max_phases = 64,
626 const std::string& traffic_method = "auto", const std::string& compress_method = "exponential",
627 double fit_time = 1.0, double fit_tolerance = .05,
628 const NativeDecSourceBackend& native_backend = NativeDecSourceBackend()) {
629 const Model snapshot = model.model();
630 validate_model(snapshot, true);
631 const auto rec = recognize_map(snapshot);
632 if (!rec.first) throw detail::mam_refusal("Model", rec.second);
633 const MapMatch& m = *rec.first;
634 double phase_order = 1.0, local_bytes = 0.0;
635 std::size_t mark_count = 0;
636 for (std::size_t a : m.sources) {
637 const AgentRecord& s = snapshot.agents[a];
638 const double n = static_cast<double>(s.states.size());
639 phase_order *= n;
640 mark_count += m.marks.at(s.name).size();
641 local_bytes += n * n * (m.marks.at(s.name).size() + 2.0) * 8;
642 }
643 if (m.queues.size() > 100 || mark_count > 64 || local_bytes > 32.0 * 1024 * 1024)
644 throw detail::mam_refusal("StateSpace", "MAP network exceeds its queue, mark or source-storage limit.");
645 std::vector<MarkedMatrices> streams;
646 std::map<std::string, std::vector<double>> source_distributions;
647 std::map<std::string, double> action_rates;
648 std::vector<std::string> source_marks;
649 double offered = 0.0;
650 for (std::size_t a : m.sources) {
651 const AgentRecord& source = snapshot.agents[a];
652 const std::vector<std::string>& marks = m.marks.at(source.name);
653 std::vector<double> phase_reward;
654 MarkedMatrices stream = detail::source_stream(source, marks, phase_reward);
655 if (detail::strong_count_positive(detail::add(stream[0], stream[1])) != 1)
656 throw detail::mam_refusal("Model", "MAP network source phase processes must be irreducible.");
657 const std::vector<double> pi = detail::stationary(detail::add(stream[0], stream[1]));
658 source_distributions[source.name] = pi;
659 double pr = 0.0;
660 for (std::size_t i = 0; i < pi.size(); ++i) pr += pi[i] * phase_reward[i];
661 action_rates[source.name + "._phase"] = pr;
662 for (std::size_t k = 0; k < marks.size(); ++k) {
663 const std::vector<double> rs = detail::row_sums(stream[k + 2]);
664 double rate = 0.0;
665 for (std::size_t i = 0; i < pi.size(); ++i) rate += pi[i] * rs[i];
666 action_rates[source.name + "." + marks[k]] = rate;
667 offered += rate;
668 source_marks.push_back(source.name + "." + marks[k]);
669 }
670 streams.push_back(stream);
671 }
672 if (offered <= 0)
673 throw detail::mam_refusal("Model", "MAP network decomposition requires a positive offered arrival rate.");
674 std::optional<Traffic> fitted_diagnostics;
675 std::string selected = traffic_method;
676 if (selected == "auto")
677 selected = phase_order <= std::min(64.0, max_phases) ? "exact" : (streams.size() > 1 ? "interpos" : "compress");
678 const bool materialize = phase_order * phase_order * (mark_count + 2.0) * 8 <= 32.0 * 1024 * 1024;
679 if (selected == "exact" && phase_order > std::min(64.0, max_phases))
680 throw detail::mam_refusal("StateSpace", "MAP network exceeds the exact source phase limit.");
681 std::optional<MarkedMatrices> aggregate;
682 if (materialize) {
683 mam::Mmap<double> combined = detail::to_mmap(streams[0]);
684 for (std::size_t k = 1; k < streams.size(); ++k) combined = mam::mmap_super(combined, detail::to_mmap(streams[k]));
685 aggregate = detail::from_mmap(combined);
686 }
687 if (selected != "exact") {
688 Traffic description;
689 description.streams = streams;
690 description.marks = source_marks;
691 const TrafficFit fit = fit_traffic(description, aggregate, selected, compress_method, fit_time, fit_tolerance);
692 Traffic d;
693 d.kind = "offered";
694 d.method = selected;
695 d.exact = false;
696 d.feasible = true;
697 d.marks = source_marks;
698 d.original_streams = streams;
699 d.original_matrices = aggregate;
700 d.fitted_matrices = fit.fitted;
701 d.fit_time = fit_time;
702 d.fit_tolerance = fit_tolerance;
704 d.fitted_rates = fit.after_rate;
707 d.rate_error = fit.rate_error;
709 if (traffic_method == "auto")
710 d.fallback_reason = "Exact source superposition has " + std::to_string(static_cast<long long>(phase_order)) + " phases.";
711 fitted_diagnostics = d;
712 aggregate = fit.fitted;
713 }
714 if (!aggregate || static_cast<double>((*aggregate)[0].rows()) > max_phases)
715 throw detail::mam_refusal("StateSpace", "MAP network traffic exceeds the configured phase limit.");
716 for (const auto& kv : m.clocks)
717 if (static_cast<double>((*aggregate)[0].rows() * snapshot.agents[kv.second.agent].states.size()) > max_phases)
718 throw detail::mam_refusal("StateSpace", "MAP/PH station exceeds the configured phase limit.");
719 const Matrix<double>& d0 = (*aggregate)[0];
720 const Matrix<double>& d1 = (*aggregate)[1];
721 const std::size_t nq = m.queues.size();
722 std::map<std::string, std::size_t> qidx;
723 for (std::size_t i = 0; i < nq; ++i) qidx[snapshot.agents[m.queues[i]].name] = i;
724 const Matrix<double> routing = detail::map_routing(snapshot, m, qidx);
725 if (detail::spectral_radius_nonneg(routing) >= 1 - 1e-12)
726 throw detail::mam_refusal("Stability", "MAP network routing must be open.");
727 std::vector<double> external(nq, 0.0);
728 external[qidx.at(*m.target)] = offered;
729 Matrix<double> system(nq, nq, 0.0);
730 for (std::size_t i = 0; i < nq; ++i)
731 for (std::size_t j = 0; j < nq; ++j) system(i, j) = (i == j ? 1.0 : 0.0) - routing(j, i);
732 std::vector<double> traffic;
733 try {
734 traffic = detail::lu_solve_vec(system, external);
735 } catch (const NumericError&) {
736 throw detail::mam_refusal("Numerical", "MAP network traffic equations are singular.");
737 }
738 for (double t : traffic)
739 if (!std::isfinite(t) || t < -1e-10)
740 throw detail::mam_refusal("Numerical", "MAP network traffic equations produced invalid rates.");
741 for (double& t : traffic) t = std::max(t, 0.0);
742 for (std::size_t i = 0; i < nq; ++i)
743 if (traffic[i] <= 0 && m.clocks.count(snapshot.agents[m.queues[i]].name))
744 throw detail::mam_refusal("Initial", "A PH station with no arrivals can retain an initial-dependent idle phase.");
745 std::vector<double> service_means(nq);
746 for (std::size_t i = 0; i < nq; ++i) {
747 const AgentRecord& q = snapshot.agents[m.queues[i]];
748 auto it = m.clocks.find(q.name);
749 service_means[i] = it != m.clocks.end() ? it->second.mean : 1.0 / *q.queue_info->service_rate;
750 }
751 std::vector<long> servers(nq);
752 for (std::size_t i = 0; i < nq; ++i) servers[i] = snapshot.agents[m.queues[i]].queue_info->servers;
753 for (std::size_t i = 0; i < nq; ++i)
754 if (traffic[i] * service_means[i] >= static_cast<double>(servers[i]) * (1 - 1e-12))
755 throw detail::mam_refusal("Stability", "A MAP network queue is unstable or critically loaded.");
756 const bool fitted = fitted_diagnostics && offered > 0;
757 std::vector<double> fitted_traffic;
758 if (fitted) {
759 double fitted_total = 0.0;
760 for (double r : fitted_diagnostics->fitted_rates) fitted_total += r;
761 for (std::size_t i = 0; i < nq; ++i) fitted_traffic.push_back(traffic[i] * (fitted_total / offered));
762 for (std::size_t i = 0; i < nq; ++i)
763 if (fitted_traffic[i] * service_means[i] >= static_cast<double>(servers[i]) * (1 - 1e-12))
764 throw detail::mam_refusal("Stability", "Traffic fitting makes a MAP network queue unstable.");
765 }
766 // The lowered network runs on a time scale of order one; its throughputs
767 // are multiplied back below and its queue lengths are scale-free.
768 double native_scale = std::max(detail::max_abs(d0), detail::max_abs(d1));
769 for (std::size_t i = 0; i < nq; ++i) {
770 const AgentRecord& q = snapshot.agents[m.queues[i]];
771 auto it = m.clocks.find(q.name);
772 native_scale = std::max(native_scale, it != m.clocks.end() ? detail::max_abs(it->second.T) : *q.queue_info->service_rate);
773 }
774 if (!std::isfinite(native_scale) || native_scale <= 0)
775 throw detail::mam_refusal("Numerical", "MAP network has an invalid time scale.");
776 std::vector<std::pair<std::optional<std::pair<std::vector<double>, Matrix<double>>>, double>> services;
777 for (std::size_t i = 0; i < nq; ++i) {
778 const AgentRecord& q = snapshot.agents[m.queues[i]];
779 auto it = m.clocks.find(q.name);
780 if (it != m.clocks.end())
781 services.push_back({std::make_pair(it->second.alpha, detail::scaled(it->second.T, 1.0 / native_scale)), 0.0});
782 else
783 services.push_back({std::nullopt, *q.queue_info->service_rate / native_scale});
784 }
785 const auto native = detail::run_native_dec_source(native_backend, detail::scaled(d0, 1.0 / native_scale),
786 detail::scaled(d1, 1.0 / native_scale), services, servers, routing,
787 qidx.at(*m.target), "LAL_MAP_Network", "LALQueue", tol, max_iter,
788 max_phases);
789 MamResult res;
790 QueueTable qt;
791 for (std::size_t i = 0; i < nq; ++i) {
792 const double qlen = native.first[i];
793 if (!std::isfinite(qlen) || qlen < 0)
794 throw detail::mam_refusal("Numerical", "Native MAM decomposition returned an invalid queue length.");
795 const double native_throughput = native.second[i] * native_scale;
796 const double expected_throughput = fitted ? fitted_traffic[i] : traffic[i];
797 const double throughput_scale = std::max(std::fabs(expected_throughput), detail::tiny());
798 if (!std::isfinite(native_throughput) || std::fabs(native_throughput - expected_throughput) > 1e-6 * throughput_scale)
799 throw detail::mam_refusal("Numerical", "Native MAM decomposition did not preserve the station traffic rate.");
800 // The flow rates and mean busy fraction follow exactly from conservation
801 // and exponential service, independently of the queue approximation.
802 const double utilization = traffic[i] * service_means[i] / static_cast<double>(servers[i]);
803 const double busy = servers[i] == 1 ? utilization : std::numeric_limits<double>::quiet_NaN();
804 const double response = traffic[i] > 0 ? qlen / traffic[i] : std::numeric_limits<double>::quiet_NaN();
805 qt.rows.push_back(QueueRow{snapshot.agents[m.queues[i]].name, qlen, busy, utilization, traffic[i], traffic[i], response});
806 }
807 detail::clock_rows_and_rates(snapshot, m, traffic, qidx, source_distributions, action_rates, res.state_table);
808 for (const std::string& label : detail::active_labels(snapshot))
809 res.action_table.rows.push_back(ActionRow{label, detail::rate_of(action_rates, label)});
810 const bool truncated = model.source_truncated;
811 for (TableAttrs* at : {&res.state_table.attrs, &res.action_table.attrs, &qt.attrs}) {
812 at->method = "dec.source";
813 at->exact = false;
814 at->truncated = truncated;
815 }
816 double residual = 0.0;
817 for (std::size_t i = 0; i < nq; ++i) {
818 double r = traffic[i] - external[i];
819 for (std::size_t j = 0; j < nq; ++j) r -= routing(j, i) * traffic[j];
820 residual = std::max(residual, std::fabs(r));
821 }
822 res.method = "dec.source";
823 res.exact = false;
824 res.truncated = truncated;
825 res.residual = residual;
826 res.queue_measures = qt;
827 if (fitted_diagnostics) {
828 res.traffic = fitted_diagnostics;
829 res.fallback_reason = fitted_diagnostics->fallback_reason;
830 } else {
831 Traffic t;
832 t.kind = "offered";
833 t.method = "mmap_super";
834 t.exact = true;
835 t.marks = source_marks;
836 t.original_streams = streams;
837 t.matrices = aggregate;
838 res.traffic = t;
839 }
840 res.extra["native_method"] = "dec.source";
841 res.native_time_scale = native_scale;
842 res.residual_kind = "traffic_balance";
843 res.approximation = std::string("Native MAM network decomposition; queue-state distributions unavailable.");
844 detail::clock_fidelity(snapshot, m, res);
845 for (std::size_t i = 0; i < nq; ++i)
846 if (servers[i] > 1) res.unavailable_busy_probabilities.push_back(snapshot.agents[m.queues[i]].name);
847 res.has_converged = false; // Python reports converged = None: the native analyzer exposes no certificate
848 res.native_internal_fitting = "not exposed by native dec.source";
849 res.extra["tolerance"] = tol;
850 res.extra["max_iterations"] = max_iter;
851 res.source_matrices = {MarkedMatrices{d0, d1}};
852 res.source_marks = source_marks;
853 res.extra["routing"] = detail::matrix_json(routing);
854 res.extra["queue_rates"] = traffic;
855 return res;
856}
857
858} // namespace lal
859} // namespace line
860
861#endif
std::size_t size() const
Definition matrix.h:91
Matrix transpose() const
Definition matrix.h:110
The algorithm cannot produce a trustworthy answer on this instance: LINE:numerical:<kind>.
Definition error.h:110
A collection of agents and embedded LINE models with atomic synchronisations (Composition).
Definition builder.h:655
Model model(const std::vector< Sync > *syncs=nullptr, const std::vector< ExtSync > *ext_syncs=nullptr) const
The current model snapshot (_model).
Definition builder.h:906
The distributions a user names, spelled as their Python twins.
Port of solver_mam_analyzer.m: one inner solve, choosing the analyzer that fits the model and the req...
LINE Agent Language (LAL): lossless lowering of open exponential LAL networks to scalar M/M/c factors...
LINE Agent Language (LAL): independent marked arrival proposals of a finite composition and their exp...
Definition ag.h:49
std::pair< std::optional< MapMatch >, std::string > recognize_parallel(const Model &snapshot)
Recognise independent stations with shared marked sources (lal_parallel_qbd.recognize).
std::vector< Matrix< double > > MarkedMatrices
A marked process as Python's list [D0, D1, D1_1, ..., D1_K].
Definition mam_common.h:54
std::pair< std::string, std::string > Endpoint
(agent, action).
Definition core.h:139
std::vector< Event > selected(const std::vector< Event > &events)
Apply maximal progress and immediate priorities to the enabled events (selected).
Definition core.h:746
TrafficFit fit_traffic(const Traffic &traffic, const std::optional< MarkedMatrices > &original, const std::string &method, const std::string &compress_method, double fit_time, double fit_tolerance, const TrafficFitBackend &backend=TrafficFitBackend())
Fit offered marked streams and enforce a finite-time counting budget (fit_traffic).
std::pair< std::optional< MapMatch >, std::string > recognize_map(const Model &snapshot, bool allow_split=false)
Recognise a restricted open MAP/PH network (lal_map_network.recognize).
void validate_model(const Model &model, bool allow_unbounded=false)
Validate the common agent model used by both frontends (validate_model).
Definition core.h:550
std::function< std::pair< std::vector< double >, std::vector< double > >(const Matrix< double > &, const Matrix< double > &, const NativeServices &, const std::vector< long > &, const Matrix< double > &, std::size_t, const std::string &, const std::string &, double, long, double)> NativeDecSourceBackend
The native dec.source solve behind map_network and marked_thinning (Python's SolverMAM(network,...
std::vector< std::pair< std::optional< std::pair< std::vector< double >, Matrix< double > > >, double > > NativeServices
Per-queue service law handed to the native dec.source solve: a PH (alpha, T) or, when empty,...
MamResult map_network(const Composition &model, double tol=1e-4, long max_iter=100, double max_phases=64, const std::string &traffic_method="auto", const std::string &compress_method="exponential", double fit_time=1.0, double fit_tolerance=.05, const NativeDecSourceBackend &native_backend=NativeDecSourceBackend())
Native MAM decomposition of a recognised MAP network (lal_map_network.solve_composition).
MamSolution< T > mam_dispatch(const qn::NetworkStruct< T > &L, const MamOptions &opt_in)
The ladder.
Mmap< T > mmap_super(const Mmap< T > &a, const Mmap< T > &b)
Superposition of two MMAPs: the phase process is the product chain, and the class list of the result ...
Definition mmap_lambda.h:88
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
void lu_solve(const Matrix< T > &LU, const std::vector< std::size_t > &piv, std::vector< T > &b)
Solve LUx = Pb in place on b, using the factors from lu_factor.
Definition lu.h:94
lang::Distrib< double > Dist
Definition nodes.h:54
std::vector< std::size_t > lu_factor(Matrix< T > &A)
In-place LU of A (n x n).
Definition lu.h:48
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...
One row of an action table: Action, Throughput.
Definition ctmc.h:62
std::vector< ActionRow > rows
Definition ctmc.h:80
TableAttrs attrs
Definition ctmc.h:81
The immutable agent record (core.Agent).
Definition core.h:284
std::string name
Definition core.h:285
std::vector< Transition > transitions
Definition core.h:288
std::vector< std::string > states
Definition core.h:286
std::optional< QueueInfo > queue_info
Definition core.h:292
std::size_t state_index(const std::string &s) const
Zero-based index of a local state, or npos.
Definition core.h:302
One routed completion mark of a PH service clock.
std::optional< std::string > target
std::vector< Endpoint > partners
The union of Python's LAL MAM result dataclasses.
Definition mam_common.h:118
nlohmann::json extra
Definition mam_common.h:148
std::optional< std::string > approximation
Definition mam_common.h:137
std::optional< QueueTable > queue_measures
Definition mam_common.h:127
std::vector< std::string > phase_dependent_routing
Definition mam_common.h:140
std::vector< MarkedMatrices > source_matrices
Definition mam_common.h:139
std::optional< Traffic > traffic
Definition mam_common.h:126
std::optional< std::string > residual_kind
Definition mam_common.h:121
nlohmann::json native_internal_fitting
null: absent
Definition mam_common.h:147
bool has_converged
whether the lowering reports converged at all
Definition mam_common.h:149
std::optional< double > native_time_scale
dec.source: factor dividing the lowered network's rates
Definition mam_common.h:144
std::vector< std::string > correlated_service_reset
Definition mam_common.h:141
std::vector< std::string > unavailable_clock_phases
Definition mam_common.h:142
std::vector< std::string > unavailable_busy_probabilities
multiserver queues: Busy is NaN
Definition mam_common.h:143
std::vector< std::string > source_marks
Definition mam_common.h:138
The recognised MAP network (lal_map_network.recognize tuple).
std::vector< std::size_t > queues
std::map< std::string, std::vector< std::string > > marks
std::vector< std::size_t > sources
std::map< std::string, ServiceClock > clocks
keyed by queue name
std::optional< std::string > target
std::map< Endpoint, std::string > sync
A minimum-rate synchronisation: at least two active endpoints and optional passive ones.
Definition core.h:258
A composition snapshot (core.Model): agents in declaration order plus synchronisations.
Definition core.h:310
std::vector< MinSync > min_syncs
Definition core.h:313
bool has_agent(const std::string &name) const
Definition core.h:323
std::vector< Sync > syncs
Definition core.h:312
std::size_t index_of(const std::string &name) const
Definition core.h:318
std::vector< AgentRecord > agents
Definition core.h:311
const AgentRecord & agent(const std::string &name) const
Definition core.h:324
Structured queue declaration retained while a queue agent is unmodified (queue_info).
Definition core.h:271
std::optional< std::string > service_phase
Definition core.h:278
std::vector< std::string > service_inputs
Definition core.h:277
One row of getQueueTable(): Agent, QLen, Busy, Util, ArvR, Tput, RespT.
Definition mam_common.h:96
std::vector< QueueRow > rows
Definition mam_common.h:107
std::string method
Definition ctmc.h:97
bool truncated
Definition ctmc.h:99
ActionTable action_table
Definition ctmc.h:104
StateTable state_table
Definition ctmc.h:103
std::optional< std::string > fallback_reason
Definition ctmc.h:100
A PH service clock driving a queue (the clocks[q] dictionary).
std::vector< double > alpha
std::size_t agent
agent index of the clock
std::vector< double > busy_phases
std::vector< std::pair< std::string, ClockRoute > > routes
mark -> route, in service-input order
One row of a state table: Agent, State, Probability.
Definition ctmc.h:55
TableAttrs attrs
Definition ctmc.h:69
std::vector< StateRow > rows
Definition ctmc.h:68
An ordinary synchronisation: one active endpoint, hand passives and injected node arrivals.
Definition core.h:250
Endpoint active
Definition core.h:251
std::vector< Endpoint > passive
Definition core.h:252
The attrs of a LAL result table.
Definition ctmc.h:46
Output of fit_traffic.
MarkedMatrices fitted
Matrix< double > before_cov
Matrix< double > after_cov
std::vector< double > before_rate
std::vector< double > after_rate
The traffic dictionary of a MAM result (result.traffic).
Definition mam_common.h:67
std::string method
Definition mam_common.h:69
std::optional< MarkedMatrices > fitted_matrices
Definition mam_common.h:81
std::string kind
Definition mam_common.h:68
std::optional< double > fit_tolerance
Definition mam_common.h:83
std::optional< Matrix< double > > original_count_covariance
Definition mam_common.h:86
std::optional< Matrix< double > > fitted_count_covariance
Definition mam_common.h:87
std::vector< std::string > marks
Definition mam_common.h:74
std::vector< MarkedMatrices > original_streams
Definition mam_common.h:80
std::vector< double > fitted_rates
Definition mam_common.h:85
std::optional< std::string > fallback_reason
Definition mam_common.h:91
std::optional< MarkedMatrices > matrices
Definition mam_common.h:77
std::optional< double > rate_error
Definition mam_common.h:88
std::optional< MarkedMatrices > original_matrices
Definition mam_common.h:79
std::optional< double > fit_time
Definition mam_common.h:82
std::optional< double > count_covariance_error
Definition mam_common.h:89
std::vector< double > original_rates
Definition mam_common.h:84
std::vector< MarkedMatrices > streams
Definition mam_common.h:76
std::optional< bool > feasible
Definition mam_common.h:72
One labelled local transition source --(action, value)--> target.
Definition core.h:111
std::string target
Definition core.h:116
std::string source
Definition core.h:112
std::string action
Definition core.h:113
static Distrib exp_rate(const double &r)
static Distrib phase_type(const std::vector< double > &alpha, const Matrix< double > &A, bool acyclic)
static Distrib map_dist(const Matrix< double > &D0, const Matrix< double > &D1, ProcessType tag)
An MMAP: the underlying MAP plus the per-class arrival matrices.
Definition mmap_lambda.h:45