LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
lqnx_io.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_IO_LQNX_IO_H
6#define LINE_IO_LQNX_IO_H
7
8/**
9 * @file
10 * @ingroup line_io
11 * The `.lqnx` (LQNS XML) interchange as a symmetric MODEL-LEVEL pair in `io::`.
12 *
13 * The implementations live in `lang/lqn/`: `lqn::read_lqnx_model` returns the
14 * `LqnModel` a builder produces, `lqn::write_lqnx` takes one, and
15 * `lqn::read_lqnx` returns the FINALIZED `LqnStruct` SolverLN consumes. The
16 * struct reader is the odd one out of that trio: its output cannot be handed
17 * back to the writer. So the io pair is `read_lqnx_model` / `write_lqnx`,
18 * both on `LqnModel`, keeping the `lqn::` names verbatim so a caller moving
19 * between the namespaces meets no second spelling. MATLAB spells the same pair
20 * `LayeredNetwork.parseXML` / `writeXML`, which name methods of a class this
21 * port does not have.
22 *
23 * The SRVN text grammar (`.in`) goes through this XML both ways: `read_srvn_model`
24 * / `srvn2lqnx` read it, `write_srvn` / `lqnx2srvn` write it, keeping the `lqn::` names.
25 */
26
27#include <string>
28
33
34namespace line {
35namespace io {
36
37/** Read a `.lqnx` file into the model-level `LqnModel`, which `write_lqnx` accepts back. */
38template <class T>
39lqn::LqnModel<T> read_lqnx_model(const std::string& path) {
40 return lqn::read_lqnx_model<T>(path);
41}
42
43/**
44 * Write an `LqnModel` as `.lqnx`; forwards to `lqn::write_lqnx`.
45 *
46 * @return what the schema could not carry (see `lqn::LqnWriteReport`)
47 */
48template <class T>
49lqn::LqnWriteReport write_lqnx(const lqn::LqnModel<T>& m, const std::string& path,
50 const std::string& model_name = std::string("LQN"),
51 bool use_abstract_names = false, std::string* out_text = NULL) {
52 return lqn::write_lqnx(m, path, model_name, use_abstract_names, out_text);
53}
54
55/**
56 * Read an SRVN file (the LQNS `.in` text grammar, or a `.lqn` that is not XML) into the
57 * model-level `LqnModel`; forwards to `lqn::read_srvn_model`.
58 */
59template <class T>
60lqn::LqnModel<T> read_srvn_model(const std::string& path) {
61 return lqn::read_srvn_model<T>(path);
62}
63
64/** Translate SRVN text into a `.lqnx` document; forwards to `lqn::srvn2lqnx`. */
65inline std::string srvn2lqnx(const std::string& src, const std::string& name = std::string("model")) {
66 return lqn::srvn2lqnx(src, name);
67}
68
69/** Translate a `.lqnx` document into SRVN text; forwards to `lqn::lqnx2srvn`. */
70inline std::string lqnx2srvn(const std::string& xml_text, const std::string& name = std::string()) {
71 return lqn::lqnx2srvn(xml_text, name);
72}
73
74/** Write an `LqnModel` as SRVN text (`write_lqnx`, then `lqnx2srvn`); forwards to `lqn::write_srvn`. */
75template <class T>
76void write_srvn(const lqn::LqnModel<T>& m, const std::string& path, bool use_abstract_names = false) {
77 lqn::write_srvn(m, path, use_abstract_names);
78}
79
80} // namespace io
81} // namespace line
82
83#endif // LINE_IO_LQNX_IO_H
.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.
std::string lqnx2srvn(const std::string &xml_text, const std::string &name=std::string())
Translate a .lqnx document into SRVN text; forwards to lqn::lqnx2srvn.
Definition lqnx_io.h:70
lqn::LqnModel< T > read_lqnx_model(const std::string &path)
Read a .lqnx file into the model-level LqnModel, which write_lqnx accepts back.
Definition lqnx_io.h:39
void write_srvn(const lqn::LqnModel< T > &m, const std::string &path, bool use_abstract_names=false)
Write an LqnModel as SRVN text (write_lqnx, then lqnx2srvn); forwards to lqn::write_srvn.
Definition lqnx_io.h:76
std::string srvn2lqnx(const std::string &src, const std::string &name=std::string("model"))
Translate SRVN text into a .lqnx document; forwards to lqn::srvn2lqnx.
Definition lqnx_io.h:65
lqn::LqnWriteReport write_lqnx(const lqn::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 an LqnModel as .lqnx; forwards to lqn::write_lqnx.
Definition lqnx_io.h:49
lqn::LqnModel< T > read_srvn_model(const std::string &path)
Read an SRVN file (the LQNS .in text grammar, or a .lqn that is not XML) into the model-level LqnMode...
Definition lqnx_io.h:60
LqnModel< T > read_lqnx_model(const std::string &path)
read_lqnx_model on a .lqnx file.
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 lqnx2srvn(const std::string &xml_text, const std::string &name=std::string())
Translate an LQN XML document into SRVN text.
LqnModel< T > read_srvn_model(const std::string &path)
Read an SRVN file (.in, or a .lqn that is not XML) into the intermediate LqnModel,...
std::string srvn2lqnx(const std::string &src, const std::string &name=std::string("model"))
Translate SRVN text into an LQN XML document.
void write_srvn(const LqnModel< T > &m, const std::string &path, bool use_abstract_names=false)
Write a layered model as SRVN text: write_lqnx, then lqnx2srvn, with LF line endings.
Conservation laws of a layered queueing network, enumerated from its structure.
Definition aoi_dist2ph.h:52
SRVN input format (the LQNS .in / .lqn text grammar) for layered models, the C++ twin of python/line_...
SRVN output (the LQNS .in text grammar) for layered models, the C++ twin of lqnx2srvn / srvn_save in ...
The intermediate model, and the second stage that flattens it.
Definition lqn_reader.h:411
What the schema could not carry, one human-readable line per loss.
Definition lqn_writer.h:67