-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutInfo2VBResults.m
More file actions
344 lines (270 loc) · 16.4 KB
/
OutInfo2VBResults.m
File metadata and controls
344 lines (270 loc) · 16.4 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
clear all, clc
%% Script to create VBResults table from OutInfo results
%% INPUT : Open folder who contains WIM results
% First place is for the WIM or SIM folder,
% Second is for the models folder (if needed)
Folder_Names{1} = 'SimFev19JamTestprBeta4_2'; %'Albertapr'; %'AGB2002_real_pr'; %'WIM1160tAll';
Folder_Names{2} = Folder_Names{1};
%Folder_Names{2} = 'BoxSim3'; %second folder will import the ECodes of the 2sd file
% Select parameters for alpha analysis
AlphaAnalys = 1; % 1)Blended Alpha 2)AlphaQ1 3)AlphaQ2 4)Alphaq
AlphaQ1 = 0.55; %0.6; 0; 0.5;
AlphaQ2 = 0.35; %0.4; 1; 0.35;
Alphaq = 0; %0.5;
%% Running script
%open folders
Dir_List = dir('Output'); % Folder containing the Output results
File_List = {Dir_List.name}';
% check if WIM folder exist
if sum(strcmp(File_List,Folder_Names{1}))>=1
else
error("------------------NO FOLDER IN OUTPUT TRY AGAIN----------------------");
end
% check fast loop
if strcmp(Folder_Names{1},Folder_Names{2})
FasterLoop = 1;
else
FasterLoop = 0;
end
if AlphaAnalys == 1
NameFileSave = append('VBResults.mat');
elseif AlphaAnalys == 2
NameFileSave = append('VBResultsAlphaQ1(Q2=',num2str(AlphaQ2),'etq=',num2str(Alphaq),').mat');
elseif AlphaAnalys == 3
NameFileSave = append('VBResultsAlphaQ2(Q1=',num2str(AlphaQ1),'etq=',num2str(Alphaq),').mat');
elseif AlphaAnalys == 4
NameFileSave = append('VBResultsAlphaq(Q1=',num2str(AlphaQ1),'etQ2=',num2str(AlphaQ2),').mat');
end
%set factors
LambdaQ = 1.5; %SIA
%AlphaQ1 = 0.6; %Fixed at 0.7/0.6
%AlphaQ2 = 0.4; %Fixed at 0.5/0.4
%Alphaq = 0.5; %editable 0.5
LenPrint = []; RamUsed = [];
%% Read inside each WIM reasults and save new format for analyse, same for BoxSimNuma
Dir_List = dir(append('Output/',Folder_Names{1}));
File_List = {Dir_List(:).name}';
%cleaning file list
File_List = File_List(~strcmp(File_List,'.')&~strcmp(File_List,'..')&contains(File_List,'.mat'));
File_List = erase(File_List,'.mat');
% Start Progress Bar
u = StartProgBar(height(File_List), 1, 1, 3-FasterLoop); tic; st = now;
MoyenneTemp = []; % Pour les sims, moyenne des différents traffics
for i=1:height(File_List)
load(append('Output/',Folder_Names{1},'/',File_List{i},'.mat'));
%OutInfo.BaseData.StopSim(1) = 1;
if OutInfo.BaseData.StopSim == 0
Fields1 = fieldnames(OutInfo.pd);
ILDataNames = {OutInfo.ILData.Name}';
for j=1:height(Fields1)
templ = OutInfo.pd.(Fields1{j});
Fields2 = fieldnames(templ);
for k=1:height(Fields2)
for l=1:height(ILDataNames)
% Create and save inside CombInfo struct
BestFit = OutInfo.pd(l).(Fields1{j}).(Fields2{k}).Best;
MatName = append(ILDataNames{l},'.EdLN.',Fields1{j},'.',Fields2{k},' = ','OutInfo.pd(',int2str(l),').',Fields1{j},'.',Fields2{k},'.','(BestFit)','.Ed;');
MatName = erase(MatName,'ILLib');
MatName = append('CombInfo',MatName);
try % Pour les sims, on fait la moyenne sur les différents traffics
eval(append('CombInfo',erase(append(ILDataNames{l},'.EdLN.',Fields1{j},'.',Fields2{k},';'),'ILLib')));
MatName = append(ILDataNames{l},'.EdLN.',Fields1{j},'.',Fields2{k},'(end+1) = ','OutInfo.pd(',int2str(l),').',Fields1{j},'.',Fields2{k},'.','(BestFit)','.Ed;');
MatName = erase(MatName,'ILLib');
MatName = append('CombInfo',MatName);
eval(MatName);
catch
eval(MatName);
end
% Save best fit
MatName = append(ILDataNames{l},'.EdLN.',Fields1{j},'.',Fields2{k},'BestFit',' = BestFit;');
MatName = erase(MatName,'ILLib');
MatName = append('CombInfo',MatName);
eval(MatName);
% Saving prop trucks
MatName = append(ILDataNames{l},'.PropTrucks.',Fields1{j},'.',Fields2{k},' = ','OutInfo.PropTrucks.',Fields1{j},'.',Fields2{k},'(',int2str(l),');');
MatName = erase(MatName,'ILLib');
MatName = append('CombInfo',MatName);
try
eval(MatName);
catch
end
end
end
end
if FasterLoop
Comp_List = fieldnames(OutInfo.E);
ILDataNames = {OutInfo.ILData.Name}';
for j=1:height(Comp_List)
temp2 = OutInfo.E.(Comp_List{j});
Fields1 = fieldnames(temp2);
for k=1:height(Fields1)
for l=1:height(ILDataNames)
% Create and save inside CombInfo struct
MatName = append(ILDataNames{l},'.',Comp_List{j},'.',Fields1{k},' = ','OutInfo.E','(',int2str(l),')','.',Comp_List{j},'.',Fields1{k},';');
MatName = erase(MatName,'ILLib');
MatName = append('CombInfo',MatName);
eval(MatName);
% Check if EdLN exist with EModels, if yes do the ratio
if isfield(eval(append('CombInfo',erase(ILDataNames{l},'ILLib'))),'EdLN') && strcmp(Fields1{k},'Total')
Fields2 = fieldnames(eval(append('CombInfo',erase(ILDataNames{l},'ILLib'),'.EdLN')));
for m=1:height(Fields2)
Fields3 = fieldnames(eval(append('CombInfo',erase(ILDataNames{l},'ILLib'),'.EdLN.',Fields2{m})));
Fields3(contains(Fields3,'BestFit')) = [];
for n=1:height(Fields3)
Actual = append('CombInfo',erase(ILDataNames{l},'ILLib'),'.EdLN',Fields2{m},Fields3{n},'0',Comp_List{j},' = ','CombInfo',erase(ILDataNames{l},'ILLib'),'.EdLN.',Fields2{m},'.',Fields3{n},'/','CombInfo',erase(ILDataNames{l},'ILLib'),'.',Comp_List{j},'.Total;');
eval(Actual);
end
end
end
end
end
end
end
end
% Update progress bar
%user = memory;
%RamUsed = [RamUsed;user.MemUsedMATLAB/(user.MemAvailableAllArrays+user.MemUsedMATLAB)*100];
LenPrint = VBUpProgBar(st,1,i,LenPrint);
end
if FasterLoop == 0
% Go inside Model folder
Dir_List = dir(append('Output/',Folder_Names{2}));
File_List = {Dir_List(:).name}';
%cleaning file list
File_List = File_List(~strcmp(File_List,'.')&~strcmp(File_List,'..')&contains(File_List,'.mat'));
File_List = erase(File_List,'.mat');
% Start Progress Bar
u = StartProgBar(height(File_List), 1, 2, 3); tic; st = now;
for i=1:height(File_List)
load(append('Output/',Folder_Names{2},'/',File_List{i},'.mat'));
if OutInfo.BaseData.StopSim == 0
Comp_List = fieldnames(OutInfo.E);
ILDataNames = {OutInfo.ILData.Name}';
for j=1:height(Comp_List)
temp2 = OutInfo.E.(Comp_List{j});
Fields1 = fieldnames(temp2);
for k=1:height(Fields1)
for l=1:height(ILDataNames)
% Create and save inside CombInfo struct
MatName = append(ILDataNames{l},'.',Comp_List{j},'.',Fields1{k},' = ','OutInfo.E','(',int2str(l),')','.',Comp_List{j},'.',Fields1{k},';');
MatName = erase(MatName,'ILLib');
MatName = append('CombInfo',MatName);
eval(MatName);
% Check if EdLN exist with EModels, if yes do the ratio
if isfield(eval(append('CombInfo',erase(ILDataNames{l},'ILLib'))),'EdLN') && strcmp(Fields1{k},'Total')
Fields2 = fieldnames(eval(append('CombInfo',erase(ILDataNames{l},'ILLib'),'.EdLN')));
for m=1:height(Fields2)
Fields3 = fieldnames(eval(append('CombInfo',erase(ILDataNames{l},'ILLib'),'.EdLN.',Fields2{m})));
for n=1:height(Fields3)
Actual = append('CombInfo',erase(ILDataNames{l},'ILLib'),'.EdLN',Fields2{m},Fields3{n},'0',Comp_List{j},' = ','CombInfo',erase(ILDataNames{l},'ILLib'),'.EdLN.',Fields2{m},'.',Fields3{n},'/','CombInfo',erase(ILDataNames{l},'ILLib'),'.',Comp_List{j},'.Total;');
eval(Actual);
end
end
end
end
end
end
end
% Update progress bar
%user = memory;
%RamUsed = [RamUsed;user.MemUsedMATLAB/(user.MemAvailableAllArrays+user.MemUsedMATLAB)*100];
LenPrint = VBUpProgBar(st,1,i,LenPrint);
end
end
%NameAnala = {'Monthly','Yearly'};
%NameAnala = {'Daily','Weekly','Monthly','Yearly'};
NameAnala = (Fields3(~contains(Fields3,'Fit')))';
%NameAnala = {'Monthly'};
warning('off','MATLAB:table:RowsAddedExistingVars');
% Start Progress Bar
u = StartProgBar(width(NameAnala), 1, 3-FasterLoop, 3-FasterLoop); tic; st = now;
[NumInfCases, ILData] = findILNamesStr(CombInfo);
CodesName = fieldnames(eval(append(ILData(1).Name,';'))); CodesName = CodesName(contains(CodesName,'0'));CodesName = cellfun(@(x) strsplit(x, '0'), CodesName, 'UniformOutput', false);CodesName = vertcat(CodesName{:});CodesName = CodesName(:,2);CodesName = unique(CodesName);
ClassName = fieldnames(eval(append(ILData(1).Name,'.EdLN',';')));
for b = 1:width(NameAnala)
for i = 1:height(CodesName)
% Save new format for plotting all results with AlphaSummaryPlot
VBResults.(CodesName{i}).(NameAnala{b}) = table('Size',[1,15],'VariableTypes',["string","string","string","string","string","string","string","string","double","double","double","double","string","string","string"]);%,"double"]);
VBResults.(CodesName{i}).(NameAnala{b}).Properties.VariableNames = {'Type','SubType','Width','Layout','Support','Trans','AE','Traffic','Span','All','ClassOW','Class','BestFitAll','BestFitClassOW','BestFitClass'};%,'PropTrucks'};
for j = 1:NumInfCases
try
if AlphaAnalys ~= 1
Q1 = eval(append(ILData(j).Name,'.',CodesName{i},'.EQ(1)'));
Q2 = eval(append(ILData(j).Name,'.',CodesName{i},'.EQ(2)'));
Qq = sum(eval(append(ILData(j).Name,'.',CodesName{i},'.Eq')));
end
for k = 1:height(ClassName)
Ed = eval(append('mean(',ILData(j).Name,'.EdLN.',ClassName{k},'.',NameAnala{b},')'));
if AlphaAnalys == 1
VBResults.(CodesName{i}).(NameAnala{b}).(ClassName{k})(j) = eval(append('mean(',ILData(j).Name,'.EdLN',ClassName{k},NameAnala{b},'0',CodesName{i},')'));
VBResults.(CodesName{i}).(NameAnala{b}).(append('BestFit',ClassName{k}))(j) = eval(append(ILData(j).Name,'.EdLN.',ClassName{k},'.',NameAnala{b},'BestFit'));
%VBResults.(CodesName{i}).(NameAnala{b}).(fields10{r})(a) = Ed./(LambdaQ.*(AlphaQ1.*Q1+Alphaq.*Qq+AlphaQ2.*Q2));
elseif AlphaAnalys == 2
VBResults.(CodesName{i}).(NameAnala{b}).(ClassName{k})(j) = (Ed./LambdaQ-(AlphaQ2.*Q2+Alphaq.*Qq))./Q1;
VBResults.(CodesName{i}).(NameAnala{b}).(append('BestFit',ClassName{k}))(j) = eval(append(ILData(j).Name,'.EdLN.',ClassName{k},'.',NameAnala{b},'BestFit'));
elseif AlphaAnalys == 3
VBResults.(CodesName{i}).(NameAnala{b}).(ClassName{k})(j) = (Ed./LambdaQ-(AlphaQ1.*Q1+Alphaq.*Qq))./Q2;
VBResults.(CodesName{i}).(NameAnala{b}).(append('BestFit',ClassName{k}))(j) = eval(append(ILData(j).Name,'.EdLN.',ClassName{k},'.',NameAnala{b},'BestFit'));
elseif AlphaAnalys == 4
VBResults.(CodesName{i}).(NameAnala{b}).(ClassName{k})(j) = (Ed./LambdaQ-(AlphaQ1.*Q1+AlphaQ2.*Q2))./Qq;
VBResults.(CodesName{i}).(NameAnala{b}).(append('BestFit',ClassName{k}))(j) = eval(append(ILData(j).Name,'.EdLN.',ClassName{k},'.',NameAnala{b},'BestFit'));
else
end
end
catch
for k=1:height(ClassName)
VBResults.(CodesName{i}).(NameAnala{b}).(ClassName{k})(j) = 0;
end
end
InflName = strsplit(ILData(j).Name,'.'); InflName = InflName(2:end);
if width(InflName)<8 % For old format of InflLines (AGB)
if contains(InflName{1},'AGBBox')
InflName{7} = InflName{2};InflName{8} = InflName{3};InflName{2} = [];InflName{3} = [];
elseif contains(InflName{1},'AGBTwin')
InflName{7} = InflName{3};InflName{8} = InflName{4};InflName{3} = [];InflName{4} = [];
VBResults.(CodesName{i}).(NameAnala{b}).SubType(j) = InflName{2};
elseif contains(InflName{1},'AGBMulti')
InflName{6} = InflName{2};InflName{7} = InflName{3};InflName{8} = InflName{4};InflName{2} = [];InflName{3} = [];InflName{4} = [];
VBResults.(CodesName{i}).(NameAnala{b}).Trans(j) = InflName{6};
elseif contains(InflName{1},'AGBSlab')
InflName{6} = InflName{3};InflName{7} = InflName{4};InflName{8} = InflName{5};InflName{5} = InflName{2};InflName{2} = [];InflName{3} = [];InflName{4} = [];
VBResults.(CodesName{i}).(NameAnala{b}).Support(j) = InflName{5};
VBResults.(CodesName{i}).(NameAnala{b}).Trans(j) = InflName{6};
else
error('Error with ILData format');
end
else
VBResults.(CodesName{i}).(NameAnala{b}).SubType(j) = InflName{2};
VBResults.(CodesName{i}).(NameAnala{b}).Width(j) = InflName{3};
VBResults.(CodesName{i}).(NameAnala{b}).Layout(j) = InflName{4};
VBResults.(CodesName{i}).(NameAnala{b}).Support(j) = InflName{5};
VBResults.(CodesName{i}).(NameAnala{b}).Trans(j) = InflName{6};
% LM on 13 October, 2022. Correction of the above line
try VBResults.(CodesName{i}).(NameAnala{b}).Traffic(j) = append(InflName{4},num2str(size(eval(append(ILData(j).Name,'.SIA.EQ;')),1)),'L'); catch end
% if (contains(InflName{4},'Uni')||contains(InflName{4},'Bi'))&&(contains(InflName{3},'12')||contains(InflName{3},'9'))
% VBResults.(CodesName{i}).(NameAnala{b}).Traffic(j) = append(InflName{4},'2L');
% elseif ((contains(InflName{4},'Uni')||contains(InflName{4},'Bi'))&&contains(InflName{3},'15'))||(contains(InflName{4},'PUN')&&(contains(InflName{3},'12')||contains(InflName{3},'9')))
% VBResults.(CodesName{i}).(NameAnala{b}).Traffic(j) = append(InflName{4},'3L');
% elseif ((contains(InflName{4},'Uni')||contains(InflName{4},'Bi'))&&contains(InflName{3},'18'))||(contains(InflName{4},'PUN')&&contains(InflName{3},'15'))||(contains(InflName{4},'Chan')&&contains(InflName{3},'12'))
% VBResults.(CodesName{i}).(NameAnala{b}).Traffic(j) = append(InflName{4},'4L');
% elseif (contains(InflName{4},'PUN')&&contains(InflName{3},'18'))||(contains(InflName{4},'Chan')&&contains(InflName{3},'15'))
% VBResults.(CodesName{i}).(NameAnala{b}).Traffic(j) = append(InflName{4},'5L');
% elseif contains(InflName{4},'Chan')&&contains(InflName{3},'18')
% VBResults.(CodesName{i}).(NameAnala{b}).Traffic(j) = append(InflName{4},'6L');
% elseif contains(InflName{1},'Multi')
% VBResults.(CodesName{i}).(NameAnala{b}).Traffic(j) = append(InflName{4},'XL');
% end
end
VBResults.(CodesName{i}).(NameAnala{b}).Type(j) = InflName{1};
VBResults.(CodesName{i}).(NameAnala{b}).AE(j) = InflName{7};
VBResults.(CodesName{i}).(NameAnala{b}).Span(j) = str2double(erase(InflName{8},'S'));
end
end
VBResults.AQ = CombInfo;
% Update progress bar
%user = memory;
%RamUsed = [RamUsed;user.MemUsedMATLAB/(user.MemAvailableAllArrays+user.MemUsedMATLAB)*100];
LenPrint = VBUpProgBar(st,1,b,LenPrint);
end
VBResults.FolderName = Folder_Names{1};
save(NameFileSave,'VBResults');