1function [S,A_jump] = build_SA(services, service_h, C)
3dim = length(service_h.beta);
4m = length(services.tau_st);
9S = zeros(newdim,newdim);
10A_jump = zeros(newdim,newdim);
12%
for example: 2 subtasks of different or same job, each can choose
13% from 2 phases, then states are:
14% (1,0;1,0); (1,0;0,1); (0,1;1,0); (0,1;0,1)
15% since the two subtasks are not symmetric, the first
is the
for the longer
16% one, the latter
is for the shorter one
17% the phase changes within each c in C
is service_h.S
18% no job completes service
20 S((row-1)*dim+1:row*dim,(row-1)*dim+1:row*dim) = service_h.S;
23% when a job completes service, and a
new job starts service
24A = -sum(services.ST,2)*services.tau_st;
26% when the job in the longer queue complete service
27S_Cminus1 = zeros(dim,dim);
30 countvect = service_h.service_phases(row,:);
32 for i = 1:m % the starting phase
34 for j = 1:m % the resulting phase
37 tovect(i) = tovect(i)-1; % jump from phase i to phase j
38 tovect(j) = tovect(j)+1;
40 col = vectmatch(tovect,service_h.service_phases);
42 % the job in the longer queue completes service
43 S_Cminus1(row,col) = S_Cminus1(row,col)+countvect(i)*A(i,j);
52 S((C-c)*dim+1:(C-c+1)*dim,(C-c+1)*dim+1:(C-c+2)*dim) = S_Cminus1;
55% when the job in the shorter queue complete service
56A_Cplus1 = zeros(dim,dim);
59 countvect = service_h.service_phases(row,:);
61 for i = m+1:2*m % the starting phase
63 for j = m+1:2*m % the resulting phase
66 tovect(i) = tovect(i)-1; % jump from phase i to phase j
67 tovect(j) = tovect(j)+1;
69 col = vectmatch(tovect,service_h.service_phases);
71 % the job in the shorter queue completes service
72 A_Cplus1(row,col) = A_Cplus1(row,col)+A(i-m,j-m);
80 A_jump((C-c)*dim+1:(C-c+1)*dim,(C-c-1)*dim+1:(C-c)*dim) = A_Cplus1;
83A_jump(1:dim,1:dim) = A_Cplus1;
85% both queue have a same length
86% the other one that didn
't finish becomes the longer queue
87A_last = zeros(dim,dim);
90 countvect = service_h.service_phases(row,:);
93 for i = 1 : m % the starting phase
94 if countvect((k-1)*m+i) > 0
96 tovect = countvect((2-k)*m+1:(2-k+1)*m);
98 temp_tovector = zeros(1,m);
100 temp_tovector = [tovect,temp_tovector];
101 col = vectmatch(temp_tovector,service_h.service_phases);
103 A_last(row,col) = A_last(row,col)+countvect((k-1)*m+i)*A(i,j);
111A_jump(C*dim+1:end,(C-1)*dim+1:C*dim) = A_last;