-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalyseData.m
108 lines (86 loc) · 2.6 KB
/
analyseData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function [prob_nbCustomer, N, N0] = analyseData( data, nbJobs, nbClasses, nbNodes, data_needed)
%number of customer classes, start from 1.
K = nbClasses;
%total number of jobs in the system
N = nbJobs;
N0 = zeros(1,K);
tempTS=[];
tempClass=[];
tempLogger=[];
for i = 1:K
temp_length = size(data{3,i},1);
tempTS = [tempTS;data{3,i};data{3,i}+data{4,i}*1000];
tempClass = [tempClass;ones(temp_length*2,1)*i];
tempLogger = [tempLogger;ones(temp_length,1);ones(temp_length,1)*2];
end
[ts index] = sort(tempTS);
class_id = tempClass(index);
logger_id = tempLogger(index);
burnin = length(ts)-data_needed;
if burnin < 0 || data_needed == 0
burnin = 1;
end
%Initialise
total_length = length(ts);
count = zeros(total_length,K,nbNodes); %number of customers in the queue, start from time 0
count(1,:,1) = N; %initialise delay center with N jobs
% serial
for i = 1:total_length-1
count(i+1,:,:) = count(i,:,:);
count(i+1,:,:) = count(i,:,:);
count(i+1,class_id(i),logger_id(i)) = count(i,class_id(i),logger_id(i))-1;
if logger_id(i) == nbNodes
count(i+1,class_id(i),1) = count(i,class_id(i),1)+1;
else
count(i+1,class_id(i),logger_id(i)+1) = count(i,class_id(i),logger_id(i)+1)+1;
end
end
if sum(N) == 0
for i = 1:K
N(i) = max(max(count(:,i,:)));
end
end
for i = 1:total_length
for j = 1:K
count(i,j,1) = count(i,j,1) + N(j);
end
end
% parallel
% for i = 1:total_length-1
% count(i+1,:,:) = count(i,:,:);
%
% if logger_id(i) < 5
% count(i+1,class_id(i),1) = count(i,class_id(i),1)-1;
% count(i+1,class_id(i),logger_id(i)+1) = count(i,class_id(i),logger_id(i)+1)+1;
% end
%
% if logger_id(i) > 5
% count(i+1,class_id(i),1) = count(i,class_id(i),1)+1;
% count(i+1,class_id(i),logger_id(i)-9) = count(i,class_id(i),logger_id(i)-9)-1;
% end
%
% end
count = reshape(count,total_length,nbClasses*nbNodes);
%calculate the interval between each timestamp
%time_interval(1) = ts(1);
time_interval(1) = 0;
time_interval(2:total_length) = diff(ts);
count(:,end+1) = time_interval';
count = count(burnin:end,:);
count = sortrows(count,[1:size(count,2)-1]);
[C ia ic] = unique(count(:,1:end-1),'rows','legacy');
%the first one
Time = C;
Time(1,end+1) = sum(count(1:ia(1),end));
for i =2:size(C,1)
Time(i,end) = sum(count(ia(i-1)+1:ia(i),end));
end
%observed time period
obs_length = ts(end)-ts(burnin);
%calculate the probability
prob_nbCustomer = Time;
prob_nbCustomer(:,end) = prob_nbCustomer(:,end)/obs_length;
for i = 1:K
N0(i) = sum(prob_nbCustomer(:,end).*prob_nbCustomer(:,K+i));
end
end