Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

WIP: handling viterbi breaks as multiple sequences #87

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2c1a010
initial work for handling viterbi breaks as multiple sequences
kodonnell Dec 11, 2016
d979ffd
handle case where viterbi breaks immediately after initialization
kodonnell Dec 12, 2016
6b856f1
merge U-turn work
kodonnell Dec 30, 2016
ade4037
refactoring sequences
kodonnell Jan 13, 2017
4b24cbc
use MatchEntry internally instead of GPXEntry
kodonnell Jan 14, 2017
5832623
debug and fix tests
kodonnell Jan 15, 2017
b6c3af4
rename timestep -> viterbimatchentry
kodonnell Jan 15, 2017
c0e5574
fix other tests
kodonnell Jan 15, 2017
2d184a2
tidying calcpath and gpxfile/main
kodonnell Jan 15, 2017
791e53c
web stuff ...
kodonnell Jan 15, 2017
eed78bf
giving up on that test ...
kodonnell Jan 15, 2017
ac105e7
woops, don't need that anymore ...
kodonnell Jan 15, 2017
d6bf213
refactor + tidy + all tests passing
kodonnell Jan 31, 2017
4e217d0
contiguous sequences
kodonnell Jan 31, 2017
f629883
undo test change to fix test change
kodonnell Feb 1, 2017
9e6cc60
add logging in again as per @stefanholder's request
kodonnell Feb 6, 2017
9d6f84b
Merge branch 'master' into sequences
kodonnell Feb 26, 2017
7f45557
note funny bug ...
kodonnell Feb 26, 2017
4a7420a
some changes as per @stefanholder
kodonnell Mar 20, 2017
13707e1
bringing back the missing readme
kodonnell Mar 20, 2017
efb7b57
a few more tidyups
kodonnell Mar 20, 2017
956e7d0
more tidy-ups
kodonnell Mar 20, 2017
1dd88e8
utilise LocationIndexTree.findWithinRadius
kodonnell Mar 20, 2017
56df0ab
ugly hacky gui ...
kodonnell Mar 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static enum SequenceType { SEQUENCE, STATIONARY, UNKNOWN };
/**
* The matched sequence, as returned from viterbi.computeMostLikelySequence().
*/
private final List<SequenceState<Candidate, MatchEntry, Path>> matchedSequence;
public final List<SequenceState<Candidate, MatchEntry, Path>> matchedSequence;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the map matching result should not contain SequenceState objects since these include internal data that is not relevant for the user. Hence, the relevant information should be extracted from SequenceState into separate result objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could just make it private? The user information (edges, original points in sequence, etc.) can be obtained by the user without it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this is also fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to be package-private as it's used in MapMatching.java for debugging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, no problem.

/**
* Time (inclusive, in milliseconds) when first began on this sequence. -1 if not set.
* TODO: is in inclusive?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
import org.json.JSONObject;

import com.graphhopper.matching.MatchEdge;
import com.graphhopper.matching.MatchEntry;
import com.bmw.hmm.SequenceState;
import com.graphhopper.matching.Candidate;
import com.graphhopper.matching.MatchResult;
import com.graphhopper.matching.MatchSequence;
import com.graphhopper.routing.Path;
import com.graphhopper.util.PointList;

/**
* Transform MatchResult in Json Object with fallow structure:
* Transform MatchResult in JSON Object with following structure:
* <pre>
* { "diary": {
* "routes": [
Expand All @@ -52,32 +56,38 @@ public JSONObject exportTo() {
JSONArray entries = new JSONArray();
JSONObject route = new JSONObject();
JSONArray links = new JSONArray();
for (int emIndex = 0; emIndex < result.getEdgeMatches().size(); emIndex++) {
JSONObject link = new JSONObject();
JSONObject geometry = new JSONObject();
for (MatchSequence matchSequence: result.sequences) {

MatchEdge edgeMatch = result.getEdgeMatches().get(emIndex);
PointList pointList = edgeMatch.getEdgeState().fetchWayGeometry(emIndex == 0 ? 3 : 2);
JSONObject link = new JSONObject();

// add sequence geometry
int emIndex = 0;
for (MatchEdge matchEdge: matchSequence.matchEdges) {
JSONObject geometry = new JSONObject();
PointList pointList = matchEdge.edge.fetchWayGeometry(emIndex == 0 ? 3 : 2);

if (pointList.size() < 2) {
geometry.put("coordinates", pointList.toGeoJson().get(0));
geometry.put("type", "Point");
} else {
geometry.put("coordinates", pointList.toGeoJson());
geometry.put("type", "LineString");
}
if (pointList.size() < 2) {
geometry.put("coordinates", pointList.toGeoJson().get(0));
geometry.put("type", "Point");
} else {
geometry.put("coordinates", pointList.toGeoJson());
geometry.put("type", "LineString");
}

link.put("id", edgeMatch.getEdgeState().getEdge());
link.put("geometry", geometry.toString());
link.put("id", matchEdge.edge.getEdge());
link.put("geometry", geometry.toString());

emIndex++;
}

// add waypoints:
JSONArray wpts = new JSONArray();
link.put("wpts", wpts);

for (Candidate extension : edgeMatch.getGpxExtensions()) {
for (SequenceState<Candidate, MatchEntry, Path> step : matchSequence.matchedSequence) {
JSONObject wpt = new JSONObject();
wpt.put("x", extension.getQueryResult().getSnappedPoint().lon);
wpt.put("y", extension.getQueryResult().getSnappedPoint().lat);
wpt.put("timestamp", extension.getEntry().getTime());
wpt.put("x", step.state.getQueryResult().getSnappedPoint().lon);
wpt.put("y", step.state.getQueryResult().getSnappedPoint().lat);
wpt.put("timestamp", step.observation.gpxEntry.getTime());
wpts.put(wpt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public void doPost(HttpServletRequest httpReq, HttpServletResponse httpRes)
matchRsp = matching.doWork(gpxFile.getEntries());

// fill GHResponse for identical structure
Path path = matching.calcPath(matchRsp);
Translation tr = trMap.getWithFallBack(locale);
DouglasPeucker peucker = new DouglasPeucker().setMaxDistance(wayPointMaxDistance);
PathMerger pathMerger = new PathMerger().
setDouglasPeucker(peucker).
setSimplifyResponse(wayPointMaxDistance > 0);
pathMerger.doWork(matchGHRsp, Collections.singletonList(path), tr);
// Path path = matching.calcPath(matchRsp);
// Translation tr = trMap.getWithFallBack(locale);
// DouglasPeucker peucker = new DouglasPeucker().setMaxDistance(wayPointMaxDistance);
// PathMerger pathMerger = new PathMerger().
// setDouglasPeucker(peucker).
// setSimplifyResponse(wayPointMaxDistance > 0);
// pathMerger.doWork(matchGHRsp, Collections.singletonList(path), tr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this commented out? If the code is really not used anymore it should be deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I didn't know how to get it working - I'll update that when I get the web stuff working.


} catch (Exception ex) {
matchGHRsp.addError(ex);
Expand Down Expand Up @@ -181,7 +181,7 @@ public void doPost(HttpServletRequest httpReq, HttpServletResponse httpRes)
// decode simply by multiplying with 0.5
List<Integer> traversalKeylist = new ArrayList<Integer>();
for (MatchEdge em : matchRsp.getEdgeMatches()) {
EdgeIteratorState edge = em.getEdgeState();
EdgeIteratorState edge = em.edge;
traversalKeylist.add(GHUtility.createEdgeKey(edge.getBaseNode(), edge.getAdjNode(), edge.getEdge(), false));
}
map.put("traversal_keys", traversalKeylist);
Expand Down