LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
SolverJMT.m
1classdef SolverJMT < NetworkSolver
2 % SolverJMT Java Modelling Tools interface for simulation analysis
3 %
4 % SolverJMT provides an interface to the Java Modelling Tools (JMT) suite
5 % for discrete event simulation of queueing networks. It handles model
6 % translation, simulation execution, and results parsing for both JMVA
7 % (analytical) and JSIM (simulation) engines within JMT.
8 %
9 % @brief Interface to Java Modelling Tools for simulation and analysis
10 %
11 % Example:
12 % @code
13 % solver = SolverJMT(model, 'samples', 10000, 'seed', 1);
14 % solver.getAvg(); % Run simulation via JMT
15 % @endcode
16 %
17 % Copyright (c) 2012-2026, Imperial College London
18 % All rights reserved.
19
20 %Private properties
21 properties %(GetAccess = 'private', SetAccess='private')
22 jmtPath;
23 filePath;
24 fileName;
25 maxSimulatedTime;
26 maxSamples;
27 maxEvents;
28 seed;
29 simConfInt;
30 simMaxRelErr;
31 xmlParser; % JMTIO instance for XML generation
32 end
33
34 %Constants
35 properties (Constant)
36 xsiNoNamespaceSchemaLocation = 'Archive.xsd';
37 fileFormat = 'jsimg';
38 jsimgPath = '';
39 end
40
41 % PUBLIC METHODS
42 methods
43
44 %Constructor
45 function self = SolverJMT(model, varargin)
46 % SOLVERJMT Create a JMT solver instance
47 %
48 % @brief Creates a Java Modelling Tools solver for the given model
49 % @param model Network model to be analyzed via JMT
50 % @param varargin Optional parameters (samples, seed, maxSimulatedTime, etc.)
51 % @return self SolverJMT instance configured for JMT simulation
52
53 % An auxiliary solver passed as first optional argument requests a
54 % warm start: its steady-state solution decides the station
55 % preload of the simulation (see NetworkSolver.initFromSolver).
56 initSolver = [];
57 if ~isempty(varargin) && isa(varargin{1}, 'NetworkSolver')
58 initSolver = varargin{1};
59 varargin(1) = [];
60 end
61 self@NetworkSolver(model, mfilename);
62 self.setOptions(Solver.parseOptions(varargin, self.defaultOptions));
63 self.setLang();
64 if ~Solver.isJavaAvailable
65 line_error(mfilename,'SolverJMT requires the java command to be available on the system path.\n');
66 end
67 if ~SolverJMT.isAvailable
68 line_warning(mfilename,'SolverJMT cannot locate JMT.jar in the common folder.\n');
69 end
70 % Set confidence interval from options (default: 0.99 for 99% confidence)
71 [confintEnabled, confintLevel] = Solver.parseConfInt(self.options.confint);
72 if confintEnabled
73 self.simConfInt = confintLevel;
74 else
75 self.simConfInt = 0.99; % default when disabled
76 end
77 self.simMaxRelErr = 0.03;
78 self.maxEvents = -1;
79 self.setJMTJarPath(jmtGetPath);
80 % Initialize XML parser for model serialization
81 self.xmlParser = JMTIO(model, self.options);
82 if ~isempty(initSolver)
83 self.initFromSolver(initSolver);
84 end
85 end
86
87 % XML generation delegated to JMTIO (see @JMTIO/)
88 % Use self.xmlParser.writeJSIM() for JSIM model generation
89
90 fileName = getFileName(self)
91
92 %Setter
93 self = setJMTJarPath(self, path)
94
95 % Getters
96 out = getJMTJarPath(self)
97
98 out = getFilePath(self)
99 jsimwView(self, options)
100 jsimgView(self, options)
101 view(self, options)
102
103 [outputFileName] = writeJSIM(self, sn, outputFileName)
104 [result, parsed] = getResults(self)
105 [result, parsed] = getResultsJSIM(self)
106 [result, parsed] = getResultsJMVA(self)
107
108 function sn = getStruct(self)
109 % QN = GETSTRUCT()
110
111 % Get data structure summarizing the model
112 sn = self.model.getStruct(true);
113 end
114 end
115
116 %Private methods.
117 methods (Access = 'private')
118 out = getJSIMTempPath(self)
119 out = getJMVATempPath(self)
120 end
121
122 %Private methods.
123 methods (Access = 'protected')
124 bool = hasAvgResults(self)
125 end
126
127
128 methods (Access = 'public')
129 getProbNormConstAggr(self); % jmva
130 %% StateAggr methods
131 Pr = getProbAggr(self, node, state_a);
132 [Pi_t, SSnode_a] = getTranProbAggr(self, node);
133 probSysStateAggr = getProbSysAggr(self);
134 tranNodeStateAggr = sampleAggr(self, node, numEvents, markActivePassive);
135 tranSysStateAggr = sampleSysAggr(self, numEvents, markActivePassive);
136
137 %% Cdf methods
138 [RD,log] = getCdfRespT(self, R);
139 RD = getTranCdfRespT(self, R);
140 RD = getTranCdfPassT(self, R);
141
142 function [allMethods] = listValidMethods(self)
143 % allMethods = LISTVALIDMETHODS()
144 % List valid methods for this solver
145 sn = self.model.getStruct();
146 allMethods = {'default','jsim','replication','jmva','jmva.amva','jmva.mva','jmva.recal',...
147 'jmva.comom','jmva.chow','jmva.bs','jmva.aql',...
148 'jmva.lin','jmva.dmlin'};
149 end
150
151 function bool = isStochasticMethod(self, method) %#ok<INUSL>
152 % BOOL = ISSTOCHASTICMETHOD(METHOD)
153 % Simulation-based methods (default, jsim, replication) return
154 % stochastic estimates. The analytical JMVA methods do not,
155 % except for its sampling-based variants (e.g. jmva.ls).
156 tokens = regexp(lower(method), '[./]', 'split');
157 if any(strcmp(tokens, 'jmva'))
158 bool = any(ismember(tokens, {'ls','mci','imci','sampling'}));
159 else
160 bool = true;
161 end
162 end
163 function featSupported = getMethodFeatureSet(self, method) %#ok<INUSD>
164 % All JMT methods share the solver-level feature envelope.
165 %
166 % Defining this is what lets NetworkSolver.supportsModelMethod name
167 % the offending features: with no method feature set it falls back
168 % to the coarse supports(model), which returns an empty reason, so
169 % the gate could only report "features not supported" without
170 % saying which ones.
171 %
172 % A non-Network model (e.g. a LayeredNetwork) has no
173 % getUsedLangFeatures, so it keeps the coarse path and any
174 % structural checks or redirects that operate on such models.
175 if ~isa(self.model, 'Network')
176 featSupported = [];
177 return;
178 end
179 featSupported = SolverJMT.getFeatureSet();
180 end
181
182
183 end
184
185 methods (Static)
186
187 function bool = isAvailable()
188 % BOOL = ISAVAILABLE()
189
190 bool = true;
191 try
192 jmt_path = jmtGetPath();
193 jmt_jar = fullfile(jmt_path, 'JMT.jar');
194 if ~exist(jmt_jar, 'file')
195 bool = false;
196 end
197 catch
198 bool = false;
199 end
200 end
201
202 function featSupported = getFeatureSet()
203 % FEATSUPPORTED = GETFEATURESET()
204
205 featSupported = SolverFeatureSet;
206 featSupported.setTrue({'Sink',...
207 'Source',...
208 'Router',...
209 'ClassSwitch',...
210 'Delay',...
211 'DelayStation',...
212 'Queue',...
213 'Fork',...
214 'Join',...
215 'Forker',...
216 'Joiner',...
217 'Logger',...
218 'Coxian',...
219 'Cox2',...
220 'APH',...
221 'Erlang',...
222 'Exp',...
223 'HyperExp',...
224 'Det',...
225 'Gamma',...
226 'Lognormal',...
227 'MAP',...
228 'MMPP2',...
229 'Normal',...
230 'PH',...
231 'Pareto',...
232 'Weibull',...
233 'Replayer',...
234 'Uniform',...
235 'StatelessClassSwitcher',...
236 'InfiniteServer',...
237 'SharedServer',...
238 'Buffer',...
239 'Dispatcher',...
240 'Server',...
241 'JobSink',...
242 'RandomSource',...
243 'ServiceTunnel',...
244 'LogTunnel',...
245 'Buffer', ...
246 'Linkage',...
247 'Enabling', ...
248 'Inhibiting', ...
249 'Timing', ...
250 'Firing', ...
251 'Storage', ...
252 'Place', ...
253 'Transition', ...
254 'SchedStrategy_INF',...
255 'SchedStrategy_PS',...
256 'SchedStrategy_DPS',...
257 'SchedStrategy_FCFS',...
258 'SchedStrategy_GPS',...
259 'SchedStrategy_SIRO',...
260 'SchedStrategy_HOL',...
261 'SchedStrategy_PSPRIO',...
262 'SchedStrategy_DPSPRIO',...
263 'SchedStrategy_GPSPRIO',...
264 'SchedStrategy_LCFS',...
265 'SchedStrategy_LCFSPR',...
266 'SchedStrategy_LCFSPRIO',...
267 'SchedStrategy_LCFSPRPRIO',...
268 'SchedStrategy_SEPT',...
269 'SchedStrategy_SRPT',...
270 'SchedStrategy_SRPTPRIO',...
271 'SchedStrategy_LEPT',...
272 'SchedStrategy_SJF',...
273 'SchedStrategy_LJF',...
274 'SchedStrategy_LPS',...
275 'SchedStrategy_POLLING',...
276 'RoutingStrategy_PROB',...
277 'RoutingStrategy_RAND',...
278 'RoutingStrategy_RROBIN',...
279 'RoutingStrategy_WRROBIN',...
280 'RoutingStrategy_JSQ',...
281 'RoutingStrategy_KCHOICES',...
282 'SchedStrategy_EXT',...
283 'ClosedClass','SelfLoopingClass',...
284 'OpenClass',...
285 'Cache', 'CacheClassSwitcher', ...
286 'ReplacementStrategy_RR', 'ReplacementStrategy_FIFO', ...
287 'ReplacementStrategy_SFIFO', 'ReplacementStrategy_LRU', ...
288 'SetupDelayOff', ... % exported as delayOffTime/setUpTime (saveDelayOffStrategy)
289 'Reneging', ... % exported as an Impatience/Reneging strategy (saveImpatience)
290 'Balking'}); % exported as an Impatience/Balking strategy (saveImpatience)
291 end
292
293 function [bool, featSupported] = supports(model)
294 % [BOOL, FEATSUPPORTED] = SUPPORTS(MODEL)
295
296 featUsed = model.getUsedLangFeatures();
297 featSupported = SolverJMT.getFeatureSet();
298 bool = SolverFeatureSet.supports(featSupported, featUsed);
299 end
300
301 function jsimgOpen(filename)
302 % JSIMGOPEN(FILENAME)
303
304 [path] = fileparts(filename);
305 if isempty(path)
306 filename=[pwd,filesep,filename];
307 end
308 runtime = java.lang.Runtime.getRuntime();
309 cmd = ['java -cp "',jmtGetPath,filesep,'JMT.jar" jmt.commandline.Jmt jsimg "',filename,'"'];
310 system(cmd);
311 %runtime.exec(cmd);
312 end
313
314 function jsimwOpen(filename)
315 % JSIMWOPEN(FILENAME)
316
317 runtime = java.lang.Runtime.getRuntime();
318 cmd =
Definition Station.m:245