LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
build_SA.m
1function [S,A_jump] = build_SA(services, service_h, C)
2
3dim = length(service_h.beta);
4m = length(services.tau_st);
5
6dim_C = C+1;
7
8newdim = dim_C*dim;
9S = zeros(newdim,newdim);
10A_jump = zeros(newdim,newdim);
11
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
19for row = 1 : dim_C
20 S((row-1)*dim+1:row*dim,(row-1)*dim+1:row*dim) = service_h.S;
21end
22
23% when a job completes service, and a new job starts service
24A = -sum(services.ST,2)*services.tau_st;
25
26% when the job in the longer queue complete service
27S_Cminus1 = zeros(dim,dim);
28for row = 1 : dim
29
30 countvect = service_h.service_phases(row,:);
31
32 for i = 1:m % the starting phase
33 if countvect(i) > 0
34 for j = 1:m % the resulting phase
35
36 tovect=countvect;
37 tovect(i) = tovect(i)-1; % jump from phase i to phase j
38 tovect(j) = tovect(j)+1;
39
40 col = vectmatch(tovect,service_h.service_phases);
41
42 % the job in the longer queue completes service
43 S_Cminus1(row,col) = S_Cminus1(row,col)+countvect(i)*A(i,j);
44
45 end
46 end
47 end
48end
49
50% form c to c-1
51for c = C : -1 : 1
52 S((C-c)*dim+1:(C-c+1)*dim,(C-c+1)*dim+1:(C-c+2)*dim) = S_Cminus1;
53end
54
55% when the job in the shorter queue complete service
56A_Cplus1 = zeros(dim,dim);
57for row = 1 : dim
58
59 countvect = service_h.service_phases(row,:);
60
61 for i = m+1:2*m % the starting phase
62 if countvect(i) > 0
63 for j = m+1:2*m % the resulting phase
64
65 tovect=countvect;
66 tovect(i) = tovect(i)-1; % jump from phase i to phase j
67 tovect(j) = tovect(j)+1;
68
69 col = vectmatch(tovect,service_h.service_phases);
70
71 % the job in the shorter queue completes service
72 A_Cplus1(row,col) = A_Cplus1(row,col)+A(i-m,j-m);
73
74 end
75 end
76 end
77end
78
79for c = C-1 : -1 : 1
80 A_jump((C-c)*dim+1:(C-c+1)*dim,(C-c-1)*dim+1:(C-c)*dim) = A_Cplus1;
81end
82
83A_jump(1:dim,1:dim) = A_Cplus1;
84
85% both queue have a same length
86% the other one that didn't finish becomes the longer queue
87A_last = zeros(dim,dim);
88for row = 1 : dim
89
90 countvect = service_h.service_phases(row,:);
91
92 for k = 1 : 2
93 for i = 1 : m % the starting phase
94 if countvect((k-1)*m+i) > 0
95
96 tovect = countvect((2-k)*m+1:(2-k+1)*m);
97 for j = 1 : m
98 temp_tovector = zeros(1,m);
99 temp_tovector(j) = 1;
100 temp_tovector = [tovect,temp_tovector];
101 col = vectmatch(temp_tovector,service_h.service_phases);
102
103 A_last(row,col) = A_last(row,col)+countvect((k-1)*m+i)*A(i,j);
104
105 end
106 end
107 end
108 end
109end
110
111A_jump(C*dim+1:end,(C-1)*dim+1:C*dim) = A_last;