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.');
14 markActivePassive = false;
17if nargin<3 %~exist('numEvents','var')
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
25Q = getAvgQLenHandles(self);
27modelCopy = self.model.copy;
28modelCopy.resetNetwork;
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;
36% apply logging to the copied model
38isNodeLogged = max(isNodeClassLogged,[],2);
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;
46 solverjmt.maxEvents = -1;
47 numEvents = self.getOptions.samples;
49solverjmt.getAvg(); % log data
50logData = SolverJMT.parseLogs(modelCopy, isNodeLogged, MetricType.toText(MetricType.QLen));
52% from here convert from
nodes in logData to stations
53sn = modelCopy.getStruct;
54ind = self.model.getNodeIndex(node.getName);
55isf = sn.nodeToStateful(ind);
57nir = cell(1,sn.nclasses);
58event = cell(1,sn.nclasses);
59%ids = cell(1,sn.nclasses);
62 if isempty(logData{ind,r})
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}.
77if isfinite(self.options.timespan(2))
78 stopAt = find(t>self.options.timespan(2),1,'first');
79 if ~isempty(stopAt) && stopAt>1
82 nir{r} = nir{r}(1:(stopAt-1));
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');
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 =
100event = cellmerge(event);
101event = {
event{cellisa(event,
'Event')}}
';
102event_t = cellfun(@(c) c.t, event);
103event_t = event_t(event_t <= max(stationStateAggr.t));
105stationStateAggr.event = {event{I}};
106stationStateAggr.event = stationStateAggr.event';
107stationStateAggr.isaggregate =
true;
110 apevent = cell(1,length(stationStateAggr.t)-1);
111 for ti = 1:length(apevent)
112 apevent{ti} =
struct(
'active',[],
'passive',[]);
114 for e=1:length(stationStateAggr.event)
115 ti = find(stationStateAggr.event{e}.t == stationStateAggr.t);
117 switch stationStateAggr.event{e}.event
119 apevent{ti-1}.passive = stationStateAggr.event{e};
121 apevent{ti-1}.active = stationStateAggr.event{e};
125 stationStateAggr.event = apevent
';