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);
61isf = sn.nodeToStateful(ind);
62t = [];
63nir = cell(1,sn.nclasses);
64event = cell(1,sn.nclasses);
65%ids = cell(1,sn.nclasses);
66
67for r=1:sn.nclasses
68 if isempty(logData{ind,r})
69 nir{r} = [];
70 else
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}.
79 end
80 end
81 end
82end
83if isfinite(self.options.timespan(2))
84 stopAt = find(t>self.options.timespan(2),1,'first');
85 if ~isempty(stopAt) && stopAt>1
86 t = t(1:(stopAt-1));
87 for r=1:length(nir)
88 nir{r} = nir{r}(1:(stopAt-1));
89 end
90 end
91end
92
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');
95end
96
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 =
105
106event = cellmerge(event);
107event = {event{cellisa(event,'Event')}}';
108event_t = cellfun(@(c) c.t, event);
109event_t = event_t(event_t <= max(stationStateAggr.t));
110[~,I]=sort(event_t);
111stationStateAggr.event = {event{I}};
112stationStateAggr.event = stationStateAggr.event';
113stationStateAggr.isaggregate = true;
114
115if markActivePassive
116 apevent = cell(1,length(stationStateAggr.t)-1);
117 for ti = 1:length(apevent)
118 apevent{ti} = struct('active',[],'passive',[]);
119 end
120 for e=1:length(stationStateAggr.event)
121 ti = find(stationStateAggr.event{e}.t == stationStateAggr.t);
122 if ~isempty(ti)
123 switch stationStateAggr.event{e}.event
124 case EventType.ARV
125 apevent{ti-1}.passive = stationStateAggr.event{e};
126 otherwise
127 apevent{ti-1}.active = stationStateAggr.event{e};
128 end
129 end
130 end
131 stationStateAggr.event = apevent';
132end
133end
Definition mmt.m:124