1% Example 9: Studying a departure process
2[model,source,queue,sink,oclass] = gallery_merl1;
4solver = CTMC(model,
'cutoff',150);
6sa = solver.sampleSysAggr(5e3);
7ind = model.getNodeIndex(queue);
9filtEvent = cellfun(@(c) c.node == ind && (isequal(c.event, EventType.DEP) || (isnumeric(c.event) && c.event == 2)), sa.event);
10interDepTimes = diff(cellfun(@(c) c.t, {sa.event{filtEvent}}));
12% estimated squared coeff. of variation of departures
13SCVdEst = var(interDepTimes)/mean(interDepTimes)^2
15util = solver.getAvgUtil();
17avgWaitTime = solver.getAvgWaitT(); % Waiting time excluding service
18avgWaitTime = avgWaitTime(queue);
19SCVa = source.getArrivalProcess(oclass).getSCV();
20svcRate = queue.getServiceProcess(oclass).getRate();
21SCVs = queue.getServiceProcess(oclass).getSCV();
23% Marshall
's exact formula
24SCVd = SCVa + 2*util^2*SCVs - 2*util*(1-util)*svcRate*avgWaitTime
26% Calculate relative error between simulated and theoretical SCV
27relativeError = abs(SCVdEst - SCVd) / SCVd * 100;
28fprintf('\n=== Departure Process Analysis Results ===\n
');
29fprintf('Simulated SCV of departures: %.6f\n
', SCVdEst);
30fprintf('Theoretical SCV (Marshall): %.6f\n
', SCVd);
31fprintf('Relative error: %.2f%%\n
', relativeError);