5#ifndef LINE_LANG_LAL_MAM_PARALLEL_QBD_H
6#define LINE_LANG_LAL_MAM_PARALLEL_QBD_H
37 if (!match.first)
throw detail::mam_refusal(
"Model", match.second);
39 if (m.
queues.size() > 100)
throw detail::mam_refusal(
"StateSpace",
"Parallel QBD exceeds 100 queues.");
40 std::map<std::string, Agent> builders;
41 for (
const Agent& a : model.
agents()) builders.emplace(a.name(), a);
42 std::map<std::string, std::vector<StateRow>> state_frames;
43 std::map<std::string, double> action_values;
45 double residual = 0.0;
46 for (std::size_t qi : m.
queues) {
48 std::set<std::string> names;
49 for (std::size_t s : m.
sources) names.insert(snapshot.
agents[s].name);
50 names.insert(queue.
name);
52 if (clock != m.
clocks.end()) names.insert(snapshot.
agents[clock->second.agent].name);
53 std::vector<Agent> members;
55 if (names.count(a.
name)) members.push_back(builders.at(a.
name));
58 std::vector<ActionRef> partners;
60 if (names.count(e.first)) partners.push_back(builders.at(e.first).action(e.second));
61 if (names.count(s.active.first) && !partners.empty())
62 local.
synchronize(builders.at(s.active.first).action(s.active.second), partners);
66 for (
const Endpoint& e : s.active) inside = inside && names.count(e.first) > 0;
67 if (!inside)
continue;
68 std::vector<ActionRef> actives, partners;
69 for (
const Endpoint& e : s.active) actives.push_back(builders.at(e.first).action(e.second));
71 if (names.count(e.first)) partners.push_back(builders.at(e.first).action(e.second));
83 residual = std::max(residual, result.
residual);
85 std::vector<std::string> order;
86 std::map<std::string, std::vector<StateRow>> groups;
88 if (!groups.count(row.agent)) order.push_back(row.agent);
89 groups[row.agent].push_back(row);
91 for (
const std::string& name : order) {
92 const std::vector<StateRow>& group = groups.at(name);
93 auto it = state_frames.find(name);
94 if (it == state_frames.end()) {
95 state_frames.emplace(name, group);
98 bool close = it->second.size() == group.size();
99 for (std::size_t k = 0; close && k < group.size(); ++k)
100 close = std::fabs(it->second[k].probability - group[k].probability) <=
101 1e-10 + 1e-8 * std::fabs(group[k].probability);
102 if (!close)
throw detail::mam_refusal(
"Numerical",
"Shared source marginals disagree across QBDs.");
105 auto it = action_values.find(row.action);
106 if (it != action_values.end() &&
107 !(std::fabs(it->second - row.throughput) <= 1e-10 + 1e-8 * std::fabs(row.throughput)))
108 throw detail::mam_refusal(
"Numerical",
"Shared source rates disagree across QBDs.");
109 action_values[row.action] = row.throughput;
112 queue_table.
rows.insert(queue_table.
rows.end(), q.
rows.begin(), q.
rows.end());
116 const std::vector<StateRow>& rows = state_frames.at(a.
name);
119 for (
const std::string& label : detail::kernel_labels(snapshot)) {
120 auto it = action_values.find(label);
121 if (it == action_values.end())
throw value_error(
"No parallel QBD throughput for action " + label);
126 attrs->method =
"parallelqbd";
127 attrs->exact = !truncated;
128 attrs->truncated = truncated;
129 attrs->extra[
"joint_queue_distribution"] =
"unavailable";
134 out.
exact = !truncated;
135 out.
method =
"parallelqbd";
136 out.
extra[
"unavailable"] = {
"joint queue-state distribution"};
A finite-state agent with active, weighted passive and immediate transitions (handle semantics).
A collection of agents and embedded LINE models with atomic synchronisations (Composition).
Composition & synchronize(const ActionRef &active, const std::vector< ActionRef > &passives)
Synchronise one active action with one or more hand passive actions.
Model model(const std::vector< Sync > *syncs=nullptr, const std::vector< ExtSync > *ext_syncs=nullptr) const
The current model snapshot (_model).
Composition & synchronize_min(const std::vector< ActionRef > &actives, const std::vector< ActionRef > &passives=std::vector< ActionRef >())
Synchronise active actions at the minimum enabled total rate.
const std::vector< Agent > & agents() const
SolverMAM on a LAL composition.
QueueTable getQueueTable()
Queue measures of unchanged structured queue declarations (getQueueTable).
const MamResult & getMAMResult()
The result container, solving first if needed (getMAMResult).
std::pair< std::optional< MapMatch >, std::string > recognize_parallel(const Model &snapshot)
Recognise independent stations with shared marked sources (lal_parallel_qbd.recognize).
std::pair< std::string, std::string > Endpoint
(agent, action).
InputError value_error(const std::string &what)
LINE:input:Unspecified, the C++ spelling of the Python ValueError raised throughout LAL.
void validate_model(const Model &model, bool allow_unbounded=false)
Validate the common agent model used by both frontends (validate_model).
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....
Conservation laws of a layered queueing network, enumerated from its structure.
LINE Agent Language (LAL): the SolverMAM binding of a Composition (the _lal_composition branches of p...
One row of an action table: Action, Throughput.
std::vector< ActionRow > rows
The immutable agent record (core.Agent).
The options of SolverMAM on a LAL composition (SolverMAMOptions).
std::string lal_traffic_method
The union of Python's LAL MAM result dataclasses.
std::optional< QueueTable > queue_measures
The recognised MAP network (lal_map_network.recognize tuple).
std::vector< std::size_t > queues
std::vector< std::size_t > sources
std::map< std::string, ServiceClock > clocks
keyed by queue name
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
std::vector< QueueRow > rows
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.
The attrs of a LAL result table.