![]() |
LINE Solver (C++)
Templated C++ port of the LINE queueing solver
|
Port of the model -> source code generators of matlab/src/io/: QN2MATLAB.m, QN2JAVA.m, LQN2JAVA.m, the generator form of LQN2MATLAB.m, and the LINE2MATLAB.m / LINE2JAVA.m dispatchers. More...
#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <fstream>#include <limits>#include <map>#include <ostream>#include <set>#include <sstream>#include <string>#include <vector>#include "line/api/mam/map_moment.h"#include "line/io/lqn_json_reader.h"#include "line/io/network_reader.h"#include "line/lang/distribution.h"#include "line/lang/lqn/lqn_builder.h"#include "line/lang/lqn/lqn_reader.h"#include "line/lang/lqn/lqn_writer.h"#include "line/lang/qn/network_builder.h"#include "line/lang/qn/network_struct.h"#include "line/util/error.h"Go to the source code of this file.
Classes | |
| struct | line::io::code_gen_detail::ProcSpec |
| One (station, class) process, reduced to what QN2MATLAB / QN2JAVA decide on. More... | |
| struct | line::io::code_gen_detail::Route |
| The (k, c, i, m, p) of every positive sn.rtnodes entry, in QN2MATLAB's loop order, 0-based. More... | |
Namespaces | |
| namespace | line |
| Conservation laws of a layered queueing network, enumerated from its structure. | |
| namespace | line::io |
| namespace | line::io::code_gen_detail |
Functions | |
| std::string | line::io::code_gen_detail::mfmt (const char *spec, double x) |
| f, e or g as MATLAB's fprintf prints it: C's text, with Inf / NaN spelt MATLAB's way. | |
| std::string | line::io::code_gen_detail::fmt_f (double x) |
| std::string | line::io::code_gen_detail::fmt_g (double x) |
| std::string | line::io::code_gen_detail::fmt_d (double x) |
| MATLAB d of a double: the integer when it is one, else MATLAB's e override. | |
| std::string | line::io::code_gen_detail::fmt_d (std::size_t x) |
| std::string | line::io::code_gen_detail::fmt_d (int x) |
| std::string | line::io::code_gen_detail::sched_property (lang::SchedStrategy s) |
| SchedStrategy.toProperty(SchedStrategy.toText(s)): the enum constant name. | |
| std::string | line::io::code_gen_detail::sched_feature (lang::SchedStrategy s) |
| strrep(SchedStrategy.toFeature(s),'_','.
| |
| template<class T> | |
| ProcSpec | line::io::code_gen_detail::proc_spec (const qn::NetworkStruct< T > &sn, std::size_t i, std::size_t k) |
| The branch of QN2MATLAB's process block for station i, class k (0-based). | |
| template<class T> | |
| std::size_t | line::io::code_gen_detail::fork_of (const qn::NetworkStruct< T > &sn, std::size_t j) |
| find(sn.fj(:,j)): the 1-based Fork node the 1-based Join node j closes. | |
| template<class T> | |
| std::size_t | line::io::code_gen_detail::empty_class_ref (const qn::NetworkStruct< T > &sn, std::size_t k) |
| zeroPopRefNode(sn, k) of QN2MATLAB / QN2JAVA: the NODE index (1-based) of the reference station of zero-population closed class k (0-based). | |
| template<class T> | |
| void | line::io::code_gen_detail::check_node_types (const qn::NetworkStruct< T > &sn, const char *who) |
| Refuses a node type neither MATLAB generator has a statement for. | |
| template<class T> | |
| std::vector< Route > | line::io::code_gen_detail::routes (const qn::NetworkStruct< T > &sn) |
| std::ofstream | line::io::code_gen_detail::open_out (const std::string &path) |
| Opens path for writing or throws, naming it. | |
| template<class T> | |
| void | line::io::qn2matlab (const qn::NetworkStruct< T > &sn, const std::string &model_name, std::ostream &os) |
| Port of QN2MATLAB(model, modelName, fid): a MATLAB script that rebuilds the network from its refreshed struct. | |
| template<class T> | |
| void | line::io::qn2matlab (qn::Network< T > &model, const std::string &model_name, std::ostream &os) |
| QN2MATLAB on a model under construction; refreshes it first. | |
| template<class T> | |
| void | line::io::qn2matlab (qn::Network< T > &model, std::ostream &os) |
| QN2MATLAB with MATLAB's default model name. | |
| template<class T> | |
| void | line::io::qn2matlab (qn::Network< T > &model, const std::string &model_name, const std::string &path) |
| QN2MATLAB into a file, as MATLAB does when fid is a file name. | |
| template<class T> | |
| std::string | line::io::qn2matlab_string (qn::Network< T > &model, const std::string &model_name="myModel") |
| QN2MATLAB returned as a string. | |
| template<class T> | |
| void | line::io::qn2java (const qn::NetworkStruct< T > &sn, const std::string &model_name, std::ostream &os, bool headers=true) |
| Port of QN2JAVA(model, modelName, fid, headers): the body of a JLINE method public static Network ex() that rebuilds the network. | |
| template<class T> | |
| void | line::io::qn2java (qn::Network< T > &model, const std::string &model_name, std::ostream &os, bool headers=true) |
| QN2JAVA on a model under construction; refreshes it first. | |
| template<class T> | |
| void | line::io::qn2java (qn::Network< T > &model, std::ostream &os) |
| QN2JAVA with MATLAB's default model name. | |
| template<class T> | |
| void | line::io::qn2java (qn::Network< T > &model, const std::string &model_name, const std::string &path, bool headers=true) |
| QN2JAVA into a file. | |
| template<class T> | |
| std::string | line::io::qn2java_string (qn::Network< T > &model, const std::string &model_name="myModel", bool headers=true) |
| QN2JAVA returned as a string. | |
| std::string | line::io::code_gen_detail::j_num (double v) |
| jnum: a Java double literal at the shortest spelling that reads back as v. | |
| template<class T> | |
| std::string | line::io::code_gen_detail::j_num_t (const T &v) |
| template<class T> | |
| std::string | line::io::code_gen_detail::j_arr (const std::vector< T > &v) |
| jarr: a new double[]{...} literal. | |
| template<class T> | |
| std::string | line::io::code_gen_detail::j_mat_row (const std::vector< T > &v) |
| jmat of a row vector: new Matrix(new double[][]{{a, b}}). | |
| template<class T> | |
| std::string | line::io::code_gen_detail::j_mat (const Matrix< T > &m) |
| jmat of a matrix, row by row. | |
| std::string | line::io::code_gen_detail::j_round (double v) |
| template<class T> | |
| std::string | line::io::code_gen_detail::java_dist (const lang::Distrib< T > &d) |
| javaDist: the Java constructor call rebuilding d with the same parameters. | |
| template<class T> | |
| std::vector< std::vector< bool > > | line::io::code_gen_detail::reply_graph (const lqn::LqnModel< T > &m, const lqn::LqnStruct< T > &sn) |
| sn.replygraph: (nacts+1) x (nentries+1), 1-based, true where the activity replies to the entry. | |
| template<class T> | |
| std::size_t | line::io::code_gen_detail::and_join_quorum (const lqn::LqnModel< T > &m, std::size_t tslot, const std::string &post_name) |
| The quorum of the AND-join into post_name on task slot tslot, 0 when it declares none. | |
| std::string | line::io::code_gen_detail::upper_nospace (const std::string &s) |
| template<class T> | |
| void | line::io::lqn2java (const lqn::LqnModel< T > &model, const std::string &model_name, std::ostream &os) |
| Port of LQN2JAVA(model, modelName, fid): a JLINE program that rebuilds the layered network and solves it with SolverLN. | |
| template<class T> | |
| void | line::io::lqn2java (const lqn::LqnBuilder< T > &b, const std::string &model_name, std::ostream &os) |
| LQN2JAVA on a model under construction. | |
| template<class T> | |
| void | line::io::lqn2java (const lqn::LqnModel< T > &model, std::ostream &os) |
| LQN2JAVA with MATLAB's default model name. | |
| template<class T> | |
| void | line::io::lqn2java (const lqn::LqnModel< T > &model, const std::string &model_name, const std::string &path) |
| LQN2JAVA into a file. | |
| template<class T> | |
| std::string | line::io::lqn2java_string (const lqn::LqnModel< T > &model, const std::string &model_name="myLayeredModel") |
| LQN2JAVA returned as a string. | |
| std::string | line::io::code_gen_detail::m_scalar (double v) |
| scalar2code: a double at the shortest of 15..17 significant digits that reads back as itself. | |
| template<class T> | |
| std::string | line::io::code_gen_detail::m_scalar_t (const T &v) |
| template<class T> | |
| std::string | line::io::code_gen_detail::m_row (const std::vector< T > &v) |
| num2code of a row vector: [a, b], a scalar when it has one element, [] when empty. | |
| template<class T> | |
| std::string | line::io::code_gen_detail::m_matrix (const Matrix< T > &M) |
| num2code of a matrix: [a, b; c, d]. | |
| std::string | line::io::code_gen_detail::m_quote (const std::string &s) |
| q(str): a MATLAB single-quoted literal. | |
| std::string | line::io::code_gen_detail::m_cellstr (const std::vector< std::string > &c) |
| cellstr2code: {'a', 'b'}. | |
| std::string | line::io::code_gen_detail::m_repl (lang::ReplacementStrategy r) |
| template<class T> | |
| std::string | line::io::code_gen_detail::m_dist (const lang::Distrib< T > &d) |
| dist2code: the constructor call that rebuilds d from its parameters, which this port keeps in MATLAB getParam order. | |
| template<class T> | |
| bool | line::io::code_gen_detail::m_default_time (const lang::Distrib< T > &d) |
| True for a think / setup / delay-off time left at its constructor default. | |
| template<class T> | |
| std::string | line::io::code_gen_detail::m_prec (const lqn::detail::RawPrecedence< T > &ap) |
| The ActivityPrecedence expression of one declared precedence (precCode). | |
| template<class T> | |
| void | line::io::code_gen_detail::m_server_extras (std::ostream &os, const std::string &v, const std::string &owner, const Matrix< T > *A, const std::vector< T > *b, const std::vector< lqn::detail::RawLinConRow< T > > *rows, const std::vector< T > *lld, bool has_cd, bool has_jd, const std::vector< lqn::detail::RawServerPool< T > > *pools) |
| emitServerExtras: admission constraints, load dependence and server pools of a host or task. | |
| template<class T> | |
| void | line::io::lqn2matlab (const lqn::LqnModel< T > &m, const std::string &model_name, std::ostream &os) |
| Port of LQN2MATLAB(model, modelName, fid), the generator form: a MATLAB script that rebuilds the layered network by the constructors a user writes, with hosts, tasks, entries and activities in model order so the regenerated model has the same LayeredNetworkStruct indexing, and numbers at the shortest spelling that reads back bit for bit. | |
| template<class T> | |
| void | line::io::lqn2matlab (const lqn::LqnModel< T > &model, std::ostream &os) |
| LQN2MATLAB under the model's own name (myLayeredModel when it has none). | |
| template<class T> | |
| void | line::io::lqn2matlab (const lqn::LqnBuilder< T > &b, const std::string &model_name, std::ostream &os) |
| LQN2MATLAB on a model under construction. | |
| template<class T> | |
| void | line::io::lqn2matlab (const lqn::LqnModel< T > &model, const std::string &model_name, const std::string &path) |
| LQN2MATLAB into a file. | |
| template<class T> | |
| std::string | line::io::lqn2matlab_string (const lqn::LqnModel< T > &model, const std::string &model_name) |
| LQN2MATLAB returned as a string. | |
| template<class T> | |
| void | line::io::line2matlab (qn::Network< T > &model, std::ostream &os) |
| Port of LINE2MATLAB(model) for a Network: QN2MATLAB under the model's own name. | |
| template<class T> | |
| void | line::io::line2matlab (qn::Network< T > &model, const std::string &path) |
| Port of LINE2MATLAB(model, filename) for a Network. | |
| template<class T> | |
| void | line::io::line2java (qn::Network< T > &model, std::ostream &os) |
| Port of LINE2JAVA(model) for a Network: QN2JAVA under the model's own name. | |
| template<class T> | |
| void | line::io::line2java (qn::Network< T > &model, const std::string &path) |
| Port of LINE2JAVA(model, filename) for a Network. | |
| template<class T> | |
| void | line::io::line2java (const lqn::LqnModel< T > &model, const std::string &model_name, std::ostream &os) |
| Port of LINE2JAVA(model) for a LayeredNetwork. | |
| template<class T> | |
| void | line::io::line2java (const lqn::LqnModel< T > &model, const std::string &model_name, const std::string &path) |
| Port of LINE2JAVA(model, filename) for a LayeredNetwork. | |
| template<class T> | |
| void | line::io::line2matlab (const lqn::LqnModel< T > &model, std::ostream &os) |
| Port of LINE2MATLAB(model) for a LayeredNetwork: LQN2MATLAB under the model's own name. | |
| template<class T> | |
| void | line::io::line2matlab (const lqn::LqnModel< T > &model, const std::string &path) |
| Port of LINE2MATLAB(model, filename) for a LayeredNetwork. | |
| template<class T> | |
| void | line::io::line2java (const lqn::LqnModel< T > &model, std::ostream &os) |
| Port of LINE2JAVA(model) for a LayeredNetwork under its own name (myLayeredModel when it has none). | |
| std::string | line::io::code_gen_detail::json_model_name (const std::string &path, const std::string &fallback) |
| The name of the model in a model.json envelope, fallback when it has none. | |
| template<class T = double> | |
| void | line::io::line2java_json (const std::string &json_path, std::ostream &os) |
| LINE2JAVA on a model.json file, dispatching on the model type as MATLAB dispatches on the class of the object: a LayeredNetwork goes to LQN2JAVA and any other network to QN2JAVA, each under the name the document declares. | |
| template<class T = double> | |
| void | line::io::line2matlab_json (const std::string &json_path, std::ostream &os) |
| LINE2MATLAB on a model.json file: a LayeredNetwork goes to LQN2MATLAB, any other network to QN2MATLAB. | |
Port of the model -> source code generators of matlab/src/io/: QN2MATLAB.m, QN2JAVA.m, LQN2JAVA.m, the generator form of LQN2MATLAB.m, and the LINE2MATLAB.m / LINE2JAVA.m dispatchers.
LQN2MATLAB, unlike the others, re-declares the model rather than its struct; see lqn2matlab below.
WHAT IS WRITTEN IS THE STRUCT, NOT THE DECLARATIONS. Exactly as in MATLAB the queueing generators read sn after refresh: every process is re-expressed from the moments of its Markovian representation (sn.proc), so an SCV of at least 0.5 is written as Exp.fitMean (SCV 1) or APH.fitMeanAndSCV, a smaller one as an Erlang with round(1/SCV) phases, and a process with no representation as Disabled. The routing is the node-level sn.rtnodes, with a ClassSwitch written as a Router because the switching is already in the matrix. The layered generator reads the LayeredNetworkStruct, plus the declared reply activities and AND-join quorums the struct does not keep.
NUMERIC TEXT FOLLOWS MATLAB'S fprintf. d of a non-integer double prints in e form there (a routing share of 1/4 is 2.500000e-01), infinities print as Inf and NaN as NaN; the helpers below reproduce that, so a line of output is byte for byte the line MATLAB writes for the same struct.
WHERE THE C++ OUTPUT DELIBERATELY DIFFERS FROM MATLAB, it is because the MATLAB text is not valid source for its target:
Definition in file code_gen.h.