-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutput2Struct.m
263 lines (232 loc) · 9.61 KB
/
Output2Struct.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
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
% Results2MATStruct
% Takes in the folder name where results are and gives a structure variable
% (often called MAT) which stores the results in a way that is condusive to
% plotting them. You can optionally probe folder to see contents using
% "OutputFolderPeek.m"
% May run into an issue in the future as simple notation Mn now has
% mroe than just 10-80m spans, it also has 90 and 100m spans Mn90 Mn100
clear, clc
% Folder name where results are. Results should be "similar" files
% AGB
%Folder_Name = 'AGB2002f50k';
% Ceneri2017
%Folder_Name = 'AGB2018';
% Platoon
Folder_Name = 'PlatoonTwinBase';
% We can delete certain results variables if we want (PlatoonwTwin should replace Platoon)
% Ceneri2017Results and Ceneri2017Resultsw/Twin
% Structure Name
% AGB and Ceneri2017
Struct_Name = 'MAT';
% Platoon
%Struct_Name = 'PLAT';
% Add to existing Structure (PLATResults)
%load('Results Variables\PLATResults.mat')
load('Results Variables\Ceneri2017Results.mat')
RegSpans = true; % Used to tell if the normal sequence of Spans (10-80)
% Number of Vehicles for Bidirectional
% AGB
%BiVehNum = 1000000;
% Ceneri2017 and Platoon
BiVehNum = 25000;
% Ensure file list is succinct
File_List = GetFileList(Folder_Name);
% Initialize ResultsPerRun
ResultsPerRun = 0;
% Read in .mat results variables into a signle OInfo variable
for i = 1:length(File_List)
load(['Output/' Folder_Name '/' File_List(i).name])
OInfo(i) = OutInfo;
% BaseFlag only used in cases of Platooning (but shouldn't be a prob)
if OInfo(i).BaseData.RunPlat == 0
BaseFlag = i;
end
% Create matrix of just span lengths
for k = 1:length(OInfo(i).InfNames)
if RegSpans
SpanLengths(k) = str2num(OInfo(i).InfNames{k}(end-1:end));
else % Insert dummy... if we don't have one (change value later)
SpanLengths(k) = 0;
end
end
% Find the number of unique span lengths
if length(unique(OInfo(i).InfNames)) > ResultsPerRun
ResultsPerRun = length(unique(SpanLengths));
end
end
% Clear OutInfo to avoid confusion (we now use complete OInfo)
clear OutInfo
% Name each column of the final matrix/table in the structure
% AGB
%ColumnNames = {'EQ1','EQ2','Eq','GS','GD','CS','CD','DS','DD','E'};
% Ceneri2017
ColumnNames = {'EQ1','EQ2','Eq','TWES','TWED','TWOS','TWOD','FIFS','FIFD','E'};
% Platoon
%ColumnNames = {'BaseMean','BaseMax','SMean','MSMean','MLMean','LMean','SMax','MSMax','MLMax','LMax'};
% AGB and Ceneri2017
if ResultsPerRun == 4
SpanDiv = 20;
else % Platoon (we only do 20, 40, 60, 80m Spans)
SpanDiv = 10;
end
% Initialize the final matrix/table
X = NaN(ResultsPerRun,length(ColumnNames));
XT = array2table(X,'VariableNames',ColumnNames);
% Sometimes we may want to load a results variable in order to add to it
%load('AGBMATResults')
% For reference, the form of each variable
%PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE).(IVD)(Span/20)
%MAT.(Section).(Config).(Dist).(AE).(Loc).(Span/10)
% Step through all output files and put them into Structure Variable
for i = 1:length(OInfo)
% Get Section
if iscell(OInfo(i).BaseData.TransILx)
if OInfo(i).BaseData.TransILx{:} == '0'
Section = 'Box';
elseif strcmp(OInfo(i).BaseData.TransILx{:},'1.5,5.5')
Section = 'TwinRed';
elseif strcmp(OInfo(i).BaseData.TransILx{:},'2.5,8.5')
Section = 'TwinExp';
elseif strcmp(OInfo(i).BaseData.TransILy{:},'0.9,0.1')
Section = 'Twin';
else% strcmp(OInfo(i).BaseData.TransILy{:},'0.7,0.3')
Section = 'TwinConc';
end
else
Section = 'Box';
end
% Get Configuration
if OInfo(i).BaseData.NumVeh == BiVehNum
Config = 'Bi';
else
Config = 'Mo';
end
% Get Distribution
if strcmp(OInfo(i).BaseData.LaneTrDistr{:},'50,50')
Dist = 'Split';
elseif strcmp(OInfo(i).BaseData.LaneTrDistr{:},'96,4')
Dist = 'Stand';
elseif strcmp(OInfo(i).BaseData.LaneTrDistr{:},'100,0')
Dist = 'ExSlow';
else
Dist = 'ExFast';
end
% Get Location (can use various deciders... customization required here)
if OInfo(i).BaseData.TrRate == 0.29
Loc = 'GD';
elseif OInfo(i).BaseData.TrRate == 0.14
Loc = 'CD';
elseif OInfo(i).BaseData.TrRate == 0.07
Loc = 'DD';
elseif OInfo(i).BaseData.TrRate == 0.12 % use CD for Ceneri... change this
Loc = 'xTCD';
else
Loc = 'DetD';
end
if OInfo(i).BaseData.NumVeh == 20000000
Loc = 'TWED';
elseif OInfo(i).BaseData.NumVeh == 2000000
Loc = 'TWOD';
else
Loc = 'FIFD';
end
% Platoon Specific
%--------------------------------------------------
if strcmp(Struct_Name,'PLAT')
if OInfo(i).BaseData.PlatRate == 0.2
PlatRate = 'L20';
elseif OInfo(i).BaseData.PlatRate == 0.4
PlatRate = 'H40';
else
PlatRate = 'Base';
end
if OInfo(i).BaseData.TrRate == 0.12
Loc = 'Ceneri2017';
end
if OInfo(i).BaseData.PlatSize == 2
PlatSize = 'S2';
elseif OInfo(i).BaseData.PlatSize == 3
PlatSize = 'M3';
elseif OInfo(i).BaseData.PlatSize == 4
PlatSize = 'L4';
else
PlatSize = 'Base';
end
if OInfo(i).BaseData.PlatFolDist == 2.5
PlatFolDist = 'SMean';
elseif OInfo(i).BaseData.PlatFolDist == 5
PlatFolDist = 'MSMean';
elseif OInfo(i).BaseData.PlatFolDist == 7.5
PlatFolDist = 'MLMean';
else
PlatFolDist = 'LMean';
end
end
%--------------------------------------------------
% Assign results of current OInfo to correct region in matrix/table
% For each InfCase in OInfo
for k = 1:length(unique(OInfo(i).InfNames))
% Get InfName (call it Temp)
% Needed because there are 2 influence lines for each Twin ESIM
UniqNames = unique(OInfo(i).InfNames,'stable'); % Sorts alphabetically!!!BUG added 'stable'
if RegSpans
Temp = UniqNames{k}; %Fixed 26.5.20
% Get Span from InfName
Span = str2num(Temp(end-1:end));
% Get Action Effect from InfName
AE = Temp(1:end-2);
else
Span = 10; %b/c SpanDiv will be 10
AE = UniqNames{k};
end
% Platoon Specific
if strcmp(Struct_Name,'PLAT')
if OInfo(i).BaseData.RunPlat == 1
% Try assigning values directly, catch if table is not yet initialized
try %PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE).(IVD)(Span/SpanDiv)
if istable(PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE))
PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE).(PlatFolDist)(Span/SpanDiv) = OInfo(i).Mean(k);
PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE).([PlatFolDist(1:end-4) 'Max'])(Span/SpanDiv) = OInfo(i).ESIM(k);
end
catch
PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE) = XT;
PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE).(PlatFolDist)(Span/SpanDiv) = OInfo(i).Mean(k);
PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE).([PlatFolDist(1:end-4) 'Max'])(Span/SpanDiv) = OInfo(i).ESIM(k);
end
PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE).BaseMean(Span/SpanDiv) = OInfo(BaseFlag).Mean(k);
PLAT.(Section).(Dist).(Loc).(PlatSize).(PlatRate).(AE).BaseMax(Span/SpanDiv) = OInfo(BaseFlag).ESIM(k);
end
elseif strcmp(Struct_Name,'MAT')
% Try assigning values directly, catch if table is not yet initialized
try
if istable(MAT.(Section).(Config).(Dist).(AE))
MAT.(Section).(Config).(Dist).(AE).(Loc)(Span/SpanDiv) = OInfo(i).ESIM(k);
if ~isempty(OInfo(i).ESIMS)
MAT.(Section).(Config).(Dist).(AE).([Loc(1:end-1) 'S'])(Span/SpanDiv) = OInfo(i).ESIMS(k);
end
% Only if it has it
if ~isempty(OInfo(i).ESIA)
MAT.(Section).(Config).(Dist).(AE).E(Span/SpanDiv) = OInfo(i).ESIA.Total(k);
MAT.(Section).(Config).(Dist).(AE).Eq(Span/SpanDiv) = OInfo(i).ESIA.Eq(k);
MAT.(Section).(Config).(Dist).(AE).EQ1(Span/SpanDiv) = OInfo(i).ESIA.EQ(1,k);
MAT.(Section).(Config).(Dist).(AE).EQ2(Span/SpanDiv) = OInfo(i).ESIA.EQ(2,k);
end
end
catch
MAT.(Section).(Config).(Dist).(AE) = XT;
MAT.(Section).(Config).(Dist).(AE).(Loc)(Span/SpanDiv) = OInfo(i).ESIM(k);
if ~isempty(OInfo(i).ESIMS)
MAT.(Section).(Config).(Dist).(AE).([Loc(1:end-1) 'S'])(Span/SpanDiv) = OInfo(i).ESIMS(k);
end
% Only if it has it
if ~isempty(OInfo(i).ESIA)
MAT.(Section).(Config).(Dist).(AE).E(Span/SpanDiv) = OInfo(i).ESIA.Total(k);
MAT.(Section).(Config).(Dist).(AE).Eq(Span/SpanDiv) = OInfo(i).ESIA.Eq(k);
MAT.(Section).(Config).(Dist).(AE).EQ1(Span/SpanDiv) = OInfo(i).ESIA.EQ(1,k);
MAT.(Section).(Config).(Dist).(AE).EQ2(Span/SpanDiv) = OInfo(i).ESIA.EQ(2,k);
end
end
end
end
end
% User may choose to save the file (they do so manually)