This repository has been archived by the owner on Jun 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcnSpatialTemporal.m
52 lines (48 loc) · 1.92 KB
/
fcnSpatialTemporal.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
function [F,path_edges] = fcnSpatialTemporal(ptn0_cand,ptn1_cand,ptn0_raw,...
ptn1_raw,delta_t,edg0_cand,edg1_cand,G,node_table,road_network,speed_limits)
%fcnSpatial:spatial analysis function
% Implementation of equation 3 in the paper
% Input:
% ptn0_cand,ptn1_cand: two neighboring candidate points [lon lat]
% ptn0_raw,ptn1_raw: GPS points of which candidate points belong
% road_network: output of splitRoad2Cell
% search for shortest path first
[path_edges,dist_min] = findShortestPath(G,node_table,ptn0_cand,...
edg0_cand,ptn1_cand,edg1_cand,road_network);
if dist_min == 0
F = 0;
elseif dist_min == Inf
% means no path
F = -99999;
else
Fs = fcnSpatial(ptn1_cand,ptn0_raw,ptn1_raw,dist_min);
Ft = fcnTemporal(delta_t,path_edges,dist_min,speed_limits,road_network);
F = Fs * Ft;
end
end
function Fs = fcnSpatial(ptn1_cand,ptn0_raw,ptn1_raw,dist_shortest)
%fcnSpatial:spatial analysis function
% Implementation of equation 3 in the paper
% Input:
% ptn0_cand,ptn1_cand: two neighboring candidate points [lon lat]
% ptn0_raw,ptn1_raw: GPS points of which candidate points belong
% road_network: output of splitRoad2Cell
%%
Ncs = fcnNormal(ptn1_cand,ptn1_raw);
% distance between two GPS points
dist_ratio = deg2km(distance(fliplr(ptn0_raw),fliplr(ptn1_raw)))/dist_shortest;
if dist_ratio >= 1.5
dist_ratio = 0;
% dist_ratio = 1 + log10(dist_ratio)/4;
end
Fs = Ncs*dist_ratio;
end
function Ft = fcnTemporal(delta_t,path_edges,dist_min,speed_limits,road_network)
avg_speed = dist_min / delta_t * 60 * 60;
path_edges = unique(path_edges);
avg_speed_vec = repmat(avg_speed,1,length(path_edges));
speed_limit_vec = speed_limits(ismember(road_network(:,1),path_edges),:)';
% cosine distance of two speed vecotrs
Ft = sum(avg_speed_vec.*speed_limit_vec)/...
sqrt(sum(avg_speed_vec.^2)*sum(speed_limit_vec.^2));
end