LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
pfqn_recal.m
1%{
2%{
3 % @file pfqn_recal.m
4 % @brief RECAL (REcursive CALculation) method for normalizing constant.
5%}
6%}
7
8%{
9%{
10 % @brief RECAL (REcursive CALculation) method for normalizing constant.
11 % @fn pfqn_recal(L, N, Z, m0)
12 % @param L Service demand matrix.
13 % @param N Population vector.
14 % @param Z Think time vector (default: zeros).
15 % @param m0 Initial multiplicity vector (default: ones).
16 % @return G Normalizing constant.
17 % @return lG Logarithm of normalizing constant.
18%}
19%}
20function [G,lG]=pfqn_recal(L,N,Z,m0)
21% [G,logG]=PFQN_RECAL(L,N,Z,M0)
22[M_original,R] = size(L);
23if nargin<4
24 m0=ones(1,M_original);
25end
26if nargin<3
27 Z=zeros(1,R);
28end
29
30% Detect and consolidate replicated stations
31[L, ~, ~, ~, mapping] = pfqn_unique(L);
32[M,~] = size(L);
33
34% Combine user-provided m0 with detected multiplicity
35% For each unique station j, sum the m0 values of all original stations mapping to it
36m0_combined = zeros(1, M);
37for i = 1:M_original
38 m0_combined(mapping(i)) = m0_combined(mapping(i)) + m0(i);
39end
40m0 = m0_combined;
41
42Ntot = sum(N);
43G_1 = ones(1,nchoosek(Ntot+(M+1)-1,Ntot));
44G = G_1;
45 I_1=multichoose(M+1,Ntot);
46 n=0;
47 for r=1:R
48 for nr=1:N(r)
49 n=n+1 ;
50 I=multichoose(M+1,(Ntot+1)-(n+1));
51 for i=1:size(I,1)
52 m=I(i,:);
53 mZ = m(1:M);
54 G(i)=Z(r)*G_1(matchrow(I_1(:,1:M),mZ))/nr;
55 for jst=1:M
56 m(jst)=m(jst)+1;
57 G(i)=G(i)+(m(jst)+m0(jst)-1)*L(jst,r)*G_1(matchrow(I_1,m))/nr;
58 m(jst)=m(jst)-1;
59 end
60 end
61 I_1=I;
62 G_1=G;
63 end
64 end
65G = G(1);
66lG = log(G);
67end