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 nargin<4
14 markActivePassive = false;
15end
16
17if nargin<3 %~exist('numEvents','var')
18 %numEvents = -1;
19else
20 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');
21 %numEvents = numEvents - 1; % we include the initialization as an event
22end
23sn = self.getStruct;
24
25Q = getAvgQLenHandles(self);
26% create a temp model
27modelCopy = self.model.copy;
28modelCopy.resetNetwork;
29
30% determine the nodes to logs
31isNodeClassLogged = false(modelCopy.getNumberOfNodes, modelCopy.getNumberOfClasses);
32ind = self.model.getNodeIndex(node.name);
33for r=1:modelCopy.getNumberOfClasses
34 isNodeClassLogged(ind,r) = true;
35end
36% apply logging to the copied model
37Plinked = sn.rtorig;
38isNodeLogged = max(isNodeClassLogged,[],2);
39logpath = lineTempDir;
40modelCopy.linkAndLog(Plinked, isNodeLogged, logpath);
41% simulate the model copy and retrieve log data
42solverjmt = SolverJMT(modelCopy, self.getOptions);
43if nargin>=3 && numEvents > 0
44 solverjmt.maxEvents = numEvents*sn.nnodes*sn.nclasses;
45else
46 solverjmt.maxEvents = -1;
47 numEvents = self.getOptions.samples;
48end
49solverjmt.getAvg(); % log data
50logData = SolverJMT.parseLogs(modelCopy, isNodeLogged, MetricType.toText(MetricType.QLen));
51
52% from here convert from nodes in logData to stations
53sn = modelCopy.getStruct;
54ind = self.model.getNodeIndex(node.getName);
55isf = sn.nodeToStateful(ind);
56t = [];
57nir = cell(1,sn.nclasses);
58event = cell(1,sn.nclasses);
59%ids = cell(1,sn.nclasses);
60
61for r=1:sn.nclasses
62 if isempty(logData{ind,r})
63 nir{r} = [];
64 else
65 [~,uniqTS] = unique(logData{ind,r}.t);
66 if isNodeClassLogged(isf,r)
67 if ~isempty(logData{ind,r})
68 t = logData{ind,r}.t(uniqTS);
69 t = [t(2:end);t(end)];
70 nir{r} = logData{ind,r}.QLen(uniqTS);
71 event{r} = logData{ind,r}.event;
72 %ids{r} = logData{ind,r}.
73 end
74 end
75 end
76end
77if isfinite(self.options.timespan(2))
78 stopAt = find(t>self.options.timespan(2),1,'first');
79 if ~isempty(stopAt) && stopAt>1
80 t = t(1:(stopAt-1));
81 for r=1:length(nir)
82 nir{r} = nir{r}(1:(stopAt-1));
83 end
84 end
85end
86
87if length(t) < 1+numEvents
88 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');
89end
90
91stationStateAggr = struct();
92stationStateAggr.handle = node;
93stationStateAggr.t = t;
94stationStateAggr.t = stationStateAggr.t(1:min(length(t),1+numEvents),:);
95stationStateAggr.t = [0; stationStateAggr.t(1:end-1)];
96stationStateAggr.state = cell2mat(nir);
97stationStateAggr.state = stationStateAggr.state(1:min(length(t),1+numEvents),:);
98%stationStateAggr.job_id =
99
100event = cellmerge(event);
101event = {event{cellisa(event,'Event')}}';
102event_t = cellfun(@(c) c.t, event);
103event_t = event_t(event_t <= max(stationStateAggr.t));
104[~,I]=sort(event_t);
105stationStateAggr.event = {event{I}};
106stationStateAggr.event = stationStateAggr.event';
107stationStateAggr.isaggregate = true;
108
109if markActivePassive
110 apevent = cell(1,length(stationStateAggr.t)-1);
111 for ti = 1:length(apevent)
112 apevent{ti} = struct('active',[],'passive',[]);
113 end
114 for e=1:length(stationStateAggr.event)
115 ti = find(stationStateAggr.event{e}.t == stationStateAggr.t);
116 if ~isempty(ti)
117 switch stationStateAggr.event{e}.event
118 case EventType.ARV
119 apevent{ti-1}.passive = stationStateAggr.event{e};
120 otherwise
121 apevent{ti-1}.active = stationStateAggr.event{e};
122 end
123 end
124 end
125 stationStateAggr.event = apevent';
126end
127end
Definition mmt.m:92