1function stationStateAggr = sampleAggr(self, node, numEvents, markActivePassive)
2% STATIONSTATEAGGR = SAMPLEAGGR(NODE, NUMEVENTS)
4if GlobalConstants.DummyMode
5 stationStateAggr = NaN;
9if nargin<2 %~exist(
'node',
'var')
10 line_error(mfilename,'sampleAggr requires to specify a node.');
13if strcmp(self.getOptions.lang,'java')
14 % Log-based sampling relies on per-node CSV logs written and parsed by the
15 % native JMT path; the JLINE (lang=java) delegation does not produce them.
16 line_error(mfilename,'SolverJMT log-based sampling (sampleAggr/getProbAggr)
is not supported with lang=''java''. Use lang=''matlab'' or SolverCTMC.');
20 markActivePassive = false;
23if nargin<3 %~exist('numEvents','var')
26 line_warning(mfilename,'JMT does not allow to fix the number of events for individual
nodes. The number of returned events may be inaccurate.\n');
27 %numEvents = numEvents - 1; % we include the initialization as an event
31Q = getAvgQLenHandles(self);
33modelCopy = self.model.copy;
34modelCopy.resetNetwork;
36% determine the
nodes to logs
37isNodeClassLogged = false(modelCopy.getNumberOfNodes, modelCopy.getNumberOfClasses);
38ind = self.model.getNodeIndex(node.name);
39for r=1:modelCopy.getNumberOfClasses
40 isNodeClassLogged(ind,r) = true;
42% apply logging to the copied model
44isNodeLogged = max(isNodeClassLogged,[],2);
46modelCopy.linkAndLog(Plinked, isNodeLogged, logpath);
47% simulate the model copy and retrieve log data
48solverjmt = SolverJMT(modelCopy, self.getOptions);
49if nargin>=3 && numEvents > 0
50 solverjmt.maxEvents = numEvents*sn.nnodes*sn.nclasses;
52 solverjmt.maxEvents = -1;
53 numEvents = self.getOptions.samples;
55solverjmt.getAvg(); % log data
56logData = SolverJMT.parseLogs(modelCopy, isNodeLogged, MetricType.toText(MetricType.QLen));
58% from here convert from
nodes in logData to stations
59sn = modelCopy.getStruct;
60ind = self.model.getNodeIndex(node.getName);
61isf = sn.nodeToStateful(ind);
63nir = cell(1,sn.nclasses);
64event = cell(1,sn.nclasses);
65%ids = cell(1,sn.nclasses);
68 if isempty(logData{ind,r})
71 [~,uniqTS] = unique(logData{ind,r}.t);
72 if isNodeClassLogged(isf,r)
73 if ~isempty(logData{ind,r})
74 t = logData{ind,r}.t(uniqTS);
75 t = [t(2:end);t(end)];
76 nir{r} = logData{ind,r}.QLen(uniqTS);
77 event{r} = logData{ind,r}.event;
78 %ids{r} = logData{ind,r}.
83if isfinite(self.options.timespan(2))
84 stopAt = find(t>self.options.timespan(2),1,'first');
85 if ~isempty(stopAt) && stopAt>1
88 nir{r} = nir{r}(1:(stopAt-1));
93if length(t) < 1+numEvents
94 line_warning(mfilename,
'LINE could not estimate correctly the JMT simulation length to return the desired number of events at the specified node. Try to re-run increasing the number of events.\n');
97stationStateAggr =
struct();
98stationStateAggr.handle = node;
99stationStateAggr.t = t;
100stationStateAggr.t = stationStateAggr.t(1:min(length(t),1+numEvents),:);
101stationStateAggr.t = [0; stationStateAggr.t(1:end-1)];
102stationStateAggr.state = cell2mat(nir);
103stationStateAggr.state = stationStateAggr.state(1:min(length(t),1+numEvents),:);
104%stationStateAggr.job_id =
106event = cellmerge(event);
107event = {
event{cellisa(event,
'Event')}}
';
108event_t = cellfun(@(c) c.t, event);
109event_t = event_t(event_t <= max(stationStateAggr.t));
111stationStateAggr.event = {event{I}};
112stationStateAggr.event = stationStateAggr.event';
113stationStateAggr.isaggregate =
true;
116 apevent = cell(1,length(stationStateAggr.t)-1);
117 for ti = 1:length(apevent)
118 apevent{ti} =
struct(
'active',[],
'passive',[]);
120 for e=1:length(stationStateAggr.event)
121 ti = find(stationStateAggr.event{e}.t == stationStateAggr.t);
123 switch stationStateAggr.event{e}.event
125 apevent{ti-1}.passive = stationStateAggr.event{e};
127 apevent{ti-1}.active = stationStateAggr.event{e};
131 stationStateAggr.event = apevent
';