LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
constructSRK.m
1function [Se, Sestar, R0, Ke, Kc, S_long, S_last] = constructSRK( C, services, service_h, S)
2
3dim = length(service_h.beta);
4m = length(services.tau_st);
5
6indexes_notbusy = build_index(m,1);
7dim_NB = size(indexes_notbusy,1);
8
9dim_C = C+1;
10
11newdim = dim_C*dim;
12dim_notbusy = (dim_C-1)*dim_NB+1;
13
14Se = zeros(newdim+dim_notbusy,newdim+dim_notbusy);
15Sestar = Se;
16
17Se(1:newdim,1:newdim) = S;
18
19%% from busy to not-busy
20% when the job in the shorter queue complete service
21S_long = zeros(dim,dim_NB);
22
23for row = 1 : dim
24
25 countvect = service_h.service_phases(row,:);
26
27 for i = m+1:2*m % the starting phase
28 if countvect(i) > 0
29
30 tovect = countvect(1:m);
31
32 col = vectmatch(tovect,indexes_notbusy);
33
34 % the job in the shorter queue completes service
35 S_long(row,col) = S_long(row,col)+countvect(i)*services.St(i-m);
36
37 end
38 end
39end
40
41Se(1:dim,newdim+1:newdim+dim_NB) = S_long;
42for row = 2 : dim_C-1
43 Se((row-1)*dim+1:row*dim,newdim+(row-2)*dim_NB+1:newdim+(row-1)*dim_NB) = S_long;
44end
45
46% when the 2 queue have the same length
47S_last = zeros(dim,dim_NB);
48
49for row = 1 : dim
50
51 countvect = service_h.service_phases(row,:);
52
53 for k = 1 : 2
54 for i = (k-1)*m+1:k*m
55 if countvect(i) > 0
56
57 tovect = countvect((2-k)*m+1:(2-k+1)*m);
58
59 col = vectmatch(tovect,indexes_notbusy);
60
61 S_last(row,col) = S_last(row,col)+countvect(i)*services.St(i-(k-1)*m);
62
63 end
64 end
65 end
66end
67
68Se((dim_C-1)*dim+1:dim_C*dim,newdim+(dim_C-2)*dim_NB+1:newdim+(dim_C-1)*dim_NB) = S_last;
69
70Sestar(1:newdim,newdim+1:end) = Se(1:newdim,newdim+1:end);
71
72%% from not-busy to not-busy
73
74for row = 1 : dim_C-1
75 Se(newdim+(row-1)*dim_NB+1:newdim+row*dim_NB,newdim+(row-1)*dim_NB+1:newdim+row*dim_NB) = services.ST;
76end
77
78A = -sum(services.ST,2)*services.tau_st;
79
80for row = 1 : dim_C-2
81 Se(newdim+(row-1)*dim_NB+1:newdim+row*dim_NB,newdim+row*dim_NB+1:newdim+(row+1)*dim_NB) = A;
82end
83
84Se(newdim+(dim_C-2)*dim_NB+1:newdim+(dim_C-1)*dim_NB,newdim+(dim_C-1)*dim_NB+1:end) = -sum(services.ST,2);
85
86for row = newdim+1 : newdim+dim_notbusy
87 Se(row,row) = 0;
88 Se(row,row) = -sum(Se(row,:));
89end
90
91
92%% Construct R0 matrix: from the not-busy period to a busy period
93% focus on the shortest queue, the system has only one idle server, thus an
94% arrival leads the system back to a busy-period
95% first dim phases: busy; second dim phases: not-busy
96% the queue jumps to the same phase in a busy period after an arrival
97R0 = zeros(newdim+dim_notbusy,newdim+dim_notbusy);
98R_NB = zeros(dim_NB,dim);
99
100for row = 1 : dim_NB
101 countvect = indexes_notbusy(row,:);
102 for i = 1 : m
103 tovect_short = zeros(1,m);
104 tovect_short(i) = 1;
105 tovect = [countvect,tovect_short];
106 col = vectmatch(tovect,service_h.service_phases);
107 R_NB(row,col) = R_NB(row,col)+services.tau_st(i);
108 end
109end
110
111
112for row = 1 : dim_C-1
113 R0(newdim+(row-1)*dim_NB+1:newdim+row*dim_NB,(row-1)*dim+1:row*dim) = R_NB;
114end
115
116R0(end,newdim-dim+1:newdim) = service_h.beta;
117
118Ke = cat(2,eye(newdim),zeros(newdim,dim_notbusy));
119Kc = cat(1,eye(newdim),zeros(dim_notbusy,newdim));
120
121Se = sparse(Se);
122Sestar = sparse(Sestar);
123R0 = sparse(R0);
124Ke = sparse(Ke);
125Kc = sparse(Kc);
126
127end