LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_lqns.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_SOLVERS_WRAPPERS_LQNS_SOLVER_LQNS_H
6#define LINE_SOLVERS_WRAPPERS_LQNS_SOLVER_LQNS_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * SolverLQNS: the layered model solved by the external lqns / lqsim binaries.
12 *
13 * Port of matlab/src/solvers/wrappers/LQNS/@@SolverLQNS (SolverLQNS.m,
14 * runAnalyzer.m, parseXMLResults.m, getEnsembleAvg.m, runRemoteLQNS.m), of
15 * jline.solvers.wrappers.lqns.SolverLQNS and of the native-Python twin. It is a
16 * WRAPPER, not an engine: nothing here computes a queueing result. The model is
17 * written as .lqnx (lqn_writer.h), a binary is run over it, and the .lqxo it
18 * leaves behind is read back.
19 *
20 * LINE SHIPS NO LQNS BINARY. Its licence is an evaluation agreement that
21 * forbids redistribution, so the binary is one the user installed; a missing
22 * one is reported by name, with the two ways to obtain an answer anyway (an
23 * install, or a host already running the REST service), rather than as a failed
24 * exec.
25 *
26 * WHAT THE COLUMNS MEAN, and why they are not the ones lqns prints. The
27 * reference's getEnsembleAvg permutes them so that a layered result reads the
28 * same whichever solver produced it:
29 *
30 * QLen <- the element's UTILIZATION (a task's utilization IS its
31 * mean number in service)
32 * Util <- its PROCESSOR utilization: lqns and SolverLN both sum it over
33 * the host's servers, so no rescaling applies. Verbatim for hosts,
34 * tasks and activities; for an entry it is aggregated over the
35 * activity graph, which lqns itself reports as 0 in the
36 * activity-graph form
37 * RespT <- its PHASE 1 SERVICE TIME
38 * Tput <- its throughput
39 * ResidT, ArvR: lqns computes neither, so they stay undefined rather than
40 * being filled with a zero that would read as a computed value
41 *
42 * THE .lqxo IS THE ONLY OUTPUT READ. lqns also prints a human-readable report;
43 * parsing that instead would tie the port to a print format that changes
44 * between releases, and it carries fewer digits than the XML.
45 */
46
48#include <algorithm>
49#include <cmath>
50#include <cstdio>
51#include <cstdlib>
52#include <ctime>
53#include <fstream>
54#include <iterator>
55#include <limits>
56#include <map>
57#include <memory>
58#include <string>
59#include <utility>
60#include <vector>
61
62#include <dirent.h>
63#include <sys/stat.h>
64#include <unistd.h>
65
66#include "json.hpp"
67#include "line/io/line_ports.h"
71#include "line/util/error.h"
72#include "line/util/http.h"
74#include "line/util/matrix.h"
76#include "line/util/tempdir.h"
77#include "line/util/xml.h"
79
80namespace line {
81namespace lqns {
82
83/** Knobs of the wrapper, the subset of SolverOptions that reaches lqns. */
85 /**
86 * default | lqns | srvn | exactmva | srvn.exactmva | sim | lqsim | lqns.default
87 *
88 * `sim` and `lqsim` run the SIMULATOR and are the only stochastic ones;
89 * `lqns.default` is lqns with no pragma at all, which is a different fixed
90 * point from `default` and not a synonym for it.
91 */
92 std::string method = "default";
93 /** conway | rolia | zhou | suri | reiser | schmidt | default (= rolia). */
94 std::string multiserver = "default";
95 /** lqsim run length, `-A`; not positive leaves lqsim's own default. */
96 double samples = 10000.0;
97 bool verbose = false;
98 /** Keep the working directory, model and result file after the run. */
99 bool keep = false;
100 /** Deadline for the child, in seconds; not positive waits indefinitely. */
102 /** Solve on a host running lqns-rest instead of on this machine. */
103 bool remote = false;
104 /** lqns-rest at its allocated host port (line/io/line_ports.h); a verified
105 * lqns-rest on the legacy 8080 is used when nothing answers there. */
107};
108
109/**
110 * Everything the .lqxo carries, indexed as the struct is.
111 *
112 * The element vectors are (nidx+1) with slot 0 unused and `callwaiting` is
113 * (ncalls+1); an entry lqns did not report stays NaN, which is how the
114 * reference leaves it and is what tells a caller "not reported" apart from
115 * "reported as zero".
116 */
118 std::vector<double> util, phase1util, phase2util;
119 std::vector<double> phase1svct, phase2svct;
120 std::vector<double> tput, procwaiting, procutil;
121 std::vector<double> residvisit; ///< host residence of ONE execution of an activity
122 std::vector<double> residt; ///< ResidT on SolverLN's definition, see compute_residt
123 std::vector<double> callwaiting;
124 int iterations = 0;
125};
126
127/** The six measures, on the element index space, with a defined mask each. */
128template <class T>
130 std::vector<T> QN, UN, RN, TN, AN, WN;
132 int iterations = 0;
133};
134
135namespace detail {
136
137/** NaN as the .lqxo reader uses it: "lqns did not report this". */
138inline double nan_value() { return std::numeric_limits<double>::quiet_NaN(); }
139
140/** An attribute as a double, NaN when absent or unparsable (str2double). */
141inline double attr_num(const xml::Element* e, const char* key) {
142 const std::string s = e->attr(key);
143 if (s.empty()) return nan_value();
144 char* end = nullptr;
145 const double v = std::strtod(s.c_str(), &end);
146 if (end == s.c_str()) return nan_value();
147 return v;
148}
149
150/**
151 * Snap a value within CoarseTol of an exact tenth onto it.
152 *
153 * lqns reports a quantity that is analytically a multiple of 0.1 with a few
154 * digits of iteration noise, and the reference removes that noise in
155 * getAvgTable before tabulating. It belongs to the TABLE and not to getAvg: the
156 * raw fixed point is what a parity comparison should see.
157 */
158inline double snap_to_tenth(double v) {
159 if (!std::isfinite(v)) return v;
160 const double scaled = v * 10.0;
161 const double snapped = std::floor(scaled + 0.5);
162 if (std::fabs(scaled - snapped) < lang::GlobalConstants::CoarseTol * scaled)
163 return snapped / 10.0;
164 return v;
165}
166
167/**
168 * A private working directory, the C++ lineTempName.
169 *
170 * Delegated rather than rolled again here: LINE_WORKSPACE_ROOT has to relocate
171 * the staged .lqnx, since a containerized lqns bind-mounts that root alone and
172 * sees nothing left under TMPDIR.
173 */
174inline std::string make_temp_dir(const std::string& tag) { return util::make_temp_dir(tag); }
175
176/** Remove a directory this wrapper created, with every file it holds. */
177inline void remove_temp_dir(const std::string& dir) {
178 DIR* d = ::opendir(dir.c_str());
179 if (d != nullptr) {
180 for (struct dirent* ent = ::readdir(d); ent != nullptr; ent = ::readdir(d)) {
181 const std::string name(ent->d_name);
182 if (name == "." || name == "..") continue;
183 ::unlink((dir + "/" + name).c_str());
184 }
185 ::closedir(d);
186 }
187 ::rmdir(dir.c_str());
188}
189
190} // namespace detail
191
192/**
193 * Whether lqns or lqsim can serve this layered model under `method`: empty when it can, else the reason.
194 *
195 * The constructs neither binary models are named one by one, since the .lqnx carries setup/delay-off in the LINE
196 * dialect and lqns would otherwise stop at its own parse error ("Unexpected element <setup>") for a modelling limit
197 * of the binary. Mirrors MATLAB lqns_method_refusal / SolverLQNS.unsupportedLNConstructs, the JAR
198 * SolverLQNS.lqnsMethodRefusal and python lqns_method_refusal; the scheduling rule stays with sched_to_lqnx.
199 */
200template <class T>
201std::string lqns_method_refusal(const lqn::LqnModel<T>& m, const std::string& method) {
202 std::vector<std::string> reasons;
203 const auto fmt_g = [](double v) {
204 char buf[64];
205 std::snprintf(buf, sizeof(buf), "%g", v);
206 return std::string(buf);
207 };
208 for (std::size_t t = 0; t < m.tasks.size(); ++t) {
209 const auto& tk = m.tasks[t];
210 if (tk.nitems > 0)
211 reasons.push_back("task '" + tk.name + "' is a CacheTask, and neither lqns nor lqsim models a cache");
212 for (std::size_t e = 0; e < m.entries.size(); ++e)
213 if (m.entries[e].task_slot == t && m.entries[e].cardinality > 0)
214 reasons.push_back("entry '" + m.entries[e].name + "' on task '" + tk.name + "' is an ItemEntry, and "
215 "neither lqns nor lqsim models an item reference stream");
216 const double su = tk.setuptime.disabled ? 0.0 : num_traits<T>::to_double(tk.setuptime.mean);
218 reasons.push_back("task '" + tk.name + "' declares a setup time (" + fmt_g(su) +
219 "), which neither lqns nor lqsim charges");
220 const double off = tk.delayofftime.disabled ? 0.0 : num_traits<T>::to_double(tk.delayofftime.mean);
222 reasons.push_back("task '" + tk.name + "' declares a delay-off time (" + fmt_g(off) +
223 "), which neither lqns nor lqsim charges");
224 // the schema takes think-time on reference tasks only, so write_lqnx drops it (reported in LqnWriteReport)
225 const double tt = tk.thinktime.disabled ? 0.0 : num_traits<T>::to_double(tk.thinktime.mean);
227 reasons.push_back("task '" + tk.name + "' is not a reference task and declares a think time (" +
228 fmt_g(tt) + "), which the LQN XML schema accepts on reference tasks only");
229 }
230 const auto server_rules = [&](const std::string& name, bool pools, bool lld, bool lcd, bool ljd) {
231 if (pools)
232 reasons.push_back("'" + name + "' declares heterogeneous server pools with a class-compatibility graph, "
233 "which neither lqns nor lqsim models: their multiserver is homogeneous");
234 if (lld) reasons.push_back("'" + name + "' declares a load-dependent service rate, which neither lqns nor lqsim models");
235 if (lcd) reasons.push_back("'" + name + "' declares a class-dependent service rate, which neither lqns nor lqsim models");
236 if (ljd) reasons.push_back("'" + name + "' declares a joint-dependent service rate, which neither lqns nor lqsim models");
237 };
238 for (std::size_t p = 0; p < m.procs.size(); ++p) {
239 const auto pl = m.proc_pools.find(p);
240 const auto ll = m.proc_lldscaling.find(p);
241 const auto cd = m.proc_cdscaling.find(p);
242 const auto jd = m.proc_jdscaling.find(p);
243 server_rules(m.procs[p].name, pl != m.proc_pools.end() && !pl->second.empty(),
244 ll != m.proc_lldscaling.end() && !ll->second.empty(),
245 cd != m.proc_cdscaling.end() && static_cast<bool>(cd->second),
246 jd != m.proc_jdscaling.end() && static_cast<bool>(jd->second));
247 }
248 for (std::size_t t = 0; t < m.tasks.size(); ++t) {
249 const auto& tk = m.tasks[t];
250 server_rules(tk.name, !tk.pools.empty(), !tk.lldscaling.empty(), static_cast<bool>(tk.cdscaling), static_cast<bool>(tk.jdscaling));
251 }
252 if (!reasons.empty()) {
253 std::string joined;
254 for (std::size_t i = 0; i < reasons.size(); ++i) joined += (i ? "; " : "") + reasons[i];
255 return "SolverLQNS cannot serve this model: " + joined +
256 ". Use SolverLN (the native layered solver), which models these constructs.";
257 }
258 const bool sim_method = method == "sim" || method == "lqsim";
259 if (!sim_method) {
260 // lqns stops at "The quorum feature is not supported in this version"; lqsim honours the quorum
261 for (std::size_t t = 0; t < m.tasks.size(); ++t)
262 for (const auto& pc : m.tasks[t].precedences)
263 if (pc.pretype == lang::PrecedenceType::PRE_AND && pc.has_quorum && pc.quorum >= 1 &&
264 pc.quorum < pc.preacts.size())
265 return "task '" + m.tasks[t].name + "' declares a quorum AND-join (" + std::to_string(pc.quorum) +
266 " of " + std::to_string(pc.preacts.size()) +
267 "), which lqns does not support. Use method sim (lqsim), SolverLN or SolverLDES.";
268 }
269 if (sim_method) {
270 for (std::size_t p = 0; p < m.procs.size(); ++p)
271 if (m.procs[p].repl > 1.0)
272 return "'" + m.procs[p].name + "' is replicated " + fmt_g(m.procs[p].repl) +
273 " times, which lqsim refuses to simulate. Use an lqns method, SolverLN or SolverLDES, "
274 "which materialise the replicas.";
275 for (std::size_t t = 0; t < m.tasks.size(); ++t)
276 if (m.tasks[t].repl > 1.0)
277 return "'" + m.tasks[t].name + "' is replicated " + fmt_g(m.tasks[t].repl) +
278 " times, which lqsim refuses to simulate. Use an lqns method, SolverLN or SolverLDES, "
279 "which materialise the replicas.";
280 }
281 return std::string();
282}
283
284/**
285 * The layered model solved by lqns or lqsim.
286 *
287 * Constructed over the INTERMEDIATE model (lqn_reader.h), not over the struct,
288 * because the document handed to the binary has to carry the precedence blocks
289 * and reply entries that getStruct flattens away.
290 */
291template <class T>
293public:
295 : model_(model), opt_(options), sn_(lqn::lqn_finalize(model)) {
296 if (!is_available() && !opt_.remote)
297 throw UnsupportedError(ErrorKind{"LQNS"},
298 "SolverLQNS requires the lqns and lqsim commands on the system path.\n"
299 "Obtain them from their authors at: http://www.sce.carleton.ca/rads/lqns/\n"
300 "LINE ships no LQNS binary and does not redistribute one.\n\n"
301 "Alternatively, point LINE at a host that already runs LQNS by setting\n"
302 "LqnsOptions::remote and LqnsOptions::remote_url.");
303 const std::string m = opt_.method.empty() ? std::string("default") : opt_.method;
304 const std::vector<std::string> valid = list_valid_methods();
305 if (std::find(valid.begin(), valid.end(), m) == valid.end())
306 throw InputError("SolverLQNS: '" + m +
307 "' is not a method of this solver; it takes default, lqns, srvn, "
308 "exactmva, srvn.exactmva, sim, lqsim and lqns.default");
309 opt_.method = m;
310 multiserver_pragma(opt_.multiserver); // refuses an unknown policy here, not mid-run
311 // LINE's own sentence before any .lqnx is written, not the binary's parse error
312 const std::string refusal = lqns_method_refusal(model_, opt_.method);
313 if (!refusal.empty()) throw UnsupportedError(ErrorKind{"Structure"}, refusal);
314 }
315
316 /** True when the native lqns command answers on this machine, any release. */
317 static bool has_local_binary() { return !lqns_version().empty(); }
318
319 /** True when a local binary is installed AND is 6.0 or greater. */
320 static bool is_available() { return lqns_is_available(); }
321
322 /** The version banner of the local binary, empty when there is none. */
323 static std::string version() { return lqns_version(); }
324
325 static std::vector<std::string> list_valid_methods() {
326 // the names and their order are this solver's row of the method registry (doc/line-methods.json); a LayeredNetwork
327 // takes every name but the flat-Network qnsolver ones
328 std::vector<std::string> m;
329 for (const std::string& name : ::line::method_registry::methods("LQNS")) {
330 if (name != "qns" && name.rfind("qns.", 0) != 0) {
331 m.push_back(name);
332 }
333 }
334 return m;
335 }
336
337 /** Only the lqsim methods draw random numbers. */
338 static bool is_stochastic_method(const std::string& method) {
339 return method == "sim" || method == "lqsim";
340 }
341
342 /**
343 * The per-layer feature set, as SolverLQNS.supports declares it.
344 *
345 * A layered model reaches lqns as a whole, so this is the set each LAYER
346 * must fall inside: the product-form station kinds and the four service
347 * distributions the LQN schema can carry.
348 */
349 static std::vector<std::string> feature_set() {
350 const char* names[] = {"Sink", "Source", "Queue",
351 "Coxian", "Erlang", "Exp",
352 "HyperExp", "Buffer", "Server",
353 "JobSink", "RandomSource", "ServiceTunnel",
354 "SchedStrategy_PS", "SchedStrategy_FCFS", "ClosedClass"};
355 return std::vector<std::string>(names, names + sizeof(names) / sizeof(names[0]));
356 }
357
358 const lqn::LqnStruct<T>& get_struct() const { return sn_; }
359 const LqnsOptions& options() const { return opt_; }
360 /** Wall-clock seconds of the last run, the reference's `runtime`. */
361 double runtime() const { return runtime_; }
362 int iterations() const { return raw_.iterations; }
363 /** Everything the .lqxo carried, before the column permutation. */
365 run_analyzer_once();
366 return raw_;
367 }
368
369 /**
370 * Run the binary and read its result back.
371 *
372 * Re-running is what the reference does on every getEnsembleAvg call, but
373 * repeating a lqsim run would silently change the answer between two reads
374 * of the same solver object, so the result is computed once and kept.
375 */
377 const std::clock_t t0 = std::clock();
378 const std::string dir = detail::make_temp_dir("lqns");
379 const std::string stem = dir + "/model";
380 const std::string modelfile = stem + ".lqnx";
381 const std::string resultfile = stem + ".lqxo";
382 try {
383 line::util::LineConsole::step("writing the LQN model to %s", modelfile.c_str());
384 const lqn::LqnWriteReport rep = lqn::write_lqnx(model_, modelfile, "LQN");
385 if (opt_.verbose)
386 for (std::size_t i = 0; i < rep.dropped.size(); ++i)
387 std::fprintf(stderr, "SolverLQNS: %s\n", rep.dropped[i].c_str());
388
389 if (opt_.remote) run_remote(modelfile, resultfile);
390 else run_local(modelfile, resultfile);
391
392 line::util::LineConsole::step("parsing the lqns XML results");
393 parse_lqxo(resultfile);
394 } catch (...) {
395 if (!opt_.keep) detail::remove_temp_dir(dir);
396 throw;
397 }
398 if (!opt_.keep) detail::remove_temp_dir(dir);
399 else if (opt_.verbose) std::fprintf(stderr, "SolverLQNS: files kept in %s\n", dir.c_str());
400 runtime_ = double(std::clock() - t0) / double(CLOCKS_PER_SEC);
401 solved_ = true;
402 }
403
404 /**
405 * The six measures on the element index space.
406 *
407 * Port of getEnsembleAvg.m, including the reachable-multiplicity rescaling
408 * of the utilization column.
409 */
411 run_analyzer_once();
412 const std::size_t n = sn_.nidx;
414 s.iterations = raw_.iterations;
415 auto fill = [&](std::vector<T>& v, std::vector<bool>& d, const std::vector<double>& src) {
416 v.assign(n + 1, num_traits<T>::from_int(0));
417 d.assign(n + 1, false);
418 for (std::size_t i = 1; i <= n; ++i) {
419 if (std::isnan(src[i])) continue;
420 v[i] = num_traits<T>::from_double(src[i]);
421 d[i] = true;
422 }
423 };
424 // lqns sums the processor utilization over the host's busy servers; it is
425 // divided by the servers the work can reach (host_reach_mult), the divisor
426 // of SolverLN and SolverLDES, so the three Util columns agree (P150). The
427 // entry rows were aggregated over the activity graph by aggregate_entry_procutil.
428 fill(s.QN, s.defined_Q, raw_.util);
429 fill(s.UN, s.defined_U, raw_.procutil);
430 for (std::size_t i = 1; i <= n; ++i)
431 if (s.defined_U[i]) s.UN[i] = s.UN[i] / num_traits<T>::from_double(sn_.host_reach_mult(i));
432 fill(s.RN, s.defined_R, raw_.phase1svct);
433 fill(s.TN, s.defined_T, raw_.tput);
434 // ResidT is derived from the .lqxo by compute_residt; lqns computes no
435 // arrival rate per element, so that column stays undefined.
436 fill(s.WN, s.defined_W, raw_.residt);
437 s.AN.assign(n + 1, num_traits<T>::from_int(0));
438 s.defined_A.assign(n + 1, false);
439 return s;
440 }
441
442 /**
443 * `getAvgTard()`, inherited by the reference from NetworkSolver: mean class
444 * tardiness against the JobClass deadlines, as {Tard, SysTard}. The method
445 * solves first when no result is held, as `getAvgTard.m` calls `getAvg`, and
446 * then returns what the result carries. Neither lqns nor lqsim reports a
447 * tardiness (parseXMLResults.m fills no `Avg.Tard` or `Avg.SysTard`), so
448 * both matrices are empty, exactly as the reference returns `[]` for them.
449 */
450 std::vector<Matrix<T>> get_avg_tard() {
451 run_analyzer_once();
452 return {Matrix<T>(), Matrix<T>()};
453 }
454
455private:
456 void run_analyzer_once() {
457 if (!solved_) run_analyzer();
458 }
459
460 /** The `-Pmultiserver=` argument of a policy name, empty when there is none. */
461 static std::string multiserver_pragma(const std::string& policy) {
462 if (policy.empty() || policy == "none") return std::string();
463 if (policy == "default") return "-Pmultiserver=rolia";
464 if (policy == "conway" || policy == "rolia" || policy == "zhou" || policy == "suri" ||
465 policy == "reiser" || policy == "schmidt")
466 return "-Pmultiserver=" + policy;
467 throw InputError("SolverLQNS: '" + policy +
468 "' is not a multiserver policy of lqns; it takes conway, rolia, zhou, "
469 "suri, reiser, schmidt and default");
470 }
471
472 /**
473 * The command line, as an argv vector.
474 *
475 * NO SHELL SEES THESE ARGUMENTS. The reference builds one string and hands
476 * it to system(); a model path holding a space would be word-split there,
477 * and this port's working directory comes from TMPDIR, which the caller
478 * controls.
479 *
480 * `env -u LD_LIBRARY_PATH`, which the MATLAB wrapper prefixes, is NOT
481 * reproduced: it exists because MATLAB injects its own libstdc++ ahead of
482 * the system one and lqns then fails to find a GLIBCXX symbol. A plain C++
483 * process has no such injection, and stripping the variable here would
484 * instead break a user who set it to reach their own lqns.
485 */
486 std::vector<std::string> build_argv(const std::string& modelfile) const {
487 const bool sim = is_stochastic_method(opt_.method);
488 std::vector<std::string> a;
489 a.push_back(sim ? "lqsim" : "lqns");
490 if (!opt_.verbose) {
491 a.push_back("-a"); // no advisories
492 a.push_back("-w"); // no warnings
493 }
494 // The simulator has no MVA to configure, so the multiserver pragma is
495 // not passed to it, exactly as the reference declines to.
496 if (!sim) {
497 const std::string ms = multiserver_pragma(opt_.multiserver);
498 if (!ms.empty()) a.push_back(ms);
499 }
500 if (opt_.method == "srvn" || opt_.method == "srvn.exactmva") a.push_back("-Playering=srvn");
501 if (opt_.method == "exactmva" || opt_.method == "srvn.exactmva") a.push_back("-Pmva=exact-mva"); // lqns 6.2 rejects "exact"
502 if (sim && opt_.samples > 0) {
503 char buf[32];
504 std::snprintf(buf, sizeof(buf), "%.0f", opt_.samples);
505 a.push_back("-A");
506 a.push_back(buf);
507 }
508 // `lqns.default` is lqns with NO pragma: a model that loses messages
509 // stops the run there, which is the binary's own default and a
510 // different answer from the one the other methods ask for.
511 if (opt_.method != "lqns.default") a.push_back("-Pstop-on-message-loss=false");
512 a.push_back("-x"); // XML result, the .lqxo this wrapper reads
513 a.push_back(modelfile);
514 return a;
515 }
516
517 void run_local(const std::string& modelfile, const std::string& resultfile) const {
518 const std::vector<std::string> argv = build_argv(modelfile);
519 if (opt_.verbose) {
520 std::string cmd;
521 for (std::size_t i = 0; i < argv.size(); ++i) cmd += (i ? " " : "") + argv[i];
522 std::fprintf(stderr, "SolverLQNS command: %s\n", cmd.c_str());
523 }
524 line::util::LineConsole::step("running the lqns binary as a subprocess");
525 const util::ProcResult r =
526 util::capture(argv, util::timeout_kill_bound(opt_.timeout_seconds), true);
527 if (r.timedOut) util::timeout_raise_if_killed_on_budget("SolverLQNS: " + argv[0]);
528 if (r.timedOut)
529 throw ExternalError(ErrorKind{"LQNS"}, "SolverLQNS: " + argv[0] + " did not finish within " +
530 std::to_string(opt_.timeout_seconds) + "s and was killed");
531 if (r.exitCode < 0)
532 throw UnsupportedError(ErrorKind{"LQNS"}, "SolverLQNS: could not run '" + argv[0] +
533 "'; LINE ships no LQNS binary, so it must be installed and on "
534 "the system path");
535 if (opt_.verbose && !r.out.empty()) std::fprintf(stderr, "%s", r.out.c_str());
536 // a model lqns rejects leaves no .lqxo; carry its own message instead of the reader's missing-file one
537 struct stat st;
538 if (r.exitCode != 0 || ::stat(resultfile.c_str(), &st) != 0) {
539 std::string out = r.out;
540 while (!out.empty() && (out.back() == '\n' || out.back() == ' ')) out.pop_back();
541 throw ExternalError(ErrorKind{"LQNS"}, "SolverLQNS: the LQNS binary (exit status " + std::to_string(r.exitCode) +
542 ") produced no results for this model. Its output was:\n" + out);
543 }
544 }
545
546 /**
547 * The lqns-rest protocol: one POST carrying the whole document.
548 *
549 * Twin of runRemoteLQNS.m and of the native-Python `_run_remote_lqns`. The
550 * service answers with the .lqxo text, which is written where the local run
551 * would have left it so that ONE parser serves both paths.
552 */
553 void run_remote(const std::string& modelfile, const std::string& resultfile) const {
554 std::string content;
555 {
556 std::ifstream in(modelfile.c_str());
557 if (!in) throw ExternalError(ErrorKind{"LQNS"}, "SolverLQNS: cannot read the model it just wrote: " + modelfile);
558 content.assign(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>());
559 }
560 const bool sim = is_stochastic_method(opt_.method);
561 // The default URL resolves to the allocated host port, or to a verified
562 // lqns-rest on the legacy 8080; an explicit URL is kept as given.
563 std::string base = ports::resolve_lqns_url(opt_.remote_url);
564 while (!base.empty() && base[base.size() - 1] == '/') base.erase(base.size() - 1);
565 const std::string url = base + (sim ? "/api/v1/solve/lqsim" : "/api/v1/solve/lqns");
566
567 nlohmann::json req;
568 req["model"]["content"] = content;
569 req["model"]["base64"] = false;
570 req["options"]["include_raw_output"] = true;
571 if (sim) {
572 req["options"]["blocks"] = 30;
573 if (opt_.samples > 0) req["options"]["run_time"] = opt_.samples;
574 } else {
575 std::string ms = opt_.multiserver.empty() || opt_.multiserver == "default"
576 ? std::string("rolia")
577 : opt_.multiserver;
578 req["options"]["pragmas"]["multiserver"] = ms;
579 req["options"]["pragmas"]["stop_on_message_loss"] = false;
580 if (opt_.method == "srvn" || opt_.method == "srvn.exactmva")
581 req["options"]["pragmas"]["layering"] = "srvn";
582 if (opt_.method == "exactmva" || opt_.method == "srvn.exactmva")
583 req["options"]["pragmas"]["mva"] = "exact";
584 }
585
586 // Read timeout: the explicit bound, else the armed budget plus grace,
587 // else none (an unbudgeted remote solve waits as a local one does).
588 const int timeout_s = util::timeout_kill_bound(opt_.timeout_seconds);
589 const int timeout_ms = timeout_s > 0 && timeout_s < 2000000 ? timeout_s * 1000 : 0;
590 http::Response resp;
591 try {
592 resp = http::post_json(url, req.dump(), timeout_ms);
593 } catch (const http::HttpError&) {
594 util::timeout_raise_if_killed_on_budget("SolverLQNS: remote LQNS at " + url);
595 throw;
596 }
597 if (resp.status < 200 || resp.status >= 300)
598 throw ExternalError(ErrorKind{"LQNS"}, "SolverLQNS: remote LQNS at " + url + " returned HTTP " +
599 std::to_string(resp.status) + ": " + resp.body);
600 nlohmann::json out;
601 try {
602 out = nlohmann::json::parse(resp.body);
603 } catch (const std::exception& e) {
604 throw ExternalError(ErrorKind{"LQNS"}, std::string("SolverLQNS: remote LQNS returned a body that is not JSON: ") +
605 e.what());
606 }
607 const std::string status = out.value("status", std::string());
608 if (status == "error" || status == "failed")
609 throw ExternalError(ErrorKind{"LQNS"}, "SolverLQNS: remote solver returned an error: " +
610 out.value("error", std::string("unknown error")));
611 std::string lqxo;
612 if (out.contains("raw_output") && out["raw_output"].is_object())
613 lqxo = out["raw_output"].value("lqxo", std::string());
614 if (lqxo.empty())
615 throw ExternalError(ErrorKind{"LQNS"}, "SolverLQNS: remote solver did not return an LQXO document");
616 std::ofstream f(resultfile.c_str());
617 if (!f) throw ExternalError(ErrorKind{"LQNS"}, "SolverLQNS: cannot write the remote result to " + resultfile);
618 f << lqxo;
619 }
620
621 /**
622 * Element index of a name OF A GIVEN KIND, 0 when we hold no such element.
623 *
624 * THE KIND IS PART OF THE KEY, and has to be. A LINE-generated layered model
625 * routinely gives a processor, its task and that task's entry the SAME name
626 * (`c0` in the randomLQN corpus, and throughout lqn_ofbiz), and `lqn.names`
627 * holds all three. The reference looks the name up in that flat list with
628 * `findstring`, which returns EVERY match, and then assigns the result to
629 * all of them -- so a processor row ends up carrying its entry's numbers,
630 * whichever element was written last. The .lqxo says which kind it is
631 * describing, in the tag being read, so the ambiguity does not have to exist
632 * here and this port does not reproduce it. On a model whose names are
633 * unique the two agree element for element.
634 */
635 std::size_t index_of(const std::string& name, lang::LqnElement kind) const {
636 const std::map<std::pair<int, std::string>, std::size_t>::const_iterator it =
637 byname_.find(std::make_pair(static_cast<int>(kind), name));
638 return it == byname_.end() ? 0 : it->second;
639 }
640
641 std::size_t call_index_of(const std::string& name) const {
642 const std::map<std::string, std::size_t>::const_iterator it = bycallname_.find(name);
643 return it == bycallname_.end() ? 0 : it->second;
644 }
645
646 void init_name_index() {
647 if (!byname_.empty()) return;
648 // First declaration wins within a kind, as `find(strcmp(...))(1)` would.
649 for (std::size_t i = 1; i <= sn_.nidx; ++i)
650 byname_.insert(std::make_pair(
651 std::make_pair(static_cast<int>(sn_.type[i]), sn_.names[i]), i));
652 for (std::size_t c = 1; c <= sn_.ncalls; ++c)
653 bycallname_.insert(std::make_pair(sn_.callnames[c], c));
654 }
655
656 /**
657 * Read the .lqxo, a port of parseXMLResults.m.
658 *
659 * The walk is processor -> task -> entry -> phase activities, then the task
660 * activity graph. It is keyed on NAMES throughout, so an activity ordering
661 * that differs between the document and the struct cannot mis-assign a row.
662 */
663 void parse_lqxo(const std::string& resultfile) {
664 init_name_index();
665 const std::size_t n = sn_.nidx;
666 const double nan = detail::nan_value();
667 raw_ = LqnsRawAvg();
668 raw_.util.assign(n + 1, nan);
669 raw_.phase1util.assign(n + 1, nan);
670 raw_.phase2util.assign(n + 1, nan);
671 raw_.phase1svct.assign(n + 1, nan);
672 raw_.phase2svct.assign(n + 1, nan);
673 raw_.tput.assign(n + 1, nan);
674 raw_.procwaiting.assign(n + 1, nan);
675 raw_.procutil.assign(n + 1, nan);
676 raw_.residvisit.assign(n + 1, nan);
677 raw_.residt.assign(n + 1, nan);
678 raw_.callwaiting.assign(sn_.ncalls + 1, nan);
679
680 std::unique_ptr<xml::Element> doc;
681 try {
682 doc = xml::parse_file(resultfile);
683 } catch (const Error&) {
684 throw ExternalError(ErrorKind{"LQNS"},
685 "SolverLQNS: no readable result at " + resultfile +
686 "; the binary ran but wrote no .lqxo, which is what it does when it rejects the "
687 "model (run with verbose to see its diagnostics)");
688 }
689
690 for (const xml::Element* sp : doc->by_tag("solver-params")) {
691 const std::vector<const xml::Element*> g = sp->by_tag("result-general");
692 if (!g.empty()) raw_.iterations = static_cast<int>(detail::attr_num(g[0], "iterations"));
693 }
694
695 for (const xml::Element* pe : doc->by_tag("processor")) {
696 const std::size_t pidx = index_of(pe->attr("name"), lang::LqnElement::HOST);
697 const std::vector<const xml::Element*> pr = pe->by_tag("result-processor");
698 if (pidx && !pr.empty()) raw_.procutil[pidx] = detail::attr_num(pr[0], "utilization");
699
700 for (const xml::Element* te : pe->by_tag("task")) {
701 const std::size_t tidx = index_of(te->attr("name"), lang::LqnElement::TASK);
702 const std::vector<const xml::Element*> tr = te->by_tag("result-task");
703 double task_tput = nan;
704 if (!tr.empty()) {
705 task_tput = detail::attr_num(tr[0], "throughput");
706 if (tidx) {
707 raw_.util[tidx] = detail::attr_num(tr[0], "utilization");
708 raw_.phase1util[tidx] = detail::attr_num(tr[0], "phase1-utilization");
709 raw_.phase2util[tidx] = detail::attr_num(tr[0], "phase2-utilization");
710 raw_.tput[tidx] = task_tput;
711 raw_.procutil[tidx] = detail::attr_num(tr[0], "proc-utilization");
712 }
713 }
714
715 for (const xml::Element* ee : te->by_tag("entry")) {
716 const std::size_t eidx = index_of(ee->attr("name"), lang::LqnElement::ENTRY);
717 const std::vector<const xml::Element*> er = ee->by_tag("result-entry");
718 double entry_tput = nan;
719 if (!er.empty()) {
720 entry_tput = detail::attr_num(er[0], "throughput");
721 if (eidx) {
722 raw_.util[eidx] = detail::attr_num(er[0], "utilization");
723 raw_.phase1util[eidx] = detail::attr_num(er[0], "phase1-utilization");
724 raw_.phase2util[eidx] = detail::attr_num(er[0], "phase2-utilization");
725 raw_.phase1svct[eidx] = detail::attr_num(er[0], "phase1-service-time");
726 raw_.phase2svct[eidx] = detail::attr_num(er[0], "phase2-service-time");
727 raw_.tput[eidx] = entry_tput;
728 raw_.procutil[eidx] = detail::attr_num(er[0], "proc-utilization");
729 }
730 }
731
732 // PH1PH2 form: the phase activities carry their own results
733 const std::vector<const xml::Element*> epa =
734 ee->by_tag("entry-phase-activities");
735 if (epa.empty()) continue;
736 for (const xml::Element* ae : epa[0]->by_tag("activity")) {
737 read_activity(ae, entry_tput, true);
738 }
739 }
740
741 const std::vector<const xml::Element*> tal = te->by_tag("task-activities");
742 if (tal.empty()) continue;
743 for (const xml::Element* ae : tal[0]->by_tag("activity")) {
744 // A synch-call of a phase activity is nested inside the same
745 // subtree in some documents; only direct children of
746 // task-activities are the graph's own activities.
747 if (ae->parent != tal[0]) continue;
748 read_activity(ae, task_tput, false);
749 }
750 }
751 }
752
753 aggregate_entry_procutil();
754 aggregate_entry_svct();
755 compute_residt();
756 }
757
758 /**
759 * Residence time, on SolverLN's definition (its residt).
760 *
761 * The time an activity holds its host per cycle of its task: one
762 * execution's host-demand-mean + proc-waiting (no think time, as in
763 * SolverLN) weighted by the executions per task cycle X_a/X_t, and for a task the sum over its
764 * activities. lqns reports no such column, but the .lqxo carries every term
765 * of it. A task lqns never invoked (X_t = 0) holds its host for no time.
766 * Entries and processors have no ResidT in any solver and stay NaN, as does
767 * any row with a term unreported.
768 */
769 void compute_residt() {
770 const std::size_t n = sn_.nidx;
771 for (std::size_t a = 1; a <= sn_.nacts; ++a) {
772 const std::size_t aidx = sn_.ashift + a;
773 if (aidx > n || aidx >= sn_.parent.size()) continue;
774 const std::size_t tidx = sn_.parent[aidx];
775 if (tidx == 0 || tidx > n) continue;
776 const double xa = raw_.tput[aidx];
777 const double xt = raw_.tput[tidx];
778 const double rv = raw_.residvisit[aidx];
779 if (std::isnan(rv) || std::isnan(xa) || std::isnan(xt)) continue;
780 raw_.residt[aidx] = xt > lang::GlobalConstants::FineTol ? xa / xt * rv : 0.0;
781 }
782 for (std::size_t t = 1; t <= sn_.ntasks; ++t) {
783 const std::size_t tidx = sn_.tshift + t;
784 double sum = 0.0;
785 bool any = false;
786 bool complete = true;
787 for (std::size_t a = 1; a <= sn_.nacts; ++a) {
788 const std::size_t aidx = sn_.ashift + a;
789 if (aidx >= sn_.parent.size() || sn_.parent[aidx] != tidx) continue;
790 any = true;
791 if (std::isnan(raw_.residt[aidx])) {
792 complete = false;
793 break;
794 }
795 sum += raw_.residt[aidx];
796 }
797 if (any && complete) raw_.residt[tidx] = sum;
798 }
799 }
800
801 /**
802 * Phase-1 service time of an entry lqns never invoked.
803 *
804 * lqns omits `phase1-service-time` from `result-entry` exactly when the
805 * entry's throughput is zero: nothing was served, so there is no
806 * per-invocation mean to report. LINE then carried a NaN where the table
807 * says an entry HAS a response time and every other solver reports one,
808 * breaking the NaN mask -- see `_kb/06-solver-catalog.md`. The value is
809 * taken from the activity rows, and ONLY where they are unanimous: if every
810 * activity reachable from the entry reports a zero service time then every
811 * aggregation law agrees on zero -- the serial sum, the branch-weighted mean
812 * of an OrFork, the order statistic of an AndFork -- so the derivation does
813 * not depend on which one applies.
814 *
815 * It is deliberately NOT generalised the way `aggregate_entry_procutil` is.
816 * Utilizations add over an activity graph; response times do not. Measured
817 * over the example corpus, the sum over actsof reproduces
818 * `phase1-service-time` on serial chains only and misses it wherever the
819 * graph branches (`lqn_workflows` `Entry`: 12.5667 reported against 8.5667
820 * summed, `lqn_fork_open_arrival` `SE`: 0.841667 against 1.0), so a summed
821 * fallback would answer with a number lqns contradicts. An entry whose
822 * activities are unreported, absent, or not all zero keeps NaN.
823 */
824 void aggregate_entry_svct() {
825 for (std::size_t e = 1; e <= sn_.nentries; ++e) {
826 const std::size_t eidx = sn_.eshift + e;
827 if (eidx >= sn_.actsof.size() || eidx >= raw_.phase1svct.size()) continue;
828 if (!std::isnan(raw_.phase1svct[eidx])) continue;
829 const std::vector<std::size_t>& acts = sn_.actsof[eidx];
830 if (acts.empty()) continue;
831 bool all_zero = true;
832 for (std::size_t aidx : acts) {
833 if (aidx >= raw_.phase1svct.size() || std::isnan(raw_.phase1svct[aidx]) ||
834 raw_.phase1svct[aidx] != 0.0) {
835 all_zero = false;
836 break;
837 }
838 }
839 if (all_zero) raw_.phase1svct[eidx] = 0.0;
840 }
841 }
842
843 /**
844 * Processor utilization of an entry, aggregated from its activity graph.
845 *
846 * lqns credits host work to whichever level carries the host demand. In the
847 * activity-graph form an entry declares none, so lqns reports its
848 * result-entry proc-utilization as a literal 0 and the work sits on the
849 * result-activity rows; the entry's value is then the sum over the
850 * activities reachable from the entry within its own task, which is what
851 * actsof holds. In PH1PH2 form the same sum runs over the phase activities
852 * and reproduces the value lqns reports there, so no form test is needed. An
853 * entry with no activities, or any activity lqns left unreported, keeps the
854 * raw attribute rather than a partial sum.
855 */
856 void aggregate_entry_procutil() {
857 for (std::size_t e = 1; e <= sn_.nentries; ++e) {
858 const std::size_t eidx = sn_.eshift + e;
859 if (eidx >= sn_.actsof.size()) continue;
860 const std::vector<std::size_t>& acts = sn_.actsof[eidx];
861 if (acts.empty()) continue;
862 double sum = 0.0;
863 bool complete = true;
864 for (std::size_t aidx : acts) {
865 if (aidx >= raw_.procutil.size() || std::isnan(raw_.procutil[aidx])) {
866 complete = false;
867 break;
868 }
869 sum += raw_.procutil[aidx];
870 }
871 if (complete) raw_.procutil[eidx] = sum;
872 }
873 }
874
875 /**
876 * One `<activity>` and the calls it issues.
877 *
878 * @param ae the element
879 * @param owner_tput throughput of the entry (phase form) or task, used
880 * where lqns omits the activity's own
881 * @param phase_form true inside entry-phase-activities, where lqns omits
882 * both throughput and proc-utilization
883 */
884 void read_activity(const xml::Element* ae, double owner_tput, bool phase_form) {
885 const std::string aname = ae->attr("name");
886 const std::size_t aidx = index_of(aname, lang::LqnElement::ACTIVITY);
887 const std::vector<const xml::Element*> ar = ae->by_tag("result-activity");
888 if (aidx && !ar.empty()) {
889 const xml::Element* r = ar[0];
890 raw_.util[aidx] = detail::attr_num(r, "utilization");
891 raw_.phase1svct[aidx] = detail::attr_num(r, "service-time");
892 raw_.procwaiting[aidx] = detail::attr_num(r, "proc-waiting");
893 // Host residence of one execution: its demand plus the wait for the
894 // host. proc-waiting is a part of service-time, so one that is
895 // negative or exceeds it is not a measurement: lqns 6.2.31 writes
896 // uninitialised values there for some phase activities (6.96e+252 in
897 // its own 76-distributions model, 1.44e+161 in 94-5101-a2-q2b1) while
898 // service-time stays sane. Such a row reports NaN.
899 const double pw = raw_.procwaiting[aidx];
900 const double st = raw_.phase1svct[aidx];
901 raw_.residvisit[aidx] = (pw < 0 || (!std::isnan(st) && pw > st))
902 ? detail::nan_value()
903 : detail::attr_num(ae, "host-demand-mean") + pw;
904 const double t = detail::attr_num(r, "throughput");
905 // Each phase executes once per entry invocation, so an omitted
906 // throughput there IS the entry's; filling it with zero would say
907 // the activity never runs.
908 raw_.tput[aidx] = std::isnan(t) && phase_form ? owner_tput : t;
909 const double pu = detail::attr_num(r, "proc-utilization");
910 if (!std::isnan(pu)) {
911 raw_.procutil[aidx] = pu;
912 } else if (phase_form) {
913 const double hd = detail::attr_num(ae, "host-demand-mean");
914 if (!std::isnan(owner_tput) && !std::isnan(hd)) raw_.procutil[aidx] = owner_tput * hd;
915 }
916 }
917 if (!aidx) return;
918 read_calls(ae, aname, "synch-call", "=>");
919 read_calls(ae, aname, "asynch-call", "->");
920 }
921
922 void read_calls(const xml::Element* ae, const std::string& aname, const char* tag,
923 const char* arrow) {
924 for (const xml::Element* ce : ae->by_tag(tag)) {
925 const std::size_t cidx = call_index_of(aname + arrow + ce->attr("dest"));
926 const std::vector<const xml::Element*> cr = ce->by_tag("result-call");
927 if (cidx && !cr.empty()) raw_.callwaiting[cidx] = detail::attr_num(cr[0], "waiting");
928 }
929 }
930
931 lqn::LqnModel<T> model_;
932 LqnsOptions opt_;
933 lqn::LqnStruct<T> sn_;
934 LqnsRawAvg raw_;
935 std::map<std::pair<int, std::string>, std::size_t> byname_;
936 std::map<std::string, std::size_t> bycallname_;
937 double runtime_ = 0.0;
938 bool solved_ = false;
939};
940
941} // namespace lqns
942} // namespace line
943
944#endif // LINE_SOLVERS_WRAPPERS_LQNS_SOLVER_LQNS_H
ExternalError(const std::string &what)
Definition error.h:126
Malformed or inconsistent input (dimensions, negative populations, ...): LINE:input:<kind>.
Definition error.h:103
InputError(const std::string &what)
Definition error.h:105
A refusal: the feature, method or analysis is not covered: LINE:unsupported:<kind>.
Definition error.h:117
UnsupportedError(const std::string &what)
Definition error.h:119
const LqnsOptions & options() const
const lqn::LqnStruct< T > & get_struct() const
void run_analyzer()
Run the binary and read its result back.
static bool is_stochastic_method(const std::string &method)
Only the lqsim methods draw random numbers.
static bool is_available()
True when a local binary is installed AND is 6.0 or greater.
SolverLQNS(const lqn::LqnModel< T > &model, const LqnsOptions &options=LqnsOptions())
static std::string version()
The version banner of the local binary, empty when there is none.
static bool has_local_binary()
True when the native lqns command answers on this machine, any release.
static std::vector< std::string > list_valid_methods()
const LqnsRawAvg & raw_avg()
Everything the .lqxo carried, before the column permutation.
double runtime() const
Wall-clock seconds of the last run, the reference's runtime.
LqnsSolution< T > get_ensemble_avg()
The six measures on the element index space.
std::vector< Matrix< T > > get_avg_tard()
getAvgTard(), inherited by the reference from NetworkSolver: mean class tardiness against the JobClas...
static std::vector< std::string > feature_set()
The per-layer feature set, as SolverLQNS.supports declares it.
static void step(const char *fmt,...)
Write one progress line.
The exception types the port throws.
Minimal HTTP/1.1 client, enough to talk to a line-*-rest service.
Running progress log of a LINE solver run (the "solver console").
Host ports of the LINE service containers.
options.timeout: one wall-clock budget per top-level solve, on a per-THREAD deadline stack.
.lqnx -> LqnStruct, a port of matlab/src/lang/layered/@LayeredNetwork/parseXML.m followed by ....
LqnModel -> .lqnx, a port of matlab/src/lang/layered/@LayeredNetwork/writeXML.m.
Is a usable lqns installed on this machine?
Dense matrix and non-owning view.
The method names of each solver, in listing order.
Response post_json(const std::string &url, const std::string &json, int timeoutMillis)
POST a JSON document.
Definition http.h:360
LqnElement
LQN element kinds, with the values of MATLAB LayeredNetworkElement.
Definition lang_types.h:505
bool in(const std::string &s, std::initializer_list< const char * > set)
std::string name(const Element *el, const std::string &key="name")
LqnWriteReport write_lqnx(const LqnModel< T > &m, const std::string &path, const std::string &model_name=std::string("LQN"), bool use_abstract_names=false, std::string *out_text=NULL)
Write a layered model as a .lqnx document.
Definition lqn_writer.h:220
std::string lqns_method_refusal(const lqn::LqnModel< T > &m, const std::string &method)
Whether lqns or lqsim can serve this layered model under method: empty when it can,...
const std::string & lqns_version()
The version banner of the local lqns, empty when there is none.
Definition lqns_probe.h:49
bool lqns_is_available()
True when lqns is installed AND is a release this port speaks.
Definition lqns_probe.h:69
std::vector< std::string > methods(const std::string &solver)
Every method name the solver can be asked for, in listing order.
std::string resolve_lqns_url(const std::string &configured)
URL the SolverLQNS remote path posts to, given LqnsOptions::remote_url.
Definition line_ports.h:123
std::string lqns_default_url()
Default LqnsOptions::remote_url.
Definition line_ports.h:70
std::vector< double > stat(const Matrix< double > &A)
Stationary distribution of a stochastic matrix: the left eigenvector for eigenvalue 1,...
Definition mg1.h:221
double sum(const Vec &a)
Definition spn_ispn.h:191
bool all_zero(const Mat &A)
Definition spn_ispn.h:133
ProcResult capture(const std::vector< std::string > &argv, int timeoutSeconds, bool mergeStderr=false)
Runs a command, capturing stdout and discarding stderr.
Definition subprocess.h:82
int timeout_kill_bound(int explicit_seconds, double grace=30.0)
The kill bound of a child that also has a bound of its OWN (explicit_seconds, not positive = none): t...
std::string make_temp_dir(const std::string &prefix, bool mountable=false)
Create a private scratch directory named after its caller.
Definition tempdir.h:84
void timeout_raise_if_killed_on_budget(const std::string &who)
A child process was killed on its bound: raise LINE:numerical:Timeout when the armed budget is what r...
std::unique_ptr< Element > parse_file(const std::string &path)
Read and parse a file.
Definition xml.h:290
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:51
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Definition error.h:37
static constexpr double FineTol
Definition lang_types.h:823
static constexpr double CoarseTol
Definition lang_types.h:824
The intermediate model, and the second stage that flattens it.
Definition lqn_reader.h:411
std::vector< detail::RawTask< T > > tasks
Definition lqn_reader.h:415
std::map< std::size_t, std::vector< detail::RawServerPool< T > > > proc_pools
Definition lqn_reader.h:441
std::vector< detail::RawProc > procs
Definition lqn_reader.h:414
std::map< std::size_t, CdScaling< T > > proc_jdscaling
Definition lqn_reader.h:439
std::map< std::size_t, CdScaling< T > > proc_cdscaling
Definition lqn_reader.h:437
std::map< std::size_t, std::vector< T > > proc_lldscaling
Queue-dependent service rates and compatibility pools declared on a HOST, by 0-based processor slot.
Definition lqn_reader.h:436
std::vector< detail::RawEntry< T > > entries
Definition lqn_reader.h:416
What the schema could not carry, one human-readable line per loss.
Definition lqn_writer.h:67
std::vector< std::string > dropped
Definition lqn_writer.h:68
Knobs of the wrapper, the subset of SolverOptions that reaches lqns.
Definition solver_lqns.h:84
bool keep
Keep the working directory, model and result file after the run.
Definition solver_lqns.h:99
std::string method
default | lqns | srvn | exactmva | srvn.exactmva | sim | lqsim | lqns.default
Definition solver_lqns.h:92
int timeout_seconds
Deadline for the child, in seconds; not positive waits indefinitely.
bool remote
Solve on a host running lqns-rest instead of on this machine.
std::string multiserver
conway | rolia | zhou | suri | reiser | schmidt | default (= rolia).
Definition solver_lqns.h:94
double samples
lqsim run length, -A; not positive leaves lqsim's own default.
Definition solver_lqns.h:96
std::string remote_url
lqns-rest at its allocated host port (line/io/line_ports.h); a verified lqns-rest on the legacy 8080 ...
Everything the .lqxo carries, indexed as the struct is.
std::vector< double > residvisit
host residence of ONE execution of an activity
std::vector< double > callwaiting
std::vector< double > residt
ResidT on SolverLN's definition, see compute_residt.
std::vector< double > procutil
std::vector< double > phase1util
std::vector< double > util
std::vector< double > phase2util
std::vector< double > phase1svct
std::vector< double > phase2svct
std::vector< double > procwaiting
std::vector< double > tput
The six measures, on the element index space, with a defined mask each.
std::vector< bool > defined_U
std::vector< T > UN
std::vector< bool > defined_W
std::vector< bool > defined_A
std::vector< bool > defined_Q
std::vector< T > RN
std::vector< bool > defined_R
std::vector< T > TN
std::vector< T > QN
std::vector< bool > defined_T
std::vector< T > AN
std::vector< T > WN
std::string attr(const std::string &key) const
Attribute value, or the empty string when absent (org.w3c.dom semantics).
Definition xml.h:63
Running an external command and capturing its output, with a deadline.
A scratch directory for the subprocess wrappers, the port's lineTempName.
A minimal XML DOM: read for the .lqnx interchange format, write for the JMT .jsimg and ....