5#ifndef LINE_IO_TIKZ_TIKZ_GRAPH_H
6#define LINE_IO_TIKZ_TIKZ_GRAPH_H
57 std::vector<std::vector<bool>>
conn;
66 for (std::size_t k = 0; k < t.size(); ++k)
67 if (t[k] >=
'a' && t[k] <=
'z') t[k] =
static_cast<char>(t[k] -
'a' +
'A');
80 if (std::isnan(v))
return "NaN";
81 const bool neg = std::signbit(v);
82 const double a = std::fabs(v);
83 if (std::isinf(a))
return neg ?
"-Infinity" :
"Infinity";
90 for (
int p = 1; p <= 17; ++p) {
91 std::snprintf(buf,
sizeof(buf),
"%.*e", p - 1, a);
92 if (std::strtod(buf,
nullptr) == a)
break;
94 const std::string s(buf);
95 const std::size_t e = s.find(
'e');
96 for (std::size_t k = 0; k < e; ++k)
97 if (s[k] !=
'.') digits.push_back(s[k]);
98 pt = std::atoi(s.c_str() + e + 1) + 1;
101 digits = std::string(
static_cast<std::size_t
>(1 - pt),
'0') + digits;
104 const std::size_t keep =
static_cast<std::size_t
>(pt + prec);
105 const bool round_up = digits.size() > keep && digits[keep] >=
'5';
106 if (digits.size() < keep) digits.append(keep - digits.size(),
'0');
109 std::size_t k = keep;
112 if (digits[k] ==
'9') {
119 digits.insert(digits.begin(),
'1');
124 std::string ip = digits.substr(0,
static_cast<std::size_t
>(pt));
125 const std::size_t nz = ip.find_first_not_of(
'0');
126 ip = (nz == std::string::npos) ? std::string(
"0") : ip.substr(nz);
127 std::string out = neg ?
"-" :
"";
129 if (prec > 0) out +=
"." + digits.substr(
static_cast<std::size_t
>(pt));
136 out.reserve(name.size());
137 for (std::size_t k = 0; k < name.size(); ++k) {
138 const unsigned char c =
static_cast<unsigned char>(name[k]);
139 if ((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') || (c >=
'0' && c <=
'9')) {
140 out.push_back(
static_cast<char>(c));
141 }
else if ((c & 0xC0) != 0x80) {
148inline void replace_all(std::string& s,
const std::string& from,
const std::string& to) {
150 while ((at = s.find(from, at)) != std::string::npos) {
151 s.replace(at, from.size(), to);
189 const std::size_t I =
sn.nodes.size();
191 for (std::size_t i = 0; i < I; ++i) {
202 g.
conn.assign(I, std::vector<bool>(I,
false));
204 for (
const auto& kv :
sn.P) {
206 for (std::size_t a = 0; a < B.
rows() && a < I; ++a)
207 for (std::size_t b = 0; b < B.
cols() && b < I; ++b)
208 if (!(B(a, b) == zero)) g.
conn[a][b] =
true;
212 if (
sn.sourceIdx > 0 &&
sn.sinkNode > 0 &&
sn.sourceIdx <=
sn.station_to_node.size()) {
213 const std::size_t src =
sn.station_to_node[
sn.sourceIdx - 1];
214 if (
sn.sinkNode <= I && src >= 1 && src <= I) g.
conn[
sn.sinkNode - 1][src - 1] =
false;
A network plus its refreshed NetworkStruct.
Enumerations and the minimal distribution descriptor shared by the model layer of the C++ port.
std::string escape_latex(std::string t)
TikZNodeRenderer.escapeLatex, applied in the SAME sequence of whole-string replacements,...
std::string sanitize_id(const std::string &name)
name.replaceAll("[^a-zA-Z0-9]", "_"): one underscore per CODE POINT, so a UTF-8 sequence is one chara...
std::string java_fixed(double v, int prec)
Java's String.format("%." + prec + "f", v).
void replace_all(std::string &s, const std::string &from, const std::string &to)
std::string java_sched_name(lang::SchedStrategy s)
Java's SchedStrategy.name(): the enumerator spelling, which is the upper-cased text of sched_to_text.
TikzGraph tikz_graph(const qn::NetworkStruct< T > &sn)
The drawable graph of a network struct.
SchedStrategy
Scheduling disciplines, with the values of MATLAB SchedStrategy.
const char * sched_to_text(SchedStrategy s)
NodeType
Node kinds, with the values of MATLAB NodeType.
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
Number-type abstraction for the templated API port.
Nodes in model order plus sn.connmatrix over them.
std::vector< std::vector< bool > > conn
conn[i][j]: node i is linked to node j, 0-based
std::vector< TikzNode > nodes
One node as the TikZ exporter sees it.
std::string sched
Java SchedStrategy.name() of a Queue (FCFSPRIO is HOL, as in MATLAB), empty when none.
double servers
a Queue's server count, infinite for an unbounded pool
bool queue_object
Declared as a Queue although its INF discipline makes nodetype Delay (Network::add_queue).
One station of the network.
double nservers
may be infinite (a Delay, or an inf-scheduled task)