LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Toggle main menu visibility
Loading...
Searching...
No Matches
qn2jsimg.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_QN2JSIMG_H
6
#define LINE_IO_QN2JSIMG_H
7
8
/**
9
* @file
10
* @ingroup line_io
11
* Port of `matlab/src/io/QN2JSIMG.m`: write a network to a JMT `.jsimg` FILE
12
* and return its path.
13
*
14
* `jmt_write_jsim` (jmt_writer.h) returns the DOCUMENT TEXT, because SolverJMT
15
* stages it in a directory of its own. The reference's `QN2JSIMG` instead
16
* returns `outputFileName`, the path written, and with no path given it writes
17
* `<lineTempName('jsim')>/model.jsim`. This header supplies exactly that
18
* contract on top of the text writer, so there is still one serializer.
19
*
20
* The temporary directory is NOT removed: the caller is handed its path to
21
* open in JMT (`jsimgView`), as in the reference.
22
*/
23
24
#include <fstream>
25
#include <string>
26
27
#include "
line/io/jmt_writer.h
"
28
#include "
line/lang/qn/network_builder.h
"
29
#include "
line/lang/qn/network_struct.h
"
30
#include "
line/util/error.h
"
31
#include "
line/util/tempdir.h
"
32
33
namespace
line
{
34
namespace
io
{
35
36
/**
37
* Port of `QN2JSIMG(model, outputFileName, options)` on a refreshed struct.
38
*
39
* @param sn the refreshed struct (`model.getStruct(true)`)
40
* @param path the file to write; empty writes `model.jsim` in a fresh temp directory
41
* @param opt the simulation header controls, `JMTIO`'s properties
42
* @return the path written
43
*/
44
template
<
class
T>
45
std::string
qn2jsimg
(
const
qn::NetworkStruct<T>
&
sn
,
const
std::string& path = std::string(),
46
const
JmtWriteOptions
&
opt
=
JmtWriteOptions
()) {
47
const
std::string out = path.empty() ?
util::make_temp_dir
(
"jsim"
) +
"/model.jsim"
: path;
48
JmtWriteOptions
o =
opt
;
49
if
(o.
log_path
.empty()) o.
log_path
=
sn
.log_path;
50
const
std::string text =
jmt_write_jsim
(
sn
, o);
51
std::ofstream f(out.c_str(), std::ios::binary);
52
if
(!f)
throw
InputError
(
"QN2JSIMG: cannot open '"
+ out +
"' for writing"
);
53
f.write(text.data(),
static_cast<
std::streamsize
>
(text.size()));
54
f.close();
55
if
(!f)
throw
InputError
(
"QN2JSIMG: failed to write '"
+ out +
"'"
);
56
return
out;
57
}
58
59
/** Port of `QN2JSIMG(model, outputFileName, options)` on a model: refreshes it first. */
60
template
<
class
T>
61
std::string
qn2jsimg
(
qn::Network<T>
& model,
const
std::string& path = std::string(),
62
const
JmtWriteOptions
&
opt
=
JmtWriteOptions
()) {
63
return
qn2jsimg
(model.
get_struct
(), path,
opt
);
64
}
65
66
}
// namespace io
67
}
// namespace line
68
69
#endif
// LINE_IO_QN2JSIMG_H
line::InputError::InputError
InputError(const std::string &what)
Definition
error.h:39
line::qn::NetworkStruct
A network plus its refreshed NetworkStruct.
Definition
network_struct.h:863
line::qn::Network
A queueing network under construction.
Definition
network_builder.h:108
line::qn::Network::get_struct
const NetworkStruct< T > & get_struct()
The refreshed struct, MATLAB's model.getStruct().
Definition
network_builder.h:1822
error.h
The exception types the port throws.
jmt_writer.h
Port of @@JMTIO: a refreshed NetworkStruct written out as a JMT .jsimg simulation model.
line::io
Definition
code_gen.h:68
line::io::jmt_write_jsim
std::string jmt_write_jsim(const qn::NetworkStruct< T > &sn, const JmtWriteOptions &opt)
Port of @@JMTIO/writeJSIM.m: serialize sn as a JMT .jsimg document.
Definition
jmt_writer.h:2856
line::io::qn2jsimg
std::string qn2jsimg(const qn::NetworkStruct< T > &sn, const std::string &path=std::string(), const JmtWriteOptions &opt=JmtWriteOptions())
Port of QN2JSIMG(model, outputFileName, options) on a refreshed struct.
Definition
qn2jsimg.h:45
line::opt
Definition
bisection_solver.h:31
line::sn
Definition
sn_gd_balance.h:42
line::util::make_temp_dir
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
line
Conservation laws of a layered queueing network, enumerated from its structure.
Definition
aoi_dist2ph.h:52
network_builder.h
The Network constructor API: Queue, Delay, Source, Sink, Router, ClassSwitch, Cache,...
network_struct.h
A queueing network and its refreshed NetworkStruct.
line::io::JmtWriteOptions
The simulation controls the JSIM header carries, MATLAB's JMTIO properties.
Definition
jmt_writer.h:68
line::io::JmtWriteOptions::log_path
std::string log_path
model.getLogPath, the logPath attribute
Definition
jmt_writer.h:70
tempdir.h
A scratch directory for the subprocess wrappers, the port's lineTempName.
include
line
io
qn2jsimg.h
Generated by
1.18.0