LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
sampleAggr.m
1function stationStateAggr = sampleAggr(self, node, numEvents, markActivePassive)
2% STATIONSTATEAGGR = SAMPLEAGGR(NODE, NUMEVENTS)
3
4if GlobalConstants.DummyMode
5 stationStateAggr = NaN;
6 return
7end
8
9if nargin<2 %~exist('node','var')
10 line_error(mfilename,'sampleAggr requires to specify a node.');
11end
12
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.');
17end
18
19if nargin<4
20 markActivePassive = false;
21end
22
23if nargin<3 %~exist('numEvents','var')
24 %numEvents = -1;
25else
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
28end
29sn = self.getStruct;
30
31Q = getAvgQLenHandles(self);
32% create a temp model
33modelCopy = self.model.copy;
34modelCopy.resetNetwork;
35
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;
41end
42% apply logging to the copied model
43Plinked = sn.rtorig;
44isNodeLogged = max(isNodeClassLogged,[],2);
45logpath = lineTempDir;
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;
51else
52 solverjmt.maxEvents = -1;
53 numEvents = self.getOptions.samples;
54end
55solverjmt.getAvg(); % log data
56logData = SolverJMT.parseLogs(modelCopy, isNodeLogged, MetricType.toText(MetricType.QLen));
57
58% from here convert from nodes in logData to stations
59sn = modelCopy.getStruct;
60ind = self.model.getNodeIndex(node.getName);
61t = [];
62nir = cell(1,sn.nclasses);
63event = cell(1,sn.nclasses);
64%ids = cell(1,sn.nclasses);
65
66for r=1:sn.nclasses
67 if isempty(logData{ind,r})
68 nir{r} = [];
69 else
70 [~,uniqTS] = unique(logData{ind,r}.t);
71 % isNodeClassLogged is allocated and written in NODE index space, so it
72 % must be read with the node index. Reading it with the stateful index
73 % silently skipped this branch, and hence returned an empty sample path,
74 % for every model whose target node sits above a non-stateful node such
75 % as a Sink, which shifts nodeToStateful(ind) away from ind.
76 if isNodeClassLogged(ind,r)
77 if ~isempty(logData{ind,r})
78 t = logData{ind,r}.t(uniqTS);
79 t = [t(2:end);t(end)];
80 nir{r} = logData{ind,r}.QLen(uniqTS);
81 event{r} = logData{ind,r}.event;
82 %ids{r} = logData{ind,r}.
83 end
84 end
85 end
86end
87if isfinite(self.options.timespan(2))
88 stopAt = find(t>self.options.timespan(2),1,'first');
89 if ~isempty(stopAt) && stopAt>1
90 t = t(1:(stopAt-1));
91 for r=1:length(nir)
92 nir{r} = nir{r}(1:(stopAt-1));
93 end
94 end
95end
96
97if length(t) < 1+numEvents
98 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');
99end
100
101stationStateAggr = struct();
102stationStateAggr.handle = node;
103stationStateAggr.t = t;
104stationStateAggr.t = stationStateAggr.t(1:min(length(t),1+numEvents),:);
105stationStateAggr.t = [0; stationStateAggr.t(1:end-1)];
106stationStateAggr.state = cell2mat(nir);
107stationStateAggr.state = stationStateAggr.state(1:min(length(t),1+numEvents),:);
108%stationStateAggr.job_id =
109
110event = cellmerge(event);
111event = {event{cellisa(event,'Event')}}';
112event_t = cellfun(@(c) c.t, event);
113event_t = event_t(event_t <= max(stationStateAggr.t));
114[~,I]=sort(event_t);
115stationStateAggr.event = {event{I}};
116stationStateAggr.event = stationStateAggr.event';
117stationStateAggr.isaggregate = true;
118
119if markActivePassive
120 apevent = cell(1,length(stationStateAggr.t)-1);
121 for ti = 1:length(apevent)
122 apevent{ti} = struct('active',[],'passive',[]);
123 end
124 for e=1:length(stationStateAggr.event)
125 ti = find(stationStateAggr.event{e}.t == stationStateAggr.t);
126 if ~isempty(ti)
127 switch stationStateAggr.event{e}.event
128 case EventType.ARV
129 apevent{ti-1}.passive = stationStateAggr.event{e};
130 otherwise
131 apevent{ti-1}.active = stationStateAggr.event{e};
132 end
133 end
134 end
135 stationStateAggr.event = apevent';
136end
137end
Definition fjtag.m:157
Definition Station.m:245