/
showTrips.m
205 lines (177 loc) · 5.12 KB
/
showTrips.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
function showTrips(place,gridSize,sigma,saveFigures)
% Shows graph and histogram of Trips, Max Flow and Shortest Path and their intercorrelation
%
% INPUT:
% place (String) - Name of polygon area in OpenSteetMap
% gridSize (Integer) - Grid granularity in metres
% sigma (Integer) - Standard deviation to use for gaussian blurring
% saveFigures (boolean) - Optional boolean switch for saving figures
% OUTPUT:
% Graph view of trips, max-flow and shortest path
% Histogram of trips, max-flow and shortest path
% Correlation between trips, max-flow and shortest path
% EXAMPLE:
% showTrips('Bristol',1000,1,true)
% NOTE:
% The fourth option is to save the diagrams into cropped PDF files
% ISSUES:
% At the moment, saving the files into cropped PDF doesn't work
% properly on Ubuntu machine but works perfectly well on the OSX.
% The fonts do the appear in the required size and the diagrams
% are not always cropped.
% Read the data to be outputted
[TR,MF,SP,ODnodes,HAM,DAM,nodes] = getTrips(place,gridSize,sigma);
% Expand the sparse matrices to full matrices for use in
% correlations and histograms
Sp=full(SP(:));
Tr=full(TR(:));
Mf=full(MF(:));
% Remove all the unresolved shortest paths
SP(SP==Inf)=0;
% Remove all the Max Flows that are zero as well as the corresponding
% indices from Trips and Shortest Path
a=find(Mf==0);
Mf(a) = [];
Sp(a) = [];
Tr(a) = [];
%% Subplots if not saving figures
% Dimension of the Sub-plots
Pi=2; Pj=3;
if ~saveFigures
figure;
plot3k([Sp,Tr,Mf]);
end;
%% Correlation - Shortest Path vs Trips
if ~saveFigures
figure('units','normalized','outerposition',[0 0 1 1]);
subplot(Pi,Pj,1);
else
figure;
end
scatter(log(Sp),log(Tr)); % Draw data points
legend('Raw Data');
xlabel('log(Shortest path (m))');
ylabel('log(Trips (Pi*Pj/Dij))');
if saveFigures
set(gcf,'Position', [0, 0, 800, 300]);
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/corr-shortestPathVsTrips-' place '.pdf']);
end
%% Correlation - Max Flow vs Shortest Path
% Calculate line of best bit
p = polyfit(Mf,Sp,3); % p returns 2 coefficients fitting r = a_1 * x + a_2
r = p(1) * Mf.^3 + p(2) * Mf.^2 + p(3) * Mf.^1 + p(4); % compute a new vector r that has matching datapoints in x
[~,i]=sort(Mf);
% Start drawing
if ~saveFigures
subplot(Pi,Pj,2);
else
figure;
end
hold on;
plot(Mf(i),log(r(i)),'LineWidth',2); % Plot best fit line
scatter(Mf, log(Sp)); % Draw data points
hold off;
legend('Average','Raw Data','Location','SouthEast');
xlabel('Maximum Flow (persons/min)');
ylabel('log(Shortest Path (m))');
if saveFigures
set(gcf,'Position', [0, 0, 800, 300]);
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/corr-maxFlowVsShortestPath-' place '.pdf']);
end
%% Correlation - Max Flow vs Trips
% Calculate line of best bit
p = polyfit(Mf,Tr,3); % p returns 2 coefficients fitting r = a_1 * x + a_2
r = p(1) * Mf.^3 + p(2) * Mf.^2 + p(3) * Mf.^1 + p(4); % compute a new vector r that has matching datapoints in x
[~,i]=sort(Mf);
% Start Drawing
if ~saveFigures
subplot(Pi,Pj,3);
else
figure;
end
hold on;
plot(Mf(i),log(r(i)),'LineWidth',2); % Plot best fit line
scatter(Mf,log(Tr)); % Draw data points
hold off;
legend('Average','Raw Data')
xlabel('Maximum Flow (persons/min)');
ylabel('log(Trips (Pi*Pj/Dij))');
if saveFigures
set(gcf,'Position', [0, 0, 800, 300]);
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/corr-maxFlowVsTrips-' place '.pdf']);
end
%% Histogram - Shortest Path
if ~saveFigures
subplot(Pi,Pj,4);
else
figure;
end
hist(Sp, 15);
xlabel('Shortest Path (m)','FontSize',20);
ylabel('Count','FontSize',20);
if saveFigures
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/hist-shortestPath-' place '.pdf']);
end
%% Histogram - Max Flow
if ~saveFigures
subplot(Pi,Pj,5);
else
figure;
end
hist(Mf, 15);
xlabel('Max Flow (cars/min)','FontSize',20);
ylabel('Count','FontSize',20);
if saveFigures
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/hist-maxFlow-' place '.pdf']);
end
%% Histogram - Trips
if ~saveFigures
subplot(Pi,Pj,6);
else
figure;
end
hist(Tr, 15);
xlabel('Trips (Pi*Pj/Dij)','FontSize',20);
ylabel('Count','FontSize',20);
if saveFigures
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/hist-trips-' place '.pdf']);
end
%% Graph - Max Flow
figure;
hold on;
gplot(HAM,nodes,'k');
wgPlot(MF,ODnodes);
legend('Max Flow');
if saveFigures
set(gcf,'Position', [0, 0, 800, 500]);
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/graph-maxFlow-' place '.pdf']);
end
%% Graph - Trips
figure;
hold on;
gplot(HAM,nodes,'k');
wgPlot(TR,ODnodes);
legend('Trips');
if saveFigures
set(gcf,'Position', [0, 0, 800, 500]);
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/graph-trips-' place '.pdf']);
end
%% Graph - Shortest Path
figure;
hold on;
gplot(HAM,nodes,'k');
wgPlot(SP,ODnodes);
legend('Shortest Path');
if saveFigures
set(gcf,'Position', [0, 0, 800, 500]);
set(gcf, 'Color', 'w');
export_fig(['./figures/highway/graph-shortestPath-' place '.pdf']);
end