5#ifndef LINE_SOLVERS_WRAPPERS_LDES_SOLVER_LDES_H
6#define LINE_SOLVERS_WRAPPERS_LDES_SOLVER_LDES_H
103#include <sys/utsname.h>
125using Json = nlohmann::json;
132inline std::string shortest(
double v) {
134 for (
int prec = 15; prec <= 17; ++prec) {
135 std::snprintf(buf,
sizeof(buf),
"%.*g", prec, v);
136 if (std::strtod(buf,
nullptr) == v)
return std::string(buf);
138 return std::string(buf);
142inline Matrix<double> mat(
const Json& v) {
143 if (v.is_null() || !v.is_array() || v.empty())
return Matrix<double>();
144 if (!v[0].is_array()) {
145 Matrix<double> m(1, v.size());
146 for (std::size_t j = 0; j < v.size(); ++j)
147 m(0, j) = v[j].is_null() ? std::numeric_limits<double>::quiet_NaN()
148 : v[j].
get<double>();
151 std::size_t cols = 0;
152 for (std::size_t i = 0; i < v.size(); ++i)
153 if (v[i].is_array() && v[i].size() > cols) cols = v[i].size();
154 Matrix<double> m(v.size(), cols, std::numeric_limits<double>::quiet_NaN());
155 for (std::size_t i = 0; i < v.size(); ++i) {
156 if (!v[i].is_array())
continue;
157 for (std::size_t j = 0; j < v[i].size(); ++j)
158 if (!v[i][j].is_null()) m(i, j) = v[i][j].get<
double>();
164inline std::vector<double> vec(
const Json& v) {
165 std::vector<double> out;
166 if (!v.is_array())
return out;
167 out.reserve(v.size());
168 for (std::size_t i = 0; i < v.size(); ++i)
169 out.push_back(v[i].is_null() ? std::numeric_limits<double>::quiet_NaN()
170 : v[i].get<
double>());
175inline Matrix<double> sp_unclamp(Matrix<double> m) {
176 for (std::size_t i = 0; i < m.rows(); ++i)
177 for (std::size_t j = 0; j < m.cols(); ++j) {
178 if (m(i, j) >= 1e308) m(i, j) = std::numeric_limits<double>::infinity();
179 else if (m(i, j) <= -1e308) m(i, j) = -std::numeric_limits<double>::infinity();
185inline void unclamp_tree(Json& j) {
186 if (j.is_number_float()) {
187 const double v = j.get<
double>();
188 if (v >= 1e308) j = std::numeric_limits<double>::infinity();
189 else if (v <= -1e308) j = -std::numeric_limits<double>::infinity();
190 }
else if (j.is_array() || j.is_object()) {
191 for (Json& x : j) unclamp_tree(x);
208inline Json parse_result_json(
const std::string& text) {
210 t.reserve(text.size());
211 bool in_string =
false, escaped =
false;
212 for (std::size_t i = 0; i < text.size(); ++i) {
213 const char c = text[i];
216 if (escaped) escaped =
false;
217 else if (c ==
'\\') escaped =
true;
218 else if (c ==
'"') in_string =
false;
223 }
else if (c ==
'1' && text.compare(i, 5,
"1e999") == 0 &&
224 (i == 0 || !(std::isdigit(
static_cast<unsigned char>(text[i - 1])) || text[i - 1] ==
'.')) &&
225 (i + 5 == text.size() || !std::isdigit(
static_cast<unsigned char>(text[i + 5])))) {
232 Json j = Json::parse(t,
nullptr,
false);
233 if (!j.is_discarded()) unclamp_tree(j);
237inline const Json& field(
const Json& o,
const char* key) {
238 static const Json null_value;
239 return o.is_object() && o.contains(key) ? o[key] : null_value;
243inline std::string read_file(
const std::string& path) {
244 std::ifstream
in(path.c_str(), std::ios::binary);
245 if (!in)
throw InputError(
"SolverLDES: cannot open the model document '" + path +
"'");
246 std::ostringstream ss;
251inline void write_file(
const std::string& path,
const std::string& text) {
252 std::ofstream out(path.c_str(), std::ios::binary);
253 if (!out)
throw InputError(
"SolverLDES: cannot write '" + path +
"'");
292inline bool document_postdates_native(
const std::string& doc) {
293 static const char* keys[] = {
"\"classDependence\"",
294 "\"loadDependence\"",
"\"jointDependence\""};
295 for (std::size_t i = 0; i <
sizeof(keys) /
sizeof(keys[0]); ++i)
296 if (doc.find(keys[i]) != std::string::npos)
return true;
313 if ((o.
method ==
"parallel" || o.
method ==
"para") && reps <= 1) reps = 8;
314 return reps > 1 ? reps : 1;
329 const std::vector<std::string>& extra) {
330 std::vector<std::string> f;
333 f.push_back(std::to_string(budget));
334 f.push_back(
"--seed");
335 f.push_back(std::to_string(o.
seed));
337 f.push_back(
"--method");
341 f.push_back(
"--cnvgon");
343 f.push_back(
"--cnvgtol");
344 f.push_back(detail::shortest(o.
cnvgtol));
347 f.push_back(
"--cnvgbatch");
348 f.push_back(std::to_string(o.
cnvgbatch));
351 f.push_back(
"--cnvgchk");
352 f.push_back(std::to_string(o.
cnvgchk));
356 f.push_back(
"--tranfilter");
360 f.push_back(
"--warmupfrac");
364 f.push_back(
"--tranobs");
365 f.push_back(std::to_string(o.
tranobs));
368 f.push_back(
"--mserbatch");
369 f.push_back(std::to_string(o.
mserbatch));
372 f.push_back(
"--cimethod");
376 f.push_back(
"--obmoverlap");
380 f.push_back(
"--ciminbatch");
384 f.push_back(
"--ciminobs");
385 f.push_back(std::to_string(o.
ciminobs));
388 f.push_back(
"--spectrallowfreqfrac");
394 f.push_back(
"--slotted");
396 f.push_back(
"--slotlength");
404 f.push_back(
"--replications");
405 f.push_back(std::to_string(reps));
407 f.push_back(
"--numthreads");
412 f.push_back(
"--timespan");
413 f.push_back(detail::shortest(o.
t0) +
"," + detail::shortest(o.
t1));
416 f.push_back(
"--maxtime");
417 f.push_back(detail::shortest(o.
timeout));
420 f.push_back(
"--busyperiod");
427 f.push_back(
"--busyperiod-subnet");
433 for (std::size_t i = 0; i < o.
init_sol.size(); ++i)
434 v += (i ?
"," :
"") + detail::shortest(o.
init_sol[i]);
435 f.push_back(
"--initsol");
442 v += (r && !c ?
";" : (c ?
"," :
"")) + detail::shortest(o.
init_jobs(r, c));
443 f.push_back(
"--initjobs");
448 f.push_back(
"--sample-path");
451 for (std::size_t i = 0; i < extra.size(); ++i) f.push_back(extra[i]);
470 const std::vector<std::string>& flags) {
472 std::vector<LdesRunner> out;
473 const std::string native = detail::native_ldes_path(dir);
474 if (!native.empty()) {
476 r.
argv.push_back(native);
477 r.
argv.push_back(
"solve");
481 const std::string java = detail::find_java();
482 const std::string jar = dir.empty() ? std::string() : dir +
"/ldes.jar";
483 if (!java.empty() && detail::is_file(jar)) {
485 r.
argv.push_back(java);
486 r.
argv.push_back(
"-jar");
487 r.
argv.push_back(jar);
488 r.
argv.push_back(
"solve");
493 if (out.size() > 1) {
497 bool prefer_jar = detail::document_postdates_native(doc);
498 for (std::size_t i = 0; i < flags.size() && !prefer_jar; ++i)
499 prefer_jar = flags[i] ==
"--respt-samples";
500 if (prefer_jar) std::swap(out[0], out[1]);
511inline detail::Json
ldes_solve_rest(
const std::string& base_url,
const std::string& doc,
512 const std::vector<std::string>& flags,
double timeout) {
513 std::string url = base_url;
514 while (!url.empty() && url[url.size() - 1] ==
'/') url.erase(url.size() - 1);
515 if (url.size() < 6 || url.compare(url.size() - 6, 6,
"/solve") != 0) url +=
"/api/v1/solve";
517 detail::Json payload = detail::Json::object();
518 detail::Json model = detail::Json::object();
519 model[
"content"] = doc;
520 model[
"base64"] =
false;
521 payload[
"model"] = model;
522 detail::Json fl = detail::Json::array();
523 for (std::size_t i = 0; i < flags.size(); ++i) fl.push_back(flags[i]);
524 payload[
"flags"] = fl;
528 const int millis = (timeout > 0.0 && std::isfinite(timeout) && timeout < 2.0e6)
529 ?
static_cast<int>((timeout + 30.0) * 1000.0)
538 if (resp.
body.empty())
540 std::to_string(resp.
status) +
" with no body");
541 detail::Json out = detail::parse_result_json(resp.
body);
542 if (out.is_discarded() || !out.is_object())
544 " returned a non-JSON body: " + resp.
body);
545 if (!out.contains(
"status") || out[
"status"].get<std::string>() !=
"ok") {
546 const std::string msg = out.contains(
"message") ? out[
"message"].get<std::string>()
547 : std::string(
"unspecified error");
548 const std::string err = out.contains(
"stderr") ? out[
"stderr"].get<std::string>()
551 (err.empty() ?
"" :
" (engine stderr: " + err +
")"));
553 return out[
"result"];
564 if (d.is_object() && d.contains(
"error"))
566 d[
"error"].get<std::string>());
567 if (!d.is_object() || !d.contains(
"format") || d[
"format"].get<std::string>() !=
"ldes-result")
569 "SolverLDES: the engine wrote a document that is not an ldes-result; the run did not "
573 r.
method = d.contains(
"method") && !d[
"method"].is_null() ? d[
"method"].get<std::string>()
574 : std::string(
"default");
575 if (d.contains(
"runtime")) r.runtime = d[
"runtime"].get<
double>();
576 if (d.contains(
"converged")) r.converged = d[
"converged"].get<
bool>();
577 if (d.contains(
"stoppingReason") && !d[
"stoppingReason"].is_null())
578 r.stopping_reason = d[
"stoppingReason"].get<std::string>();
582 if (d.contains(
"warnings") && d[
"warnings"].is_array())
583 for (
const auto& w : d[
"warnings"]) {
584 r.warnings.push_back(w.get<std::string>());
585 std::fprintf(stderr,
"[SolverLDES] Warning: %s\n", r.warnings.back().c_str());
587 if (d.contains(
"convergenceBatches")) r.convergence_batches = d[
"convergenceBatches"].get<
long>();
588 if (d.contains(
"totalSimulatedEvents"))
589 r.total_simulated_events = d[
"totalSimulatedEvents"].get<
long long>();
591 const detail::Json& dim = detail::field(d,
"dimensions");
592 if (dim.is_object()) {
593 if (dim.contains(
"nstations")) r.nstations = dim[
"nstations"].get<std::size_t>();
594 if (dim.contains(
"nclasses")) r.nclasses = dim[
"nclasses"].get<std::size_t>();
595 if (dim.contains(
"nchains")) r.nchains = dim[
"nchains"].get<std::size_t>();
596 if (dim.contains(
"stationNames"))
597 for (std::size_t i = 0; i < dim[
"stationNames"].size(); ++i)
598 r.station_names.push_back(dim[
"stationNames"][i].get<std::string>());
599 if (dim.contains(
"classNames"))
600 for (std::size_t i = 0; i < dim[
"classNames"].size(); ++i)
601 r.class_names.push_back(dim[
"classNames"][i].get<std::string>());
604 const detail::Json& m = detail::field(d,
"metrics");
605 r.QN = detail::mat(detail::field(m,
"QN"));
606 r.UN = detail::mat(detail::field(m,
"UN"));
607 r.RN = detail::mat(detail::field(m,
"RN"));
608 r.TN = detail::mat(detail::field(m,
"TN"));
609 r.AN = detail::mat(detail::field(m,
"AN"));
610 r.WN = detail::mat(detail::field(m,
"WN"));
611 r.CN = detail::mat(detail::field(m,
"CN"));
612 r.XN = detail::mat(detail::field(m,
"XN"));
613 r.DropRateJoin = detail::mat(detail::field(m,
"DropRateJoin"));
615 const detail::Json& ci = detail::field(d,
"confidenceIntervals");
616 r.QNCI = detail::mat(detail::field(ci,
"QNCI"));
617 r.UNCI = detail::mat(detail::field(ci,
"UNCI"));
618 r.RNCI = detail::mat(detail::field(ci,
"RNCI"));
619 r.TNCI = detail::mat(detail::field(ci,
"TNCI"));
620 r.ANCI = detail::mat(detail::field(ci,
"ANCI"));
621 r.WNCI = detail::mat(detail::field(ci,
"WNCI"));
623 const detail::Json& rp = detail::field(d,
"relativePrecision");
624 r.QNRelPrec = detail::mat(detail::field(rp,
"QNRelPrec"));
625 r.UNRelPrec = detail::mat(detail::field(rp,
"UNRelPrec"));
626 r.RNRelPrec = detail::mat(detail::field(rp,
"RNRelPrec"));
627 r.TNRelPrec = detail::mat(detail::field(rp,
"TNRelPrec"));
629 const detail::Json& sc = detail::field(d,
"sampleCounts");
630 r.QNSamples = detail::mat(detail::field(sc,
"QNSamples"));
631 r.UNSamples = detail::mat(detail::field(sc,
"UNSamples"));
632 r.RNSamples = detail::mat(detail::field(sc,
"RNSamples"));
633 r.TNSamples = detail::mat(detail::field(sc,
"TNSamples"));
635 const detail::Json& fcr = detail::field(d,
"fcr");
636 if (fcr.is_object()) {
637 if (fcr.contains(
"nregions")) r.nregions = fcr[
"nregions"].get<std::size_t>();
638 r.QNfcr = detail::mat(detail::field(fcr,
"QNfcr"));
639 r.UNfcr = detail::mat(detail::field(fcr,
"UNfcr"));
640 r.RNfcr = detail::mat(detail::field(fcr,
"RNfcr"));
641 r.TNfcr = detail::mat(detail::field(fcr,
"TNfcr"));
642 r.ANfcr = detail::mat(detail::field(fcr,
"ANfcr"));
643 r.WNfcr = detail::mat(detail::field(fcr,
"WNfcr"));
644 r.WeightNfcr = detail::mat(detail::field(fcr,
"WeightNfcr"));
645 r.MemOccNfcr = detail::mat(detail::field(fcr,
"MemOccNfcr"));
646 r.DropRateNfcr = detail::mat(detail::field(fcr,
"DropRateNfcr"));
650 const detail::Json& fjb = detail::field(d,
"forkJoin");
651 if (fjb.is_object()) {
652 const detail::Json& fk = detail::field(fjb,
"forks");
653 const detail::Json& jn = detail::field(fjb,
"joins");
654 for (std::size_t p = 0; fk.is_array() && p < fk.size(); ++p)
655 r.fj_forks.push_back(fk[p].is_string() ? fk[p].get<std::string>() : std::string());
656 for (std::size_t p = 0; jn.is_array() && p < jn.size(); ++p)
657 r.fj_joins.push_back(jn[p].is_string() ? jn[p].get<std::string>() : std::string());
658 r.FJQLen = detail::mat(detail::field(fjb,
"FJQLen"));
659 r.FJRespT = detail::mat(detail::field(fjb,
"FJRespT"));
660 r.FJTput = detail::mat(detail::field(fjb,
"FJTput"));
663 const detail::Json& imp = detail::field(d,
"impatience");
664 if (imp.is_object()) {
665 r.renegedCustomers = detail::mat(detail::field(imp,
"renegedCustomers"));
666 r.avgRenegingWaitTime = detail::mat(detail::field(imp,
"avgRenegingWaitTime"));
667 r.renegingRate = detail::mat(detail::field(imp,
"renegingRate"));
668 r.balkedCustomers = detail::mat(detail::field(imp,
"balkedCustomers"));
669 r.balkingProbability = detail::mat(detail::field(imp,
"balkingProbability"));
670 r.retriedCustomers = detail::mat(detail::field(imp,
"retriedCustomers"));
671 r.retrialDropped = detail::mat(detail::field(imp,
"retrialDropped"));
672 r.avgOrbitSize = detail::mat(detail::field(imp,
"avgOrbitSize"));
675 const detail::Json& cm = detail::field(d,
"cacheMetrics");
677 for (detail::Json::const_iterator it = cm.begin(); it != cm.end(); ++it) {
679 c.
hit = detail::mat(detail::field(it.value(),
"hit"));
680 c.
delayed = detail::mat(detail::field(it.value(),
"delayed"));
681 c.
miss = detail::mat(detail::field(it.value(),
"miss"));
682 c.
latency = detail::mat(detail::field(it.value(),
"latency"));
683 c.
hitList = detail::mat(detail::field(it.value(),
"hitList"));
684 c.
itemProb = detail::mat(detail::field(it.value(),
"itemProb"));
685 c.
listCost = detail::mat(detail::field(it.value(),
"listCost"));
686 r.cache_metrics[it.key()] = c;
689 const detail::Json& bp = detail::field(d,
"busyPeriods");
690 if (bp.is_object()) {
691 const detail::Json& targets = detail::field(bp,
"targets");
692 for (std::size_t i = 0; i < targets.size(); ++i) {
694 const detail::Json& tj = targets[i];
695 if (tj.contains(
"name") && tj[
"name"].is_string())
696 t.
name = tj[
"name"].get<std::string>();
697 const detail::Json& st = detail::field(tj,
"stations");
698 for (std::size_t k = 0; k < st.size(); ++k)
699 t.
stations.push_back(
static_cast<std::size_t
>(st[k].get<
double>()));
700 if (tj.contains(
"class") && tj[
"class"].is_number())
701 t.
job_class =
static_cast<int>(tj[
"class"].get<
double>());
702 t.
mean = detail::vec(detail::field(tj,
"mean"));
703 t.
count = detail::vec(detail::field(tj,
"count"));
704 r.busy_periods.push_back(t);
708 const detail::Json& js = detail::field(d,
"jobState");
709 if (js.is_object()) {
710 r.finalJobs = detail::mat(detail::field(js,
"finalJobs"));
711 r.jobDepartures = detail::mat(detail::field(js,
"jobDepartures"));
718 const detail::Json& spj = detail::field(d,
"samplePath");
719 if (spj.is_object()) {
721 sp.
t = detail::vec(detail::field(spj,
"t"));
722 const detail::Json& ev = detail::field(spj,
"events");
723 for (std::size_t k = 0; ev.is_array() && k < ev.size(); ++k)
724 sp.
events.push_back(detail::vec(ev[k]));
725 const detail::Json& nodes = detail::field(spj,
"statefulNodes");
726 const detail::Json& state = detail::field(spj,
"state");
727 const detail::Json& aggr = detail::field(spj,
"aggr");
728 const detail::Json& refusals = detail::field(spj,
"refusals");
729 const std::size_t nsf = nodes.is_array() ? nodes.size() : 0;
731 sp.
state.resize(nsf);
734 for (std::size_t f = 0; f < nsf; ++f) {
736 if (state.is_array() && f < state.size()) sp.
state[f] = detail::sp_unclamp(detail::mat(state[f]));
737 if (aggr.is_array() && f < aggr.size()) sp.
aggr[f] = detail::sp_unclamp(detail::mat(aggr[f]));
738 if (refusals.is_array() && f < refusals.size() && refusals[f].is_string())
739 sp.
refusals[f] = refusals[f].get<std::string>();
741 const detail::Json& ph = detail::field(spj,
"phases");
742 for (std::size_t f = 0; ph.is_array() && f < ph.size(); ++f) {
743 std::vector<int> row;
744 for (std::size_t k = 0; ph[f].is_array() && k < ph[f].size(); ++k)
745 row.push_back(
static_cast<int>(ph[f][k].get<
double>()));
748 if (spj.contains(
"unboundScripts") && spj[
"unboundScripts"].is_number())
750 if (spj.contains(
"simTime") && spj[
"simTime"].is_number())
751 sp.
sim_time = spj[
"simTime"].get<
double>();
752 r.has_sample_path =
true;
755 const detail::Json& hist = detail::field(d,
"stateHistogram");
756 if (hist.is_object()) {
757 r.histogram_space = detail::mat(detail::field(hist,
"space"));
758 r.histogram_time = detail::mat(detail::field(hist,
"time"));
759 r.traj_space = detail::mat(detail::field(hist,
"trajSpace"));
760 r.traj_time = detail::mat(detail::field(hist,
"trajTime"));
766 const detail::Json& tran = detail::field(d,
"transient");
767 if (tran.is_object()) {
768 r.t = detail::vec(detail::field(tran,
"t"));
769 const char* keys[3] = {
"QNt",
"UNt",
"TNt"};
770 std::vector<std::vector<Matrix<double>>>* dst[3] = {&r.QNt, &r.UNt, &r.TNt};
771 for (
int q = 0; q < 3; ++q) {
772 const detail::Json& blk = detail::field(tran, keys[q]);
773 if (!blk.is_array())
continue;
774 for (std::size_t i = 0; i < blk.
size(); ++i) {
775 std::vector<Matrix<double>> row;
776 for (std::size_t k = 0; k < blk[i].
size(); ++k)
777 row.push_back(detail::mat(blk[i][k]));
778 dst[q]->push_back(row);
782 const detail::Json& rts = tran.is_object() && tran.contains(
"respTimeSamples")
783 ? tran[
"respTimeSamples"]
784 : detail::field(d,
"respTimeSamples");
786 for (std::size_t i = 0; i < rts.size(); ++i) {
787 std::vector<std::vector<double>> row;
788 for (std::size_t k = 0; k < rts[i].size(); ++k) row.push_back(detail::vec(rts[i][k]));
789 r.respTimeSamples.push_back(row);
793 const detail::Json& rtr = detail::field(d,
"respTimeSamplesRep");
795 for (std::size_t q = 0; q < rtr.size(); ++q) {
796 std::vector<std::vector<std::vector<double>>> blk;
797 for (std::size_t i = 0; rtr[q].is_array() && i < rtr[q].size(); ++i) {
798 std::vector<std::vector<double>> row;
799 for (std::size_t k = 0; k < rtr[q][i].size(); ++k) row.push_back(detail::vec(rtr[q][i][k]));
802 r.respTimeSamplesRep.push_back(blk);
826 const std::vector<std::string>& extra_flags =
827 std::vector<std::string>()) {
834 const std::vector<std::string> flags =
ldes_flags(ob, extra_flags);
836 const std::string model_path = tmp.
file(
"model.json");
837 const std::string result_path = tmp.
file(
"result.json");
839 detail::write_file(model_path, doc);
848 const std::vector<LdesRunner> runners =
ldes_runners(doc, flags);
854 std::string last_err;
855 for (std::size_t i = 0; i < runners.size(); ++i) {
856 std::vector<std::string> argv = runners[i].argv;
857 argv.push_back(model_path);
858 argv.push_back(
"-o");
859 argv.push_back(result_path);
860 for (std::size_t j = 0; j < flags.size(); ++j) argv.push_back(flags[j]);
861 std::remove(result_path.c_str());
864 for (std::size_t j = 0; j < argv.size(); ++j)
line += (j ?
" " :
"") + argv[j];
865 std::fprintf(stderr,
"SolverLDES command: %s\n",
line.c_str());
868 runners[i].
engine.c_str());
876 if (p.
exitCode == 0 && detail::is_file(result_path)) {
878 const std::string text = detail::read_file(result_path);
879 detail::Json parsed = detail::parse_result_json(text);
880 if (parsed.is_discarded())
883 r.engine = runners[i].engine;
890 std::to_string(runners.size()) +
" runner(s); " + last_err);
895 const std::vector<std::string>& extra_flags =
896 std::vector<std::string>()) {
940 const std::vector<LdesStateQuery>& query) {
943 "SolverLDES: this result carries no state histogram, so no state probability can be "
944 "read from it; the run has to pass --export-histogram");
946 throw InputError(
"SolverLDES: a state probability needs the model's class count");
949 for (std::size_t s = 0; s < nstates; ++s) total += r.
histogram_time(s, 0);
950 if (!(total > 0.0))
return 0.0;
953 for (std::size_t q = 0; q < query.size(); ++q) {
954 if (query[q].station == 0)
955 throw InputError(
"SolverLDES: a state query names station 0; stations are 1-based");
956 const std::size_t last = (query[q].station - 1) * nclasses + nclasses;
959 "SolverLDES: station " + std::to_string(query[q].station) +
960 " is past the end of the state histogram, which holds " + std::to_string(ncols) +
961 " columns for " + std::to_string(nclasses) +
" classes");
964 double matched = 0.0;
965 for (std::size_t s = 0; s < nstates; ++s) {
967 for (std::size_t q = 0; q < query.size() && ok; ++q) {
968 const std::size_t base = (query[q].station - 1) * nclasses;
969 const std::size_t n = std::min(nclasses, query[q].counts.size());
970 for (std::size_t k = 0; k < n; ++k)
971 if (std::fabs(r.
histogram_space(s, base + k) - query[q].counts[k]) > 1e-9) {
978 return matched / total;
1001 std::size_t job_class) {
1007 std::sort(x.begin(), x.end());
1008 const std::size_t n = x.size();
1009 std::vector<double> tu, fu;
1010 for (std::size_t i = 0; i < n; ++i) {
1011 const double f =
static_cast<double>(i + 1) /
static_cast<double>(n);
1012 if (i + 1 < n && x[i + 1] == x[i])
continue;
1017 for (std::size_t i = 0; i < tu.size(); ++i) {
1059 std::vector<double> p = percentiles;
1060 if (p.empty()) p = {10, 25, 50, 75, 90, 95, 99};
1061 bool percent =
false;
1062 for (std::size_t j = 0; j < p.size(); ++j)
1063 if (p[j] > 1.0) percent =
true;
1064 for (std::size_t j = 0; j < p.size(); ++j) {
1065 if (percent) p[j] /= 100.0;
1066 if (!(p[j] > 0.0) || !(p[j] < 1.0))
1068 "SolverLDES.getPerctRespT: percentiles must be fractions in (0,1) or "
1069 "percentages in (0,100)");
1086 const int R = replications > 1 ? replications : 1;
1087 const std::string want = R >= 2 ?
"firquest" :
"fquest";
1088 std::string m = method;
1089 std::transform(m.begin(), m.end(), m.begin(), [](
unsigned char c) { return std::tolower(c); });
1090 if (m.empty() || m ==
"default")
return want;
1091 if (m ==
"forktail")
1093 "SolverLDES.getPerctRespT: method 'forktail' is the base NetworkSolver percentile "
1094 "approximation, which the C++ solver facade does not carry; call "
1095 "fj::fj_tail_forktail directly for it");
1096 if (m ==
"fquest" || m ==
"firquest") {
1099 "SolverLDES.getPerctRespT: method '" + m +
"' does not match the replication count " +
1100 std::to_string(R) +
"; use 'fquest' with replications <= 1 and 'firquest' with "
1101 "replications >= 2 (or 'default')");
1105 "SolverLDES.getPerctRespT: unknown method '" + method +
1106 "'; expected 'default', 'fquest', 'firquest' or 'forktail'");
1112inline double ldes_empirical_quantile(std::vector<double> x,
double p) {
1113 std::sort(x.begin(), x.end());
1114 std::size_t k =
static_cast<std::size_t
>(std::ceil(
static_cast<double>(x.size()) * p));
1120inline bool ldes_quest_too_short(
const InputError& e) {
1121 const std::string w = e.what();
1122 return w.find(
"too short") != std::string::npos || w.find(
"exhausts") != std::string::npos;
1153 const std::vector<double>& percentiles,
1155 const std::string& method = std::string(),
1156 double level = 0.95,
long job_class = -1) {
1159 if (!(level > 0.0) || !(level < 1.0))
1160 throw InputError(
"SolverLDES.getPerctRespT: the confidence level must be in (0,1)");
1161 const double alpha = 1.0 - level;
1164 "SolverLDES.getPerctRespT needs the per-job response times the engine records under "
1165 "--respt-samples and the run returned none; raise the samples so completions are observed");
1166 const bool rep = used ==
"firquest";
1170 "SolverLDES.getPerctRespT: FIRQUEST needs the per-replication samples "
1171 "(respTimeSamplesRep) of a replicated run, and this result carries none; the engine "
1172 "that produced it predates them or ran a single path");
1175 throw InputError(
"SolverLDES.getPerctRespT: job class index " + std::to_string(job_class) +
1176 " is out of range");
1179 std::vector<LdesPercentileResult> out;
1182 if (job_class >= 0 && k !=
static_cast<std::size_t
>(job_class))
continue;
1184 if (pooled.empty())
continue;
1193 const std::size_t np = p.size();
1194 e.
values.assign(np, 0.0);
1195 e.
lower.assign(np, 0.0);
1196 e.
upper.assign(np, 0.0);
1200 std::vector<std::vector<double>> Y;
1202 std::size_t nmin = std::numeric_limits<std::size_t>::max();
1203 for (std::size_t q = 0; q < R; ++q) {
1205 const std::size_t len = (i < blk.
size() && k < blk[i].size()) ? blk[i][k].
size() : 0;
1206 nmin = std::min(nmin, len);
1209 for (std::size_t q = 0; q < R; ++q)
1218 bool too_short = rep && e.
samples == 0;
1219 for (std::size_t j = 0; j < np && !too_short; ++j) {
1229 if (!detail::ldes_quest_too_short(ex))
throw;
1234 const double nan = std::numeric_limits<double>::quiet_NaN();
1235 for (std::size_t j = 0; j < np; ++j) {
1236 e.
values[j] = detail::ldes_empirical_quantile(pooled, p[j]);
1243 std::fprintf(stderr,
1244 "[SolverLDES] Warning: getPerctRespT: station %s, class %s has %zu response-time "
1245 "samples, too few for %s; reporting the empirical quantile without a "
1246 "confidence interval\n",
1256 const std::vector<double>& percentiles,
1257 int replications,
const std::string& method,
1258 double level,
const std::string& job_class) {
1259 for (std::size_t k = 0; k < r.
class_names.size(); ++k)
1261 return ldes_perct_respt(r, percentiles, replications, method, level,
static_cast<long>(k));
1262 throw InputError(
"SolverLDES.getPerctRespT: no job class named '" + job_class +
"'");
1289 const std::vector<double>& counts, std::size_t nclasses) {
1290 std::vector<std::string> flags;
1291 flags.push_back(
"--export-histogram");
1293 std::vector<LdesStateQuery> q(1);
1294 q[0].station = station;
1295 q[0].counts = counts;
1306 if (target.
rows() == 0 || target.
cols() == 0)
1307 throw InputError(
"SolverLDES: getProbSysAggr needs an (nstations x nclasses) target state");
1308 std::vector<std::string> flags;
1309 flags.push_back(
"--export-histogram");
1311 const std::size_t K = target.
cols();
1312 std::vector<LdesStateQuery> q(target.
rows());
1313 for (std::size_t i = 0; i < target.
rows(); ++i) {
1314 q[i].station = i + 1;
1315 q[i].counts.resize(K);
1316 for (std::size_t k = 0; k < K; ++k) q[i].counts[k] = target(i, k);
1329 const std::size_t R =
sn.nclasses;
1333 for (std::size_t p = 0; p < out.
npairs(); ++p) {
1334 const std::string& fname =
sn.nodes[out.
forks[p] - 1].name;
1335 const std::string& jname =
sn.nodes[out.
joins[p] - 1].name;
1337 for (std::size_t k = 0; k < r.
fj_forks.size() && k < r.
fj_joins.size(); ++k)
1342 if (e == r.
fj_forks.size())
continue;
1343 for (
int m = 0; m < 3; ++m)
1344 for (std::size_t c = 0; c < R; ++c) {
1346 for (std::size_t k = 0; k < r.
class_names.size(); ++k)
1352 (e < src[m]->
rows() && cc < src[m]->cols()) ? (*src[m])(e, cc) : 0.0;
1353 (*dst[m])(p, c) = std::isfinite(v) ? v : 0.0;
1391 std::vector<std::string> out;
1392 if (QN.empty() || !
sn.regions.empty())
return out;
1393 for (std::size_t i = 0; i <
sn.nodes.size(); ++i)
1394 if (
sn.nodes[i].nodetype == qn::NodeType::Fork)
return out;
1395 const std::vector<double> njobs =
sn.njobs();
1396 for (std::size_t
nc = 0;
nc <
sn.nchains &&
nc <
sn.chains.size(); ++
nc) {
1397 double njobs_chain = 0.0;
1398 std::vector<std::size_t> inchain;
1399 for (std::size_t r = 0; r <
sn.chains[
nc].size() && r < njobs.size(); ++r)
1400 if (
sn.chains[
nc][r]) {
1401 inchain.push_back(r);
1402 njobs_chain += njobs[r];
1404 if (!(std::isfinite(njobs_chain) && njobs_chain > 0.0))
continue;
1406 for (std::size_t i = 0; i < QN.rows(); ++i)
1407 for (std::size_t k = 0; k < inchain.size(); ++k)
1408 if (inchain[k] < QN.cols() && !std::isnan(QN(i, inchain[k]))) qtot += QN(i, inchain[k]);
1409 if (std::fabs(qtot - njobs_chain) > std::max(0.05 * njobs_chain, 0.05)) {
1411 std::snprintf(buf,
sizeof(buf),
1412 "LDES returned %.3f jobs for closed chain %zu, whose population is %g: the engine "
1413 "dropped blocked jobs at a finite-capacity station, so these averages describe a "
1414 "different model. Use SolverCTMC/SolverSSA for capped closed networks, or rebuild "
1416 qtot,
nc + 1, njobs_chain);
1425 const std::vector<std::string>& extra_flags =
1426 std::vector<std::string>()) {
1433 for (std::size_t k = 0; k < w.size(); ++k)
1434 std::fprintf(stderr,
"[SolverLDES] Warning: %s\n", w[k].c_str());
1446 const std::vector<double>& percentiles,
1447 const std::string& method = std::string(),
1448 long job_class = -1) {
1467 std::vector<double>
t;
1490 throw InputError(
"SolverLDES: a sample path needs a positive number of rows (events)");
1496 "SolverLDES: the engine (" + r.
engine +
") returned no samplePath block for "
1497 "--sample-path; it predates the export, so rebuild common/ldes or common/ldes.jar");
1504 for (std::size_t k = 0; k < sp.
events.size(); ++k)
1505 if (sp.
events[k].size() >= 7 &&
1506 (node0 < 0 ||
static_cast<long>(sp.
events[k][3]) == node0))
1510 for (std::size_t k = 0; k < sp.
events.size(); ++k) {
1511 const std::vector<double>& e = sp.
events[k];
1512 if (e.size() < 7 || (node0 >= 0 &&
static_cast<long>(e[3]) != node0))
continue;
1528 if (
static_cast<std::size_t
>(sp.
stateful_nodes[f]) + 1 == ind)
return f;
1529 const std::string name = (ind >= 1 && ind <=
sn.nodes.size()) ?
sn.nodes[ind - 1].name
1530 :
"#" + std::to_string(ind);
1531 throw InputError(
"SolverLDES: node '" + name +
"' is not stateful and has no sample path");
1539 const std::size_t ind =
static_cast<std::size_t
>(sp.
stateful_nodes[f]) + 1;
1540 const std::string name = ind <=
sn.nodes.size() ?
sn.nodes[ind - 1].name
1541 :
"#" + std::to_string(ind);
1543 "SolverLDES: detailed sample-path rows are not available at node '" + name +
"' (" +
1544 sp.
refusals[f] +
"); sampleAggr and sampleSysAggr still apply.");
1554 std::size_t width = 0;
1555 for (std::size_t b = 0; b < out.
block.size(); ++b) width += out.
block[b].cols();
1557 std::size_t col = 0;
1558 for (std::size_t b = 0; b < out.
block.size(); ++b) {
1560 for (std::size_t i = 0; i < m.
rows() && i < sp.
t.size(); ++i)
1561 for (std::size_t j = 0; j < m.
cols(); ++j) out.
state(i, col + j) = m(i, j);
1577 std::size_t events) {
1581 out.
nodes.push_back(ind);
1591 std::size_t events) {
1596 out.
nodes.push_back(ind);
1609 std::size_t events) {
1624 std::size_t events) {
ExternalError(const std::string &what)
NumericError(const std::string &what)
UnsupportedError(const std::string &what)
Transport-level failure: unresolvable host, refused connection, timeout.
A network plus its refreshed NetworkStruct.
static VerboseLevel get_verbose()
The session verbosity.
static void step(const char *fmt,...)
Write one progress line.
std::string file(const std::string &name) const
A file inside it.
The RAII frame timeout_arm returns.
The exception types the port throws.
Fork-join section metrics: FJQLen, FJRespT and FJTput of every Fork/Join pair.
Minimal HTTP/1.1 client, enough to talk to a line-*-rest service.
The option and result records of SolverLDES, the discrete-event simulator.
Where the LDES engine is, and whether this machine can run it.
Running progress log of a LINE solver run (the "solver console").
options.timeout: one wall-clock budget per top-level solve, on a per-THREAD deadline stack.
Dense matrix and non-owning view.
Response post_json(const std::string &url, const std::string &json, int timeoutMillis)
POST a JSON document.
void require_finite_pas_buffers(const qn::NetworkStruct< T > &sn)
Refuse an OI/PAS station with no finite buffer before it reaches LDES.
detail::json network_json_envelope(const qn::NetworkStruct< T > &sn)
The complete model.json envelope: {format, version, model}.
std::size_t stateful_of(const qn::NetworkStruct< T > &sn, const LdesSamplePath &sp, std::size_t ind)
The stateful position of 1-based node ind in the block, or a refusal naming it.
Matrix< double > events(const LdesSamplePath &sp, long node0)
The event rows of node node0 (0-based), or of every node when it is negative.
const Matrix< double > & detail_rows(const qn::NetworkStruct< T > &sn, const LdesSamplePath &sp, std::size_t f)
The detailed rows of stateful position f, or the engine's refusal by name.
void finish(const LdesSamplePath &sp, LdesSample &out)
Fills t, the provenance fields and the joined state of an assembled sample.
LdesSamplePath run(const qn::NetworkStruct< T > &sn, const LdesOptions &o_in, std::size_t events)
Runs the engine with --sample-path events and returns its block.
LdesSample ldes_sample_aggr(const qn::NetworkStruct< T > &sn, const LdesOptions &o, std::size_t ind, std::size_t events)
sampleAggr(node, events): the same path as per-class counts, always available.
std::vector< LdesPercentileResult > ldes_perct_respt(const LdesResult &r, const std::vector< double > &percentiles, int replications, const std::string &method=std::string(), double level=0.95, long job_class=-1)
Port of @SolverLDES/getPerctRespT: steady-state response-time p-quantiles with confidence intervals,...
solvers::FjMetrics< double > ldes_fj_metrics(const qn::NetworkStruct< T > &sn, const LdesResult &r)
ldesParseForkJoin: the engine's "forkJoin" rows mapped onto the Fork/Join pairs of sn by (fork name,...
LdesSample ldes_sample_sys(const qn::NetworkStruct< T > &sn, const LdesOptions &o, std::size_t events)
sampleSys(events): the LINE State of every stateful node at each step, and every event of the run.
double ldes_prob_from_histogram(const LdesResult &r, std::size_t nclasses, const std::vector< LdesStateQuery > &query)
Residence-time probability of an aggregate joint state, from a parsed result.
LdesResult solver_ldes_text(const std::string &doc, const LdesOptions &o, const std::vector< std::string > &extra_flags=std::vector< std::string >())
Runs one LDES simulation on a model.json DOCUMENT and parses its result.
double ldes_prob_sys_aggr(const std::string &doc, const LdesOptions &o, const Matrix< double > &target)
Port of getProbSysAggr: the joint probability of a whole aggregate state.
LdesResult solver_ldes_file(const std::string &path, const LdesOptions &o, const std::vector< std::string > &extra_flags=std::vector< std::string >())
The same, reading the document from a file.
const std::string & ldes_engine_dir()
The directory holding the engine, or empty when there is none.
std::vector< std::string > ldes_flags(const LdesOptions &o, const std::vector< std::string > &extra)
The engine flags of one run, after solve <model> -o <result>.
double ldes_perct_level(const LdesOptions &o)
The confidence level getPerctRespT uses: confint when intervals are on (a level in (0,...
LdesSample ldes_sample_sys_aggr(const qn::NetworkStruct< T > &sn, const LdesOptions &o, std::size_t events)
sampleSysAggr(events): the per-class counts of every stateful node at each step.
Matrix< double > ldes_cdf_respt(const LdesResult &r, std::size_t station, std::size_t job_class)
Port of getCdfRespT: the EMPIRICAL response time CDF of one (station, class) pair,...
LdesSample ldes_sample(const qn::NetworkStruct< T > &sn, const LdesOptions &o, std::size_t ind, std::size_t events)
sample(node, events): the exact path of one stateful node (1-based ind), one LINE State row per step ...
std::vector< double > ldes_perct_levels(const std::vector< double > &percentiles)
The percentile levels as fractions: any entry above 1 makes the whole vector PERCENT,...
LdesResult parse_ldes_result(const detail::Json &d)
Parses one ldes-result document.
double ldes_prob_aggr(const std::string &doc, const LdesOptions &o, std::size_t station, const std::vector< double > &counts, std::size_t nclasses)
Port of getProbAggr: the marginal probability of a per-class job count at one station.
detail::Json ldes_solve_rest(const std::string &base_url, const std::string &doc, const std::vector< std::string > &flags, double timeout)
Solves through an LDES REST server and returns its result document.
int ldes_replications(const LdesOptions &o)
The replication count a run asks the engine for: replications when it is above one,...
LdesResult solver_ldes(const qn::NetworkStruct< T > &sn, const LdesOptions &o, const std::vector< std::string > &extra_flags=std::vector< std::string >())
std::vector< LdesRunner > ldes_runners(const std::string &doc, const std::vector< std::string > &flags)
The runners to try, in order (see the file header for why there are two and when the order flips).
std::string ldes_perct_method(int replications, const std::string &method)
The quantile procedure a replication count calls for: 'fquest' on one path (R <= 1),...
std::vector< std::string > ldes_closed_population_warnings(const qn::NetworkStruct< T > &sn, const Matrix< double > &QN)
The same, for a model built through the C++ API.
bool in(const std::string &s, std::initializer_list< const char * > set)
const std::string * get(const Element *el, const std::string &key)
el.get(key), with Python's None as a null pointer.
QuestResult< T > sim_fquest(const std::vector< T > &Y, double p, double alpha=0.05, const QuestOptions &options=QuestOptions())
Fixed-sample-size confidence interval for a steady-state quantile.
QuestResult< T > sim_firquest(const std::vector< std::vector< T > > &Y, double p, double alpha=0.05, const QuestOptions *options=nullptr)
Fixed-sample-size quantile interval from independent replications.
std::vector< std::pair< std::size_t, std::size_t > > fj_sorted_pairs(const S &sn)
The Fork/Join pairs of a struct, sortrows([forks joins]) over find(sn.fj): ascending in fork node,...
FjMetrics< T > fj_metrics_zero(const S &sn, std::size_t nclasses)
An empty-but-shaped result: every pair of sn, all three matrices zero.
void timeout_trip()
Mark the innermost budget tripped without reading the clock: for an external engine that REPORTS it s...
TimeoutScope timeout_arm(double budget)
Arm budget seconds for the scope's lifetime, capped by the outer frame's remaining time.
ProcResult capture(const std::vector< std::string > &argv, int timeoutSeconds, bool mergeStderr=false)
Runs a command, capturing stdout and discarding stderr.
std::string trim(const std::string &s)
Trims ASCII whitespace from both ends, as Java's String.trim() does.
double timeout_remaining()
Seconds left on the innermost armed budget; +Inf when none is armed.
int timeout_kill_seconds(double grace=30.0)
The hard kill bound of a child process under the armed budget: the remaining seconds plus grace,...
bool timeout_tripped()
Whether the innermost budget was tripped by a checkpoint or by timeout_trip.
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...
Conservation laws of a layered queueing network, enumerated from its structure.
qn::NetworkStruct -> model.json, the inverse of network_reader.h.
Fixed-sample-size quantile interval from independent replications.
Fixed-sample-size confidence interval for a steady-state quantile.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
An HTTP response, with the body already de-chunked.
std::string body
Response body, decoded.
int status
HTTP status code.
Per-cache hit/miss/latency, as the cacheMetrics block carries them.
Matrix< double > listCost
(1 x nlists) mean storage cost held per list
Matrix< double > latency
(1 x nclasses) expected retrieval latency
Matrix< double > hitList
(nclasses x nlists) hit probability by list
Matrix< double > itemProb
(nitems x nlists+1) item position law
Matrix< double > delayed
(1 x nclasses) delayed-hit probability
Matrix< double > miss
(1 x nclasses) miss probability
Matrix< double > hit
(1 x nclasses) hit probability
The knobs of one LDES run.
double warmupfrac
–warmupfrac, only for tranfilter=fixed
int ciminbatch
–ciminbatch
double spectral_low_freq_frac
–spectrallowfreqfrac
bool verbose
echo the resolved command line before running it
double confint
Confidence level of the reported half-widths.
std::string rest_url
Base URL of an LDES REST server (the imperialqore/ldes container).
double obmoverlap
–obmoverlap; 0 reduces OBM to plain batch means
std::vector< std::vector< std::size_t > > busy_period_subnets
–busyperiod-subnet, zero-based station indexes, one flag per set.
long seed
–seed; -1 requests a random stream
bool slotted
–slotted, run on the slot lattice
int mserbatch
–mserbatch, MSER batch size
std::string cimethod
–cimethod: obm | bm | spectral | none
double slot_length
–slotlength
Matrix< double > init_jobs
–initjobs, the JOB-LEVEL initial state, one row per job: [station, class, remaining,...
int tranobs
–tranobs, equally spaced transient observation points over [t0,t1]; fixes the time grid only.
int cnvgchk
–cnvgchk, events between checks; 0 = samples/50
int replications
–replications; 0 = not given (one path)
int sample_path_events
–sample-path N: record the exact sample path, N rows of SolverSSA-style events plus LINE State,...
bool track_jobs
–trackjobs: fill finalJobs and jobDepartures; implied by init_jobs.
int ciminobs
–ciminobs, below which no CI is reported
std::size_t events
0 = not given; overrides samples when set
int cnvgbatch
–cnvgbatch, batches before the first check
std::string tranfilter
–tranfilter: mser5 | fixed | none
std::vector< double > init_sol
–initsol, the warm-start placement as a STATION-MAJOR vector [st0_cl0, st0_cl1, .....
int numthreads
–numthreads; 0 = not given
std::size_t samples
-s, service-completion budget
double timeout
–maxtime, a COOPERATIVE wall-clock budget the event loop polls; the wrapper caps it by any options....
bool has_timespan
true when [t0,t1] was set: a TRANSIENT run
int busy_period_orders
–busyperiod: highest busy period order measured, 0 disabling the measurement.
One (station, class) row of getPerctRespT on SolverLDES: the steady-state response-time p-quantiles w...
std::vector< bool > heuristic
true where the fallback interval was used
std::string station
node name of the station
double level
confidence level
std::vector< double > halfwidth
halfwidths
std::vector< double > lower
lower confidence limits
std::size_t station_index
0-based station index in the result
std::vector< double > upper
upper confidence limits
std::vector< double > percentiles
fractions in (0,1)
std::size_t class_index
0-based class index in the result
std::string job_class
class name (class in MATLAB / Python)
std::size_t samples
observations used (per replication after trimming, times R)
std::vector< double > values
point estimates (QuestResult::estimate)
std::string method
"fquest" or "firquest"
One measured busy period target (–busyperiod): a station, a station-class pair, or a declared station...
std::vector< std::size_t > stations
station indexes, zero-based
std::vector< double > mean
std::vector< double > count
One ldes-result document, parsed.
std::vector< std::string > fj_forks
Fork and Join node NAMES of each pair, ordered by fork node then join node; empty without a pair.
Matrix< double > FJTput
getAvgFJ, FJQLen = FJTput * FJRespT
std::vector< std::vector< std::vector< double > > > respTimeSamples
[station][class] -> the per-job response times the engine recorded, in departure order.
bool has_sample_path
–sample-path: the recorded path; meaningful when has_sample_path.
std::vector< std::vector< std::vector< std::vector< double > > > > respTimeSamplesRep
[rep][station][class][j] -> the same samples kept PER REPLICATION, each in departure order with the w...
Matrix< double > histogram_space
The exact joint-state residence-time histogram (–export-histogram).
std::vector< std::string > class_names
std::string engine
"native" or "jar": which runner produced these numbers.
std::vector< std::string > station_names
std::vector< std::string > fj_joins
bool timed_out
True when the run stopped early on its wall-clock budget (timeout, or the options....
Matrix< double > histogram_time
LdesSamplePath sample_path
One runner: the argv prefix that runs the engine, and the name of its image.
std::vector< std::string > argv
up to and including "solve"
std::string engine
"native" or "jar"
The samplePath block (--sample-path N): one simulated path in SolverSSA's row convention.
std::vector< Matrix< double > > aggr
[stateful] per-class counts per row (Inf at a source).
std::vector< std::vector< double > > events
Rows {step, time, type, node, class, jobId, phase}.
std::vector< int > stateful_nodes
0-based node index of each stateful node, in stateful order.
std::vector< std::vector< int > > phases
[stateful][class] phase count used for the state layout.
std::vector< Matrix< double > > state
[stateful] detailed rows (empty when refused), left-padded to equal width.
std::vector< std::string > refusals
[stateful] why the detailed state is not recorded, empty when it is.
long long unbound_scripts
Drawn intervals no phase script could be bound to (recorded as one phase).
One exact sample path as sample, sampleAggr, sampleSys and sampleSysAggr return it,...
Matrix< double > state
The blocks side by side, the single matrix ssa::SsaSamplePath::state is.
std::vector< Matrix< double > > block
per node, rows aligned with t
double sim_time
the simulated clock at the stop
std::vector< std::size_t > nodes
1-based node index of each block of state
long long unbound_scripts
drawn intervals recorded as a single phase
Matrix< double > event
One row per event, [time, node, type, class, jobId, phase]: node and class 0-based as on the wire,...
bool aggregate
per-class counts rather than LINE State rows
std::vector< double > t
the step times, one per row
One constraint of a joint-state query: a station and the per-class job counts it is required to hold.
std::vector< double > counts
Point estimate and interval delivered by the QUEST procedures.
T halfwidth
(upper-lower)/2, attained only on average when asymmetric
T estimate
Full-sample empirical p-quantile of the truncated path.
T upper
Upper confidence limit, NaN if refused.
bool heuristic
True when a stage test failed.
T lower
Lower confidence limit, NaN if refused.
self.result.FJ: one row per Fork/Join pair, one column per class.
std::vector< std::size_t > forks
1-based fork node of each pair
Matrix< T > Tput
FJTput, P x R.
Matrix< T > QLen
FJQLen, P x R.
std::size_t npairs() const
std::vector< std::size_t > joins
1-based join node of each pair
Matrix< T > RespT
FJRespT, P x R.
Outcome of a captured command.
int exitCode
Exit status, or -1 when the command could not run.
bool timedOut
True when the deadline expired and the child was killed.
std::string out
Everything the command wrote to stdout.
Running an external command and capturing its output, with a deadline.
A scratch directory for the subprocess wrappers, the port's lineTempName.