forked from Transitime/core
-
Notifications
You must be signed in to change notification settings - Fork 32
Tc issue 262 #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scrudden
wants to merge
6
commits into
develop
Choose a base branch
from
tc_issue_262
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tc issue 262 #271
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b0f5d81
Remove hardcoded URL from avlMap.
scrudden 09a4fe2
Set tile url
scrudden 1504b37
Use barefoot to map match an avlreport against a trip shape. Result n…
scrudden 10dc9fa
Use stopPath as external ref id.
scrudden a95822f
Now finds a SpatialMatch and sets all values including distance along…
scrudden 8723a40
Record source of spatial match. Set config paramters for which matche…
scrudden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
transitclock/src/main/java/org/transitclock/core/MapMatcher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.transitclock.core; | ||
|
||
import java.util.Date; | ||
|
||
import org.transitclock.db.structs.AvlReport; | ||
import org.transitclock.db.structs.Block; | ||
import org.transitclock.db.structs.Location; | ||
|
||
public interface MapMatcher { | ||
void setMatcher(Block block, Date assignmentTime); | ||
SpatialMatch getSpatialMatch(AvlReport avlReport); | ||
} |
51 changes: 51 additions & 0 deletions
51
transitclock/src/main/java/org/transitclock/core/MapMatcherFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* This file is part of Transitime.org | ||
* | ||
* Transitime.org is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License (GPL) as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* Transitime.org is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Transitime.org . If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.transitclock.core; | ||
|
||
import org.transitclock.config.StringConfigValue; | ||
import org.transitclock.utils.ClassInstantiator; | ||
|
||
/** | ||
* For instantiating a map matcher object that matches avl locations to trip shapes | ||
* | ||
* @author Sean Óg Crudden | ||
* | ||
*/ | ||
public class MapMatcherFactory { | ||
|
||
// The name of the class to instantiate | ||
private static StringConfigValue className = | ||
new StringConfigValue("transitclock.core.mapMatcherClass", | ||
"org.transitclock.core.barefoot.BareFootMapMatcher", | ||
"Specifies the name of the class used for map matching."); | ||
|
||
/********************** Member Functions **************************/ | ||
|
||
public static MapMatcher getInstance() { | ||
|
||
|
||
try { | ||
return ClassInstantiator.instantiate(className.getValue(), | ||
MapMatcher.class); | ||
} catch (Exception e) { | ||
|
||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
transitclock/src/main/java/org/transitclock/core/barefoot/BareFootMapMatcher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.transitclock.core.barefoot; | ||
|
||
import java.util.Date; | ||
import java.util.Set; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.transitclock.configData.CoreConfig; | ||
import org.transitclock.core.MapMatcher; | ||
import org.transitclock.core.SpatialMatch; | ||
import org.transitclock.db.structs.AvlReport; | ||
import org.transitclock.db.structs.Block; | ||
import org.transitclock.db.structs.Location; | ||
|
||
import com.bmwcarit.barefoot.matcher.Matcher; | ||
import com.bmwcarit.barefoot.matcher.MatcherCandidate; | ||
import com.bmwcarit.barefoot.matcher.MatcherKState; | ||
import com.bmwcarit.barefoot.matcher.MatcherSample; | ||
import com.bmwcarit.barefoot.roadmap.Road; | ||
import com.bmwcarit.barefoot.roadmap.RoadMap; | ||
import com.bmwcarit.barefoot.roadmap.RoadPoint; | ||
import com.bmwcarit.barefoot.roadmap.TimePriority; | ||
import com.bmwcarit.barefoot.spatial.Geography; | ||
import com.bmwcarit.barefoot.spatial.SpatialOperator; | ||
import com.bmwcarit.barefoot.topology.Dijkstra; | ||
import com.esri.core.geometry.Point; | ||
import org.transitclock.utils.Geo; | ||
|
||
public class BareFootMapMatcher implements MapMatcher { | ||
|
||
private RoadMap barefootMap = null; | ||
|
||
private Matcher barefootMatcher = null; | ||
|
||
private MatcherKState barefootState = null; | ||
|
||
private Block block = null; | ||
|
||
private int tripIndex = -1; | ||
|
||
private static SpatialOperator spatial = new Geography(); | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(BareFootMapMatcher.class); | ||
|
||
@Override | ||
public void setMatcher(Block block, Date assignmentTime) { | ||
|
||
if (block != null) { | ||
|
||
this.block = block; | ||
|
||
tripIndex = block.activeTripIndex(assignmentTime, 0); | ||
|
||
TransitClockRoadReader roadReader = new TransitClockRoadReader(block, tripIndex); | ||
|
||
barefootMap = RoadMap.Load(roadReader); | ||
|
||
barefootMap.construct(); | ||
|
||
barefootMatcher = new Matcher(barefootMap, new Dijkstra<Road, RoadPoint>(), new TimePriority(), | ||
new Geography()); | ||
|
||
barefootMatcher.shortenTurns(false); | ||
|
||
barefootState = new MatcherKState(); | ||
} | ||
} | ||
|
||
@Override | ||
public SpatialMatch getSpatialMatch(AvlReport avlReport) { | ||
|
||
if (barefootState != null) { | ||
Point point = new Point(); | ||
point.setX(avlReport.getLon()); | ||
point.setY(avlReport.getLat()); | ||
MatcherSample sample = new MatcherSample(avlReport.getTime(), point); | ||
|
||
Set<MatcherCandidate> result = barefootMatcher.execute(barefootState.vector(), barefootState.sample(), | ||
sample); | ||
|
||
barefootState.update(result, sample); | ||
|
||
MatcherCandidate estimate = barefootState.estimate(); | ||
|
||
logger.debug("Vehicle {} has {} samples.", avlReport.getVehicleId(), barefootState.samples().size()); | ||
|
||
if (estimate != null) { | ||
|
||
Location location = new Location(estimate.point().geometry().getY(), | ||
estimate.point().geometry().getX()); | ||
|
||
ReferenceId refId = ReferenceId.deconstructRefId(estimate.point().edge().base().refid()); | ||
|
||
logger.debug( | ||
"Vehicle {} assigned to {} is {} metres from GPS coordindates on {}. Probability is {} and Sequence probabilty is {}.", | ||
avlReport.getVehicleId(), avlReport.getAssignmentId(), | ||
Geo.distance(location, avlReport.getLocation()), refId, estimate.filtprob(), | ||
estimate.seqprob()); | ||
|
||
return new SpatialMatch(avlReport.getTime(), block, tripIndex, refId.getStopPathIndex(), | ||
refId.getSegmentIndex(), 0, spatial.intercept(estimate.point().edge().geometry(), point) | ||
* spatial.length(estimate.point().edge().geometry())); | ||
|
||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
transitclock/src/main/java/org/transitclock/core/barefoot/ReferenceId.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.transitclock.core.barefoot; | ||
|
||
import java.util.Objects; | ||
|
||
public class ReferenceId { | ||
int stopPathIndex; | ||
int segmentIndex; | ||
static long mutiplier=1000; | ||
public ReferenceId(int stopPathIndex, int segmentIndex) { | ||
super(); | ||
this.stopPathIndex = stopPathIndex; | ||
this.segmentIndex = segmentIndex; | ||
} | ||
|
||
public int getStopPathIndex() { | ||
return stopPathIndex; | ||
} | ||
public void setStopPathIndex(int stopPathIndex) { | ||
this.stopPathIndex = stopPathIndex; | ||
} | ||
public int getSegmentIndex() { | ||
return segmentIndex; | ||
} | ||
public void setSegmentIndex(int segmentIndex) { | ||
this.segmentIndex = segmentIndex; | ||
} | ||
static ReferenceId deconstructRefId(long refId) | ||
{ | ||
int segmentIndex=(int) Math.floorDiv(refId,mutiplier); | ||
int stopPathIndex=(int) Math.floorMod(refId,mutiplier); | ||
return new ReferenceId(stopPathIndex, segmentIndex); | ||
} | ||
long getRefId() | ||
{ | ||
return stopPathIndex+segmentIndex*mutiplier; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ReferenceId [stopPathIndex=" + stopPathIndex + ", segmentIndex=" + segmentIndex + "]"; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(segmentIndex, stopPathIndex); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
ReferenceId other = (ReferenceId) obj; | ||
return segmentIndex == other.segmentIndex && stopPathIndex == other.stopPathIndex; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be good to record the provenance of the match in spatialMatches that ultimately gets selected in getBestTemporalMatch