9#ifndef LINE_LANG_LAL_TABLES_H
10#define LINE_LANG_LAL_TABLES_H
43 enum class Kind { Label, Agent, Node, Key };
44 Kind kind = Kind::Label;
46 std::optional<ActionRef> ref;
47 std::optional<NodeRef> node;
49 std::string node_name;
50 std::size_t node_index = 0;
51 bool by_index =
false;
52 lang::EventType
event = lang::EventType::LOCAL;
53 std::optional<std::string> jobclass;
54 std::size_t class_index = 0;
55 std::optional<std::string> mode;
56 std::optional<std::string> part;
58 ActionSpec(
const std::string& l) : kind(Kind::Label), label(l) {}
59 ActionSpec(
const char* l) : kind(Kind::Label), label(l) {}
60 ActionSpec(
const ActionRef& r) : kind(Kind::Agent), ref(r) {}
61 ActionSpec(
const NodeRef& n) : kind(Kind::Node), node(n) {}
64 static ActionSpec key(
const std::string& node, lang::EventType event,
65 const std::optional<std::string>& jobclass = std::nullopt,
66 const std::optional<std::string>& mode = std::nullopt,
67 const std::optional<std::string>& part = std::nullopt) {
68 ActionSpec s{std::string()};
72 s.jobclass = jobclass;
78 static ActionSpec key(std::size_t node, lang::EventType event, std::size_t jobclass = 0,
79 const std::optional<std::string>& part = std::nullopt) {
80 ActionSpec s{std::string()};
85 s.class_index = jobclass;
92inline std::pair<std::string, bool> resolve_labels(
const Composition& composition,
const ActionSpec& spec) {
95 case ActionSpec::Kind::Label: {
96 const std::string& l = spec.label;
97 if (l.size() >= 3 && l.compare(l.size() - 3, 3,
"[*]") == 0)
return {l.substr(0, l.size() - 3),
true};
100 case ActionSpec::Kind::Agent: {
102 std::set<std::string> labels;
103 for (
const Transition& t : r.agent.transitions())
105 if (labels.size() != 1)
106 throw InputError(
ErrorKind(
"Argument"), r.agent.name() +
"." + r.name +
" has no single event label.");
107 return {*labels.begin(),
false};
109 case ActionSpec::Kind::Node:
110 key = spec.node->key;
112 case ActionSpec::Kind::Key:
113 key = spec.by_index ? composition.action(spec.node_index, spec.event, spec.class_index, spec.part).key
114 : composition.action(spec.node_name, spec.event, spec.jobclass, spec.mode, spec.part).key;
117 return {key.label(), !key.index.has_value()};
121template <
class Table>
122double act_value(
const Composition& composition,
const Table& table,
const ActionSpec& spec) {
123 const std::pair<std::string, bool> lf = resolve_labels(composition, spec);
124 const std::string& label = lf.first;
127 for (
const auto& row :
table.rows) {
128 const std::string& a = row.action;
129 const bool hit = lf.second ? (a == label || a.compare(0, label.size() + 1, label +
"[") == 0) : a == label;
132 total += row.throughput;
137 "no action '" + label +
"' in this composition; see getActTable().");
142 const std::pair<std::string, bool> lf = resolve_labels(*
this,
action);
143 hidden_.insert(lf.second ? lf.first +
"[*]" : lf.first);
153inline bool is_hidden(
const Model& snapshot,
const std::string& label) {
154 for (
const std::string& h : snapshot.hidden) {
155 if (h == label)
return true;
156 if (h.size() >= 3 && h.compare(h.size() - 3, 3,
"[*]") == 0) {
157 const std::string base = h.substr(0, h.size() - 3);
158 if (label == base || label.compare(0, base.size() + 1, base +
"[") == 0)
return true;
LINE Agent Language (LAL): programmatic construction of finite agents and their composition,...
A collection of agents and embedded LINE models with atomic synchronisations (Composition).
Composition & hide(const ActionSpec &action)
Make actions internal (hide): they still occur, but leave the action tables.
NodeRef action(const std::string &node, lang::EventType event, const std::optional< std::string > &jobclass=std::nullopt, const std::optional< std::string > &mode=std::nullopt, const std::optional< std::string > &part=std::nullopt) const
A node action of an embedded LINE model (action): node and jobclass are names, mode a Petri-net mode ...
LINE Agent Language (LAL): the finite-agent model record, its validation, the joint-state event kerne...
std::string transition_label(const std::string &agent, const Transition &t)
Primary label of a transition (its first label when it carries several).
const std::map< std::string, std::vector< std::string > > & table()
Conservation laws of a layered queueing network, enumerated from its structure.
A composition snapshot (core.Model): agents in declaration order plus synchronisations.
Key of an embedded node action: (node, EventType, class | mode).
One labelled local transition source --(action, value)--> target.