LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pas_nc_sampling.m
1function pas_nc_sampling()
2% PAS_NC_SAMPLING Importance-sampling normalizing-constant analysis of a closed
3% pass-and-swap (P&S) tandem via SolverNC method='sampling' (Casale, Comte &
4% Dorsman, 2026). The model is the Figure 6 closed tandem of Comte & Dorsman
5% (2021, arXiv:2009.12299) also used in PAS_CLOSED_TANDEM_FIG6.
6%
7% A non-empty swap graph makes the ordered-state chain reducible; the recurrent
8% communicating class carries the per-class product form pi(c)=Phi_1 Phi_2/G_C.
9% SolverNC importance sampling estimates G_C and the mean queue lengths by auto-normalized
10% importance sampling (API PFQN_PAS_IS), scaling to populations where the exact
11% ordered-state CTMC is intractable. Here we validate it against the exact CTMC.
12
13mu1 = 1.0; mu2 = 1.3;
14edges = [1 3; 1 4; 2 4; 2 5; 3 6; 4 6; 5 6];
15G = zeros(6);
16for k = 1:size(edges,1)
17 G(edges(k,1),edges(k,2)) = 1;
18 G(edges(k,2),edges(k,1)) = 1;
19end
20
21model = Network('PASsampling');
22q1 = Queue(model, 'PASQueue1', SchedStrategy.PAS);
23q2 = Queue(model, 'PASQueue2', SchedStrategy.PAS);
24jobclass = cell(1,6);
25for r = 1:6
26 jobclass{r} = ClosedClass(model, sprintf('Class%d', r), 1, q1);
27end
28q1.setService(@(c) mu1); q2.setService(@(c) mu2); % head-only single server
29q1.setSwapGraph(G); q1.setNumberOfServers(1); q1.setCap(6);
30q2.setSwapGraph(G); q2.setNumberOfServers(1); q2.setCap(6);
31P = model.initRoutingMatrix;
32for r = 1:6
33 P{jobclass{r}}(q1, q2) = 1.0;
34 P{jobclass{r}}(q2, q1) = 1.0;
35end
36model.link(P);
37q1.setState([1 2 3 4 5 6]); % Fig. 6a initial placement (reducible model input)
38
39fprintf('=== CTMC (exact) ===\n');
40Tc = CTMC(model, 'cutoff', 6).getAvgTable;
41fprintf('=== SolverNC method=''sampling'' (importance sampling, 5e5 samples) ===\n');
42Tn = NC(model, 'method', 'sampling', 'samples', 5e5, 'seed', 777, 'verbose', false).getAvgTable;
43
44qc = Tc.QLen; qn = Tn.QLen;
45fprintf('\n station class CTMC NC-samp\n');
46for i = 1:height(Tc)
47 fprintf(' %-9s %-6s %9.5f %9.5f\n', string(Tc.Station(i)), ...
48 string(Tc.JobClass(i)), qc(i), qn(i));
49end
50err = max(abs(qn - qc));
51fprintf('\nNC-samp vs CTMC: max|dQ| = %.3e (importance-sampling noise)\n', err);
52assert(err <= 5e-2, 'NC sampling does not match the exact CTMC within IS tolerance');
53fprintf('PASS: SolverNC ''sampling'' matches the exact CTMC within importance-sampling noise.\n');
54end
Definition Station.m:245