99
1010namespace Sandwych . MapMatchingKit . Matching
1111{
12+ using CandidateProbability = CandidateProbability < MatcherCandidate > ;
13+ using TransitionProbability = TransitionProbability < MatcherTransition > ;
14+
15+
1216 /// <summary>
1317 /// Matcher filter for Hidden Markov Model (HMM) map matching. It is a HMM filter (<see cref="IFilter{TCandidate, TTransition, TSample}"/>)
1418 /// and determines emission and transition probabilities for map matching with HMM.
@@ -77,7 +81,7 @@ public double Sigma
7781 public double MaxDistance { get ; set ; } = 15000.0 ;
7882
7983
80- public override IReadOnlyCollection < ( MatcherCandidate , double ) > Candidates (
84+ public override IReadOnlyCollection < CandidateProbability > Candidates (
8185 IEnumerable < MatcherCandidate > predecessors , in MatcherSample sample )
8286 {
8387 var points_ = this . _map . Radius ( sample . Coordinate , this . MaxRadius ) ;
@@ -91,20 +95,20 @@ public double Sigma
9195
9296 foreach ( var predecessor in predecessors )
9397 {
94- var pointExisted = dict . TryGetValue ( predecessor . RoadPoint . Edge . Id , out var point ) ;
98+ var pointExisted = dict . TryGetValue ( predecessor . Point . Edge . Id , out var point ) ;
9599 if ( pointExisted && point . Edge != null
96- && _spatial . Distance ( point . Coordinate , predecessor . RoadPoint . Coordinate ) < this . Sigma
100+ && _spatial . Distance ( point . Coordinate , predecessor . Point . Coordinate ) < this . Sigma
97101 && ( ( point . Edge . Headeing == Heading . Forward
98- && point . Fraction < predecessor . RoadPoint . Fraction )
102+ && point . Fraction < predecessor . Point . Fraction )
99103 || ( point . Edge . Headeing == Heading . Backward
100- && point . Fraction > predecessor . RoadPoint . Fraction ) ) )
104+ && point . Fraction > predecessor . Point . Fraction ) ) )
101105 {
102106 points . Remove ( point ) ;
103- points . Add ( predecessor . RoadPoint ) ;
107+ points . Add ( predecessor . Point ) ;
104108 }
105109 }
106110
107- var candidates = new List < ( MatcherCandidate , double ) > ( points . Count ) ;
111+ var candidates = new List < CandidateProbability > ( points . Count ) ;
108112
109113 foreach ( var point in points )
110114 {
@@ -121,39 +125,39 @@ public double Sigma
121125 }
122126
123127 var candidate = new MatcherCandidate ( point ) ;
124- candidates . Add ( ( candidate , emission ) ) ;
128+ candidates . Add ( new CandidateProbability ( candidate , emission ) ) ;
125129 }
126130
127131 return candidates ;
128132 }
129133
130- public override ( MatcherTransition , double ) Transition (
134+ public override TransitionProbability Transition (
131135 in ( MatcherSample , MatcherCandidate ) predecessor , in ( MatcherSample , MatcherCandidate ) candidate )
132136 {
133137 throw new NotSupportedException ( ) ;
134138 }
135139
136- public override IDictionary < MatcherCandidate , IDictionary < MatcherCandidate , ( MatcherTransition , double ) > > Transitions (
140+ public override IDictionary < MatcherCandidate , IDictionary < MatcherCandidate , TransitionProbability > > Transitions (
137141 in ( MatcherSample , IEnumerable < MatcherCandidate > ) predecessors ,
138142 in ( MatcherSample , IEnumerable < MatcherCandidate > ) candidates )
139143 {
140- var targets = candidates . Item2 . Select ( c => c . RoadPoint ) ;
144+ var targets = candidates . Item2 . Select ( c => c . Point ) ;
141145
142- var transitions = new Dictionary < MatcherCandidate , IDictionary < MatcherCandidate , ( MatcherTransition , double ) > > ( ) ;
146+ var transitions = new Dictionary < MatcherCandidate , IDictionary < MatcherCandidate , TransitionProbability > > ( ) ;
143147 var base_ = 1.0 * _spatial . Distance ( predecessors . Item1 . Coordinate , candidates . Item1 . Coordinate ) / 60.0 ;
144148 var bound = Math . Max ( 1000.0 , Math . Min ( this . MaxDistance , ( ( candidates . Item1 . Time - predecessors . Item1 . Time ) / 1000.0 ) * 100.0 ) ) ;
145149
146150 foreach ( var predecessor in predecessors . Item2 )
147151 {
148- var map = new Dictionary < MatcherCandidate , ( MatcherTransition , double ) > ( ) ;
152+ var map = new Dictionary < MatcherCandidate , TransitionProbability > ( ) ;
149153 //TODO check return
150- var routes = _router . Route ( predecessor . RoadPoint , targets , _cost , Costs . DistanceCost , bound ) ;
154+ var routes = _router . Route ( predecessor . Point , targets , _cost , Costs . DistanceCost , bound ) ;
151155
152156 foreach ( var candidate in candidates . Item2 )
153157 {
154- if ( routes . TryGetValue ( candidate . RoadPoint , out var edges ) )
158+ if ( routes . TryGetValue ( candidate . Point , out var edges ) )
155159 {
156- var route = new Route ( predecessor . RoadPoint , candidate . RoadPoint , edges ) ;
160+ var route = new Route ( predecessor . Point , candidate . Point , edges ) ;
157161
158162 // According to Newson and Krumm 2009, transition probability is lambda *
159163 // Math.exp((-1.0) * lambda * Math.abs(dt - route.length())), however, we
@@ -168,7 +172,7 @@ public override (MatcherTransition, double) Transition(
168172 var transition = ( 1D / beta ) * Math . Exp (
169173 ( - 1.0 ) * Math . Max ( 0D , route . Cost ( _cost ) - base_ ) / beta ) ;
170174
171- map . Add ( candidate , ( new MatcherTransition ( route ) , transition ) ) ;
175+ map . Add ( candidate , new TransitionProbability ( new MatcherTransition ( route ) , transition ) ) ;
172176 }
173177 }
174178
0 commit comments