LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
toMarginalAggr.m
1function [ni, nir] = toMarginalAggr(sn, ind, state_i, K, Ks, space_buf, space_srv, space_var) %#ok<INUSD>
2% TOMARGINALAGGR Compute aggregate marginal distributions for a specific node
3%
4% [NI, NIR] = TOMARGINALAGGR(SN, IND, STATE_I, K, KS, SPACE_BUF, SPACE_SRV, SPACE_VAR)
5%
6% @brief Computes aggregate marginal job counts from state information without phase details
7%
8% This function provides a simplified version of toMarginal that computes
9% aggregate job counts per node and per class, without considering individual
10% service phases. It is more efficient when phase-level detail is not required.
11%
12% @param sn Network structure or Network object
13% @param ind Node index to extract marginal information for
14% @param state_i Global state matrix or vector
15% @param K Vector of population for each class
16% @param Ks Matrix of populations per chain and class
17% @param space_buf Buffer space configuration
18% @param space_srv Service space configuration
19% @param space_var Variable space configuration
20%
21% @return ni Total jobs in node IND (aggregate across all classes)
22% @return nir Jobs per class in node IND [vector: classes]
23
24% Copyright (c) 2012-2026, Imperial College London
25% All rights reserved.
26
27if ~isstruct(sn) % the input can be a Network object too
28 sn=sn.getStruct();
29end
30% ind: node index
31ist = sn.nodeToStation(ind);
32%isf = sn.nodeToStateful(ind);
33R = sn.nclasses;
34if ~sn.isstation(ind) && sn.isstateful(ind) % if stateful node
35 ni = sum(state_i(1:(end-sum(sn.nvars(ind,:)))));
36 nir = state_i(1:(end-sum(sn.nvars(ind,:))));
37 return
38end
39
40if nargin < 4
41 K = sn.phasessz(ist,:);
42end
43 if nargin < 5
44 Ks = sn.phaseshift(ist,:);
45end
46
47if nargin < 8
48 space_var = state_i(:,(end-sum(sn.nvars(ind,:))+1):end); % server state
49 space_srv = state_i(:,(end-sum(K)+1):(end-sum(sn.nvars(ind,:))));
50 space_buf = state_i(:,1:(end-sum(K)));
51end
52
53nir = zeros(size(state_i,1),R); % class-r jobs in service
54for r=1:R
55 for k=1:K(r)
56 nir(:,r) = nir(:,r) + space_srv(:,Ks(r)+k);
57 end
58end
59switch sn.sched(ist)
60 case SchedStrategy.EXT
61 for r=1:R
62 nir(:,r) = Inf;
63 end
64 case SchedStrategy.FCFS
65 for r=1:R
66 nir(:,r) = nir(:,r) + sum(space_buf==r,2); % class-r jobs in station
67 end
68 case SchedStrategy.HOL
69 for r=1:R
70 nir(:,r) = nir(:,r) + sum(space_buf==r,2); % class-r jobs in station
71 end
72 case SchedStrategy.LCFS
73 for r=1:R
74 nir(:,r) = nir(:,r) + sum(space_buf==r,2); % class-r jobs in station
75 end
76 case SchedStrategy.SIRO
77 for r=1:R
78 nir(:,r) = nir(:,r) + space_buf(:,r); % class-r jobs in station
79 end
80 case SchedStrategy.SEPT
81 for r=1:R
82 nir(:,r) = nir(:,r) + space_buf(:,r); % class-r jobs in station
83 end
84 case SchedStrategy.LEPT
85 for r=1:R
86 nir(:,r) = nir(:,r) + space_buf(:,r); % class-r jobs in station
87 end
88 %otherwise % possibly other stateful nodes
89 % no-op
90end
91
92for r=1:R
93 if isnan(sn.rates(ist,r)) && sn.nodetype(ind) ~= NodeType.Place % if disabled
94 nir(:,r) = 0;
95 end
96end
97
98ni = sum(nir,2); % total jobs in station
99end