-
Notifications
You must be signed in to change notification settings - Fork 6
/
map_matcher_4326_small_test.go
112 lines (96 loc) · 3.58 KB
/
map_matcher_4326_small_test.go
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
package horizon
import (
"fmt"
"math"
"testing"
"time"
)
func TestMapMatcherSRID_4326(t *testing.T) {
var (
currentTime = time.Now()
graphFileName = "./test_data/matcher_4326_test.csv"
sigma = 50.0
beta = 2.0
gpsMeasurements = GPSMeasurements{
NewGPSMeasurement(1, 37.662745994981435, 55.77323867786974, 4326, WithGPSTime(currentTime.Add(1*time.Second))),
NewGPSMeasurement(2, 37.66373679411533, 55.77352528537278, 4326, WithGPSTime(currentTime.Add(2*time.Second))),
NewGPSMeasurement(3, 37.6634658408828, 55.77408712095024, 4326, WithGPSTime(currentTime.Add(3*time.Second))),
NewGPSMeasurement(4, 37.66271768643477, 55.77491052526131, 4326, WithGPSTime(currentTime.Add(4*time.Second))),
}
correctStates = MatcherResult{
Observations: []ObservationResult{
{Observation: gpsMeasurements[0]},
{Observation: gpsMeasurements[1]},
{Observation: gpsMeasurements[2]},
{Observation: gpsMeasurements[3]},
},
Probability: -48.239713,
}
)
hmmParams := NewHmmProbabilities(sigma, beta)
matcher, err := NewMapMatcher(hmmParams, graphFileName)
if err != nil {
t.Error(err)
}
correctStates.Observations[0].MatchedEdge = *matcher.engine.edges[101][102]
correctStates.Observations[1].MatchedEdge = *matcher.engine.edges[101][102]
correctStates.Observations[2].MatchedEdge = *matcher.engine.edges[101][102]
correctStates.Observations[3].MatchedEdge = *matcher.engine.edges[102][105]
statesRadiusMeters := 7.0
maxStates := 5
result, err := matcher.Run(gpsMeasurements, statesRadiusMeters, maxStates)
if err != nil {
t.Error(err)
}
if len(result.Observations) != len(correctStates.Observations) {
t.Errorf("Result should contain %d measurements, but got %d", len(correctStates.Observations), len(result.Observations))
}
eps := 10e-6
if math.Abs(result.Probability-correctStates.Probability) > eps {
t.Errorf("Path's probability should be %f, but got %f", correctStates.Probability, result.Probability)
}