5#ifndef LINE_LANG_LAL_SOLVER_MAM_H
6#define LINE_LANG_LAL_SOLVER_MAM_H
64 long max_iter = 100,
double tol = 1e-4);
79 nlohmann::json
config = nlohmann::json::object();
81 double timeout = std::numeric_limits<double>::infinity();
82 std::string
lang =
"python";
83 std::optional<std::string>
arith;
85 std::optional<nlohmann::json>
cutoff;
95 std::string
key()
const {
96 std::ostringstream os;
113 static const std::set<std::string> fields{
114 "method",
"tol",
"max_iter",
"space_max",
"config",
"verbose",
"timeout",
"lang",
"arith",
115 "lal_max_phases",
"lal_max_states",
"lal_level_agent",
"lal_traffic_method",
"lal_compress_method",
116 "lal_fit_time",
"lal_fit_tolerance"};
117 if (!kwargs.is_null() && !kwargs.is_object())
throw InputError(
"SolverMAM keyword arguments must be an object");
118 std::set<std::string> unknown;
119 if (kwargs.is_object())
120 for (
auto it = kwargs.begin(); it != kwargs.end(); ++it)
121 if (!fields.count(it.key())) unknown.insert(it.key());
122 if (!unknown.empty()) {
124 for (
const std::string& u : unknown) joined += (joined.empty() ?
"" :
", ") + u;
129 if (!kwargs.is_object())
return o;
130 auto opt_str = [&](
const char* k) -> std::optional<std::string> {
131 const nlohmann::json& v = kwargs.at(k);
132 if (v.is_null())
return std::nullopt;
133 return v.get<std::string>();
135 for (
auto it = kwargs.begin(); it != kwargs.end(); ++it) {
136 const std::string& k = it.key();
137 const nlohmann::json& v = it.value();
138 if (k ==
"method")
continue;
139 if (k ==
"tol") o.
tol = v.get<
double>();
140 else if (k ==
"max_iter") o.
max_iter = v.get<
long>();
141 else if (k ==
"space_max") o.
space_max = v.get<
long>();
142 else if (k ==
"config") o.
config = v;
143 else if (k ==
"verbose") o.
verbose = v.get<
bool>();
144 else if (k ==
"timeout") o.
timeout = v.get<
double>();
145 else if (k ==
"lang") o.
lang = v.get<std::string>();
146 else if (k ==
"arith") o.
arith = opt_str(
"arith");
147 else if (k ==
"lal_max_phases") o.
lal_max_phases = v.is_boolean() ? -1.0 : v.get<
double>();
148 else if (k ==
"lal_max_states") o.
lal_max_states = v.is_boolean() ? -1.0 : v.get<
double>();
149 else if (k ==
"lal_level_agent") o.
lal_level_agent = opt_str(
"lal_level_agent");
152 else if (k ==
"lal_fit_time") o.
lal_fit_time = v.get<
double>();
161inline nlohmann::json num_json(
double x) {
162 if (std::isfinite(x) && x == std::floor(x) && std::fabs(x) < 9e15)
return static_cast<long long>(x);
167inline std::string int_str(
double x) {
168 if (std::isfinite(x) && std::fabs(x) < 9e18)
return std::to_string(
static_cast<long long>(x));
170 std::snprintf(buf,
sizeof(buf),
"%.0f", x);
174inline nlohmann::json opt_json(
const std::optional<std::string>& s) {
175 return s ? nlohmann::json(*s) : nlohmann::json(nullptr);
178inline nlohmann::json opt_marked_json(
const std::optional<MarkedMatrices>& m) {
179 return m ? matrices_json(*m) : nlohmann::json(nullptr);
183inline nlohmann::json traffic_json(
const Traffic& t) {
184 nlohmann::json j = t.extra.is_object() ? t.extra : nlohmann::json::object();
186 j[
"method"] = t.method;
187 if (t.compression) j[
"compression"] = *t.compression;
188 j[
"exact"] = t.exact;
189 if (t.feasible) j[
"feasible"] = *t.feasible;
190 j[
"sources"] = t.sources;
191 j[
"marks"] = t.marks;
192 if (!t.targets.empty()) j[
"targets"] = t.targets;
193 if (!t.streams.empty()) {
194 nlohmann::json s = nlohmann::json::array();
195 for (
const MarkedMatrices& m : t.streams) s.push_back(matrices_json(m));
198 j[
"matrices"] = opt_marked_json(t.matrices);
199 if (t.blocking) j[
"blocking"] = *t.blocking;
200 if (t.kind !=
"offered" || t.original_matrices || !t.original_streams.empty() || t.fitted_matrices) {
201 j[
"original_matrices"] = opt_marked_json(t.original_matrices);
202 nlohmann::json s = nlohmann::json::array();
203 for (
const MarkedMatrices& m : t.original_streams) s.push_back(matrices_json(m));
204 j[
"original_streams"] = s;
205 j[
"fitted_matrices"] = opt_marked_json(t.fitted_matrices);
207 if (t.fit_time) j[
"fit_time"] = *t.fit_time;
208 if (t.fit_tolerance) j[
"fit_tolerance"] = *t.fit_tolerance;
209 if (!t.original_rates.empty()) j[
"original_rates"] = t.original_rates;
210 if (!t.fitted_rates.empty()) j[
"fitted_rates"] = t.fitted_rates;
211 if (t.original_count_covariance) j[
"original_count_covariance"] = matrix_json(*t.original_count_covariance);
212 if (t.fitted_count_covariance) j[
"fitted_count_covariance"] = matrix_json(*t.fitted_count_covariance);
213 if (t.rate_error) j[
"rate_error"] = *t.rate_error;
214 if (t.count_covariance_error) j[
"count_covariance_error"] = *t.count_covariance_error;
215 if (t.unavailable) j[
"unavailable"] = *t.unavailable;
216 if (t.fallback_reason) j[
"fallback_reason"] = *t.fallback_reason;
220inline bool positive_integer(
double x) {
return std::isfinite(x) && x > 0 && x == std::floor(x); }
222inline bool in_list(
const std::string& x, std::initializer_list<const char*> list) {
223 for (
const char* s : list)
224 if (x == s)
return true;
236 typedef std::function<
MamResult(
const Composition&,
double,
double,
const std::optional<std::string>&)>
258 return {
"default",
"finiteqbd",
"reachableqbd",
"infiniteqbd",
"jackson",
"dec.source",
"parallelqbd",
"marked.thinning"};
272 if (lowering_reason_)
return {
false, *lowering_reason_};
273 const Model snapshot = model_->model();
276 return {
false,
"lal_max_phases and lal_max_states must be positive integers."};
279 return {
false,
"SolverMAM LAL methods recognize timed hand-declared agents only; the composition uses " +
280 (features.empty() ? std::string(
"discrete-time") : detail::join_sorted(features)) +
282 std::vector<std::size_t> unbounded;
283 for (std::size_t a = 0; a < snapshot.
agents.size(); ++a)
284 if (snapshot.
agents[a].unbounded_queue) unbounded.push_back(a);
285 const bool traffic_ok = detail::in_list(o.
lal_traffic_method, {
"auto",
"exact",
"compress",
"interpos"});
286 const char* traffic_msg =
"lal_traffic_method must be auto, exact, compress or interpos.";
287 if (!unbounded.empty()) {
288 if (unbounded.size() > 1 || method ==
"jackson") {
289 if (!detail::in_list(method, {
"default",
"jackson",
"dec.source",
"parallelqbd",
"marked.thinning"}))
290 return {
false,
"Multiple unbounded queues require jackson, dec.source, parallelqbd or marked.thinning."};
291 if (o.
lal_level_agent)
return {
false,
"This network lowering does not select a single level agent."};
292 if (!traffic_ok)
return {
false, traffic_msg};
294 const std::string jackson_reason = jr.second;
295 if (!detail::in_list(method, {
"dec.source",
"parallelqbd",
"marked.thinning"}) && jr.first) {
297 return {
false,
"Jackson lowering does not use marked-traffic fitting."};
300 if (method ==
"jackson")
return {
false, jr.second};
302 const std::string map_reason = mr.second;
303 if (method ==
"dec.source")
return {mr.first.has_value(), mr.second};
305 std::string parallel_reason = pr.second;
306 if (method !=
"marked.thinning" && pr.first) {
308 if (method ==
"parallelqbd")
return {
false,
"Parallel QBD currently requires exact source phases."};
310 if (method ==
"parallelqbd")
return {
false, parallel_reason};
311 if (method !=
"marked.thinning" && mr.first)
return {
true,
""};
313 std::string reason = sr.second;
314 if (!sr.first && method ==
"default") {
317 if (pr.first) parallel_reason =
"Parallel QBD currently requires exact source phases.";
318 reason =
"No LAL network lowering applies. jackson: " + jackson_reason +
" dec.source: " + map_reason +
319 " parallelqbd: " + parallel_reason +
" marked.thinning: " + reason;
321 return {sr.first.has_value(), reason};
324 return {
false,
"Infinite QBD requires the unbounded queue as its selected level."};
325 if (method !=
"default" && method !=
"infiniteqbd")
326 return {
false,
"Unbounded LAL queues support the infiniteqbd MAM method."};
327 if (!traffic_ok)
return {
false, traffic_msg};
330 if (!detail::in_list(method, {
"default",
"finiteqbd",
"reachableqbd"}))
331 return {
false,
"Finite LAL compositions support the finiteqbd and reachableqbd MAM methods."};
332 if (method ==
"reachableqbd" && !detail::in_list(o.
lal_traffic_method, {
"auto",
"exact"}))
333 return {
false,
"reachableqbd does not use traffic reduction."};
334 if (!traffic_ok)
return {
false, traffic_msg};
338 return {st.first.has_value(), st.second};
349 if (o.
timeout != std::numeric_limits<double>::infinity())
352 throw InputError(
"LAL MAM tol and max_iter must be finite and positive");
353 const Model snapshot = model_->model();
355 std::vector<std::size_t> unbounded;
356 for (std::size_t a = 0; a < snapshot.
agents.size(); ++a)
357 if (snapshot.
agents[a].unbounded_queue) unbounded.push_back(a);
358 const bool has_unbounded = !unbounded.empty();
360 std::optional<std::string> fallback_reason;
361 std::optional<MamResult> reachable_result;
362 const bool use_network = unbounded.size() > 1 ||
363 detail::in_list(o.
method, {
"jackson",
"dec.source",
"parallelqbd",
"marked.thinning"});
364 bool jackson_match =
false, map_match =
false, parallel_match =
false;
370 auto network_fallback = [&](
bool map) {
376 auto level_of = [&]() -> std::string {
377 if (has_unbounded)
return snapshot.
agents[unbounded[0]].name;
379 if (!st.first)
throw detail::mam_refusal(
"Model", st.second);
382 if (use_network && (o.
method ==
"jackson" || (o.
method ==
"default" && jackson_match))) {
384 }
else if (use_network && (o.
method ==
"parallelqbd" ||
385 (o.
method ==
"default" && parallel_match &&
390 if (o.
method !=
"default" || exc.
id() !=
"LINE:unsupported:StateSpace")
throw;
392 fallback_reason = std::string(
"Exact parallel QBD exceeded a resource limit: ") + exc.what();
393 reachable_result = network_fallback(map_match);
395 }
else if (use_network && (o.
method ==
"marked.thinning" || (o.
method ==
"default" && !map_match))) {
396 reachable_result = network_fallback(
false);
397 }
else if (use_network) {
398 reachable_result = network_fallback(
true);
399 }
else if (!has_unbounded && o.
method ==
"reachableqbd") {
401 }
else if (traffic_method ==
"auto") {
402 const std::string level = level_of();
403 double phase_count = 1.0;
405 if (a.
name != level) phase_count *=
static_cast<double>(a.
states.size());
406 const double boundary = phase_count *
static_cast<double>(snapshot.
agent(level).states.size());
408 fallback_reason =
"Exact QBD requires " + detail::int_str(phase_count) +
" phases and " +
409 detail::int_str(boundary) +
" boundary states, exceeding configured limits.";
410 if (!has_unbounded) {
414 if (exc.
id() !=
"LINE:unsupported:StateSpace")
throw;
417 if (!reachable_result) traffic_method = snapshot.
agents.size() > 2 ?
"interpos" :
"compress";
419 traffic_method =
"exact";
423 if (reachable_result) {
424 result = std::move(*reachable_result);
425 }
else if (has_unbounded && traffic_method ==
"exact") {
427 }
else if (traffic_method ==
"exact") {
431 const std::string msg = exc.what();
432 if (o.
method !=
"default" ||
433 (msg.find(
"unique closed class") == std::string::npos && exc.
id() !=
"LINE:unsupported:Numerical"))
436 fallback_reason =
"Cartesian QBD could not be used (" + msg +
"); restricted to initial reachability.";
444 if (fallback_reason) {
445 if (result.
traffic) result.
traffic->fallback_reason = fallback_reason;
461 "The LAL model or solver options changed during MAM analysis; retry with a stable snapshot.");
463 result_ = std::move(result);
496 const std::optional<std::string>& jobclass = std::nullopt,
497 const std::optional<std::string>& mode = std::nullopt) {
498 return getAvgAct(ActionSpec::key(node, event, jobclass, mode));
501 return getAvgAct(ActionSpec::key(node, event, jobclass));
504 std::vector<double>
getActAvg(
const std::vector<ActionSpec>& actions) {
505 std::vector<double> out;
506 for (
const ActionSpec& a : actions) out.push_back(
getAvgAct(a));
517 const Model snapshot = model_->model();
518 std::map<Endpoint, std::string> events;
532 double busy = 0.0, occupancy = 0.0, busy_servers = 0.0;
534 if (row.agent != agent.
name)
continue;
535 const bool tail = row.state.compare(0, 5,
"n_ge_") == 0;
536 const long n = std::stol(tail ? row.state.substr(5) : row.state.substr(2));
537 if (!tail) occupancy +=
static_cast<double>(n) * row.probability;
538 if (n) busy += row.probability;
539 busy_servers +=
static_cast<double>(std::min(n, info.
servers)) * row.probability;
545 std::vector<std::string> arrivals, departures;
546 for (
const std::string& a : info.
arrivals) {
548 if (it != events.end()) arrivals.push_back(it->second);
550 for (
const std::string& a : info.
departures) {
552 departures.push_back(it != events.end() ? it->second : agent.
name +
"." + a);
556 if (it != events.end()) departures.push_back(it->second);
561 auto throughput = [&](
const std::vector<std::string>& labels) {
562 std::set<std::string> seen;
564 for (
const std::string& l : labels)
565 if (seen.insert(l).second) total += action_values.
throughput(l);
568 const double arrival_rate = throughput(arrivals), departure_rate = throughput(departures);
573 q.
util = busy_servers /
static_cast<double>(info.
servers);
574 q.
arvr = arrival_rate;
575 q.
tput = departure_rate;
576 q.
respt = departure_rate > 0 ? occupancy / departure_rate : std::numeric_limits<double>::quiet_NaN();
577 table.rows.push_back(q);
579 table.attrs.method = r.
method;
580 table.attrs.exact = r.
exact;
591 const Model snapshot = model_->model();
592 std::size_t unbounded_count = 0;
595 const bool has_unbounded = unbounded_count > 0;
596 bool jackson_sel =
false, map_sel =
false, parallel_sel =
false, marked_sel =
false;
597 if (unbounded_count > 1 || detail::in_list(o.
method, {
"jackson",
"dec.source",
"parallelqbd",
"marked.thinning"})) {
598 jackson_sel = !detail::in_list(o.
method, {
"dec.source",
"parallelqbd",
"marked.thinning"}) &&
601 parallel_sel = !detail::in_list(o.
method, {
"dec.source",
"marked.thinning"}) &&
602 detail::in_list(traffic_method, {
"auto",
"exact"}) &&
605 map_sel = !detail::in_list(o.
method, {
"parallelqbd",
"marked.thinning"}) &&
607 marked_sel = !map_sel;
611 nlohmann::json c = nlohmann::json::object();
613 c[
"requested_method"] = o.
method;
615 c[
"selected_method"] = jackson_sel ?
"jackson"
616 : map_sel ?
"dec.source"
617 : parallel_sel ?
"parallelqbd"
618 : marked_sel ?
"marked.thinning"
619 : has_unbounded ?
"infiniteqbd"
620 : (o.
method ==
"reachableqbd" ?
"reachableqbd" :
"finiteqbd");
621 c[
"exactness"] = (map_sel || marked_sel) ?
"approximate"
622 : detail::in_list(traffic_method, {
"exact",
"auto"}) ?
"conditional"
625 c[
"selected_method"] =
nullptr;
626 c[
"exactness"] =
nullptr;
628 c[
"supported"] = ok.first;
629 c[
"reason"] = ok.second;
630 std::vector<std::string> conditions{
"Events change the selected level by at most one.",
631 "The block system is numerically solvable."};
632 if (marked_sel || jackson_sel || map_sel || parallel_sel)
633 conditions.push_back(
"Routing is open and every queue is stable.");
634 else if (has_unbounded)
635 conditions.push_back(
"The homogeneous phase process has one closed class and negative drift.");
637 conditions.push_back(
"The Cartesian method requires a unique closed class; reachableqbd handles multiple classes.");
638 c[
"conditions"] = conditions;
639 std::vector<std::string> transformations;
640 if (marked_sel) transformations = {
"visit_thinning",
"poisson_feedback_if_needed"};
641 else if (map_sel) transformations = {
"native_queue_decomposition"};
642 if (traffic_method !=
"exact") transformations.push_back(traffic_method);
643 c[
"transformations"] = transformations;
645 c[
"measures"] = {
"agent-state probabilities",
"labelled action throughputs",
646 "structured queue occupancy, utilization and throughput"};
647 const std::vector<std::string> fitted_unavailable{
"original source phase probabilities if fitted",
648 "original source internal action throughputs if fitted"};
649 if (map_sel || marked_sel) c[
"unavailable"] = {
"queue-state distributions",
"convergence certificate"};
650 else if (parallel_sel) c[
"unavailable"] = {
"joint queue-state distribution"};
651 else if (traffic_method ==
"exact") c[
"unavailable"] = nlohmann::json::array();
652 else c[
"unavailable"] = fitted_unavailable;
653 if (ok.first && result_ && signature_ && *signature_ == key_()) {
655 c[
"selected_method"] = r.
method;
656 c[
"exactness"] = r.
exact ?
"exact" :
"approximate";
658 if (r.
method ==
"dec.source" || r.
method ==
"marked.thinning") {
659 nlohmann::json u = {
"queue-state distributions",
"convergence certificate"};
662 c[
"unavailable"] = u;
663 }
else if (r.
method ==
"parallelqbd") {
664 c[
"unavailable"] = {
"joint queue-state distribution"};
666 c[
"unavailable"] = fitted_unavailable;
668 c[
"unavailable"] = nlohmann::json::array();
670 if (r.
method ==
"marked.thinning") c[
"transformations"] = {
"visit_thinning",
"poisson_feedback_if_needed"};
687 nlohmann::json d = nlohmann::json::object();
689 d[
"exact"] = r.
exact;
694 d[
"traffic"] = r.
traffic ? detail::traffic_json(*r.
traffic) : nlohmann::json(
nullptr);
696 d[
"converged"] =
nullptr;
706 const Model snapshot = model_->model();
711 nlohmann::json states = nlohmann::json::array(), actions = nlohmann::json::array();
712 const double nan = std::numeric_limits<double>::quiet_NaN();
713 double max_state = nan, max_action = nan;
714 long compared_states = 0, missing_states = 0, compared_actions = 0, missing_actions = 0;
720 {
"Probability_ctmc", c.
probability}, {
"AbsoluteError", err}});
721 if (std::isnan(err)) ++missing_states;
724 if (std::isnan(max_state) || err > max_state) max_state = err;
729 if (m.action != c.action)
continue;
730 const double err = std::fabs(m.throughput - c.throughput);
731 actions.push_back({{
"Action", m.action}, {
"Throughput_mam", m.throughput},
732 {
"Throughput_ctmc", c.throughput}, {
"AbsoluteError", err}});
733 if (std::isnan(err)) ++missing_actions;
736 if (std::isnan(max_action) || err > max_action) max_action = err;
739 d[
"ctmc_comparison"] = {{
"states", states},
740 {
"actions", actions},
741 {
"max_state_error", max_state},
742 {
"max_action_error", max_action},
743 {
"compared_state_rows", compared_states},
744 {
"unavailable_state_rows", missing_states},
745 {
"compared_action_rows", compared_actions},
746 {
"unavailable_action_rows", missing_actions},
747 {
"reference_states", reference.
states.size()}};
765 finite_backend_ = std::move(backend);
775 native_backend_ = std::move(backend);
782 std::shared_ptr<Composition> lowered_;
783 std::map<std::string, std::string> lowered_labels_;
784 std::optional<std::string> lowering_reason_;
791 void init_lowering_() {
792 if (original_->
embedded().empty())
return;
795 lowered_ = std::make_shared<Composition>(lc.
composition);
796 lowered_labels_ = lc.
labels;
797 model_ = lowered_.get();
799 lowering_reason_ = exc.what();
803 FiniteQBDBackend finite_backend_ = [](
const Composition& m,
double phases,
double states,
804 const std::optional<std::string>& level) {
808 std::optional<MamResult> result_;
809 std::optional<std::string> signature_;
811 std::string key_()
const {
812 return signature(model_->model()) +
"|" + (model_->source_truncated ?
"T" :
"F") +
"|" +
options.
key();
815 const MamResult& ensure_() {
816 if (!result_ || !signature_ || *signature_ != key_())
runAnalyzer();
LINE Agent Language (LAL): programmatic construction of finite agents and their composition,...
const std::string & id() const noexcept
The full identifier, e.g.
A refusal: the feature, method or analysis is not covered: LINE:unsupported:<kind>.
UnsupportedError(const std::string &what)
A collection of agents and embedded LINE models with atomic synchronisations (Composition).
const std::vector< std::shared_ptr< EmbeddedPart > > & embedded() const
double getAvgAct(const std::string &node, lang::EventType event, const std::optional< std::string > &jobclass=std::nullopt, const std::optional< std::string > &mode=std::nullopt)
ActionTable getActionTable()
SolverMAM & runAnalyzer()
Run the selected lowering and store the result (runAnalyzer).
double getAvgAct(std::size_t node, lang::EventType event, std::size_t jobclass=0)
void setFiniteQBDBackend(FiniteQBDBackend backend)
Replace the Cartesian finite-QBD backend (Python tests monkeypatch it).
ActionTable getActTable()
Labelled event throughputs (getActTable and its aliases).
double getAvgAct(const ActionSpec &action)
Throughput of one LAL action (named as in SolverCTMC::getAvgAct, against the original composition).
SolverMAM(const Composition &model, MAMOptions options=MAMOptions())
nlohmann::json getCompositionCapabilities() const
The binding described before solving, with runtime conditions (getCompositionCapabilities).
void setNativeDecSourceBackend(NativeDecSourceBackend backend)
Replace the native dec.source solve behind the MAP-network and marked-thinning decompositions (Python...
void reset()
Clear the stored result (reset).
ActionTable GetActTable()
SolverMAM(const Composition &&, MAMOptions=MAMOptions())=delete
static std::vector< std::string > listLALMethods()
Methods available for a LAL Composition (MATLAB SolverMAM.listLALMethods).
static MAMOptions defaultOptions()
ActionTable get_act_table()
QueueTable get_queue_table()
QueueTable getQueueTable()
Queue measures of unchanged structured queue declarations (getQueueTable).
std::function< MamResult(const Composition &, double, double, const std::optional< std::string > &)> FiniteQBDBackend
The Cartesian finite-QBD backend (Python's module-level lal_qbd.solve_composition); replaceable so a ...
bool hasResult() const
Whether a result is stored (Python solver.result is not None).
std::string getName() const
StateTable getAvgTable()
Agent-state probabilities (getAvgTable).
nlohmann::json getMAMDiagnostics(bool compare_ctmc=false, std::size_t max_states=1000)
Diagnostics, optionally compared with the finite CTMC (getMAMDiagnostics).
std::vector< Matrix< double > > getAvgTard()
getAvgTard(), inherited by the reference from NetworkSolver: mean class tardiness against the JobClas...
const Composition & model() const
The composition the solver analyzes: the lowered one when an embedded network was lowered.
std::pair< bool, std::string > Support
std::vector< Matrix< double > > get_avg_tard()
nlohmann::json get_composition_capabilities() const
Support supportsModelMethod(const std::string &method) const
Method-aware structural gate (supportsModelMethod); the reason is empty when supported.
std::vector< double > getActAvg(const std::vector< ActionSpec > &actions)
Throughputs of several actions, each named as in getAvgAct.
const MamResult & getMAMResult()
The result container, solving first if needed (getMAMResult).
SolverMAM(const Composition &&, const std::string &, const nlohmann::json &=nlohmann::json::object())=delete
nlohmann::json get_mam_diagnostics(bool compare_ctmc=false, std::size_t max_states=1000)
SolverMAM(const Composition &model, const std::string &method, const nlohmann::json &kwargs=nlohmann::json::object())
SolverMAM(model, method, **kwargs) with keyword arguments as a json object.
void getAvg() const
Queueing-network averages are refused on a composition (getAvg).
LINE Agent Language (LAL): the finite-agent model record, its validation, the joint-state event kerne...
LINE Agent Language (LAL): the result tables every LAL solver returns, the exact finite CTMC analysis...
LINE Agent Language (LAL): shared types and numerical helpers of the SolverMAM LAL paths (python/line...
LINE Agent Language (LAL): matrix-geometric analysis of one structured unbounded queue (solver_mam/la...
LINE Agent Language (LAL): lossless lowering of open exponential LAL networks to scalar M/M/c factors...
LINE Agent Language (LAL): lowering of embedded LINE networks to the agents SolverMAM's LAL methods r...
LINE Agent Language (LAL): lowering of a restricted open MAP/PH network to the native MAM dec....
LINE Agent Language (LAL): marked-source network decomposition with explicit visit thinning (solver_m...
LINE Agent Language (LAL): exact marginal QBDs for independent stations with shared marked sources (p...
LINE Agent Language (LAL): exact finite, level-dependent QBD analysis of a composition (solver_mam/la...
LINE Agent Language (LAL): QBD analysis restricted to the states reachable from the initial support (...
LINE Agent Language (LAL): the fitted-traffic QBD (lal_traffic.solve_reduced).
LINE Agent Language (LAL): independent marked arrival proposals of a finite composition and their exp...
std::string signature(const Model &m)
A deterministic text signature of a model snapshot (Python's repr(model)), used by the solvers to cac...
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].
std::pair< std::string, std::string > Endpoint
(agent, action).
MamResult jackson(const Composition &model, double max_states=50000)
Product-form solution of a recognised Jackson network (lal_jackson.solve_composition).
std::pair< std::optional< std::string >, std::string > qbd_structure(const Model &snapshot, double max_phases, double max_states, const std::optional< std::string > &level_name=std::nullopt)
The level agent of a finite QBD, or nullopt and the refusal reason (structure).
MamResult finite_qbd(const Composition &model, double max_phases=64, double max_states=50000, const std::optional< std::string > &level_name=std::nullopt)
Finite QBD solution of a composition (lal_qbd.solve_composition).
bool has_discrete(const Model &model)
True when any agent of the model is discrete-time.
MamResult marked_thinning(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())
Visit-thinning decomposition of a recognised MAP network (lal_marked_network.solve_composition).
ActionTable relabel_action_table(const ActionTable &table, const std::map< std::string, std::string > &mapping)
Rename lowered action rows to their node-event labels, summing rows that share one (relabel_action_ta...
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).
std::pair< std::optional< JacksonMatch >, std::string > recognize_jackson(const Model &snapshot)
Conservatively recognise independent Poisson inputs and open M/M/c routing.
MamResult parallel_qbd(const Composition &model, double max_phases, double max_states, long max_iter, double tol)
Exact marginal QBDs of independent stations sharing marked sources (mam_parallel_qbd....
LoweredComposition lower(const Composition &composition)
A Composition of plain agents equivalent to composition, or itself (lower).
std::string endpoint_label(const Endpoint &e)
MamResult infinite_qbd(const Composition &model, double max_phases=64, double max_states=50000, const std::optional< std::string > &level_name=std::nullopt, long max_iter=100, double tol=1e-4)
Infinite QBD solution of a composition (lal_infinite_qbd.solve_composition).
Result solve_composition(const Model &snapshot, std::size_t max_states=0, std::size_t max_dense_bytes=kDefaultMaxDenseBytes)
Solve a finite composition, respecting its initial state if reducible (solve_composition).
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,...
MamResult solve_reduced(const Composition &model, const std::string &level_name, const std::string &method, const std::string &compress_method, double fit_time, double fit_tolerance, double max_phases, double max_states, long max_iter=100, double tol=1e-4)
Fit the offered streams, then solve the reduced QBD (solve_reduced).
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).
MamResult reachable_qbd(const Composition &model, double max_phases=64, double max_states=50000, const std::optional< std::string > &level_name=std::nullopt)
Reachable QBD solution of a composition (lal_reachable_qbd.solve_composition).
std::set< std::string > model_features(const Model &model)
Features of a model that only the extended kernel interprets (model_features).
EventType
The events a state can undergo, with the values of MATLAB EventType.
Conservation laws of a layered queueing network, enumerated from its structure.
One row of an action table: Action, Throughput.
std::vector< ActionRow > rows
double throughput(const std::string &action) const
Throughput of one action label; throws when absent.
The immutable agent record (core.Agent).
std::vector< std::string > states
std::optional< QueueInfo > queue_info
A composition lowered for SolverMAM, with the map of lowered action labels to node-event labels.
std::map< std::string, std::string > labels
python _lal_labels
The options of SolverMAM on a LAL composition (SolverMAMOptions).
static MAMOptions from_kwargs(const nlohmann::json &kwargs, const std::string &method="default")
Options from Python-style keyword arguments (SolverMAM(model, **kwargs)).
std::optional< std::string > lal_level_agent
std::optional< nlohmann::json > cutoff
refused when set
std::string lal_traffic_method
std::string lal_compress_method
std::optional< std::string > arith
std::string key() const
The cache key (Python repr(self.options)).
std::optional< nlohmann::json > timespan
refused when set
The union of Python's LAL MAM result dataclasses.
std::optional< std::string > approximation
std::map< std::string, double > queue_means
empty: Python has no queue_means
std::optional< QueueTable > queue_measures
std::vector< std::string > phase_dependent_routing
std::optional< Traffic > traffic
std::optional< std::string > residual_kind
nlohmann::json native_internal_fitting
null: absent
std::optional< double > native_time_scale
dec.source: factor dividing the lowered network's rates
std::vector< std::string > correlated_service_reset
std::vector< std::string > unavailable_clock_phases
std::vector< std::string > unavailable_busy_probabilities
multiserver queues: Busy is NaN
nlohmann::json poissonised_visit_excess
std::optional< double > mean_level
nlohmann::json native_time_scales
marked.thinning: station -> scale (null without input); null: absent
std::optional< ActionTable > raw_action_table
The action table under the lowered agents' own route-specific labels, kept when an embedded network w...
A minimum-rate synchronisation: at least two active endpoints and optional passive ones.
A composition snapshot (core.Model): agents in declaration order plus synchronisations.
std::vector< MinSync > min_syncs
std::vector< Sync > syncs
std::vector< AgentRecord > agents
const AgentRecord & agent(const std::string &name) const
Structured queue declaration retained while a queue agent is unmodified (queue_info).
std::vector< std::string > service_inputs
std::vector< std::string > departures
std::vector< std::string > arrivals
One row of getQueueTable(): Agent, QLen, Busy, Util, ArvR, Tput, RespT.
The result container shared by the LAL solver paths (LALCTMCResult, the AG decomposition results,...
std::vector< std::vector< std::size_t > > states
joint states (CTMC)
std::optional< std::string > fallback_reason
One row of a state table: Agent, State, Probability.
std::vector< StateRow > rows
An ordinary synchronisation: one active endpoint, hand passives and injected node arrivals.
std::vector< Endpoint > passive
std::optional< std::string > fallback_reason