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
use super::prelude::*;
fn stlc_spa(t1: &Trajectory, t2: &Trajectory) -> f32 {
let mut spa = 0f32;
for location in &t1.locations {
spa += (0.0 - location.pos.shortest_distance_from_trajectory(t2).unwrap()).exp();
}
spa /= t1.len() as f32;
spa
}
fn stlc_tem(t1: &Trajectory, t2: &Trajectory) -> f32 {
let mut tem = 0f32;
for location in &t1.locations {
tem += (0.0 - location.time_shortest_distance_from_trajectory(t2).unwrap() as f32).exp();
}
tem /= t1.len() as f32;
tem
}
pub fn stlc_trajectory_similarity(traj1: &Trajectory, traj2: &Trajectory, lambda: f32) -> Option<f32> {
if traj1.is_empty() || traj2.is_empty() { return None; }
let spa = (stlc_spa(traj1, traj2) + stlc_spa(traj2, traj1)) / 2.0;
let tem = (stlc_tem(traj1, traj2) + stlc_tem(traj2, traj1)) / 2.0;
let sim = spa * lambda + (1.0 - lambda) * tem;
Some(sim)
}
mod test {
#[test]
fn test_temp() {
}
}