Repository navigation
moved LocationIndexMatch.findNClosest from map-matching to LocationIndexTree - #994
Conversation
LocationIndexTree.findWithinRadius
boldtrn
left a comment
There was a problem hiding this comment.
Thanks for this PR. While reviewing the code a couple of questions came to my mind, see my comments. Other from that I think this is a great addition to the core and might be very useful for a couple of use-cases.
| * @param edgeFilter only include edges from edgeFilter | ||
| * @param radius include all results within this radius (in meters) - assuming it's not | ||
| * bounded by maxIterations. | ||
| * @param maxIterations if not null, search only a square of (2 * maxIterations - 1) tiles |
There was a problem hiding this comment.
I don't get the purpose of maxIterations and radius.
include all results within this radius (in meters) - assuming it's not bounded by maxIterations.
How can I bound the radius with maxIterations, when maxIterations says:
Note that it is possible that the search radius exceeds this square - in this case, an exception will be thrown.
To me this sounds contradicting. You can bound the radius with maxIterations, but maxIterations has to be at least as big as the radius.
So maxIterations can increase the radius? But why bothering, I could just increase the radius.
BTW: At this point haven't really looked at the code, I just stumbled over the JavaDoc.
Edit:
Ok, I am finished with reviewing the code and still don't understand maxIterations.
Is it necessary to have maxIterations? If yes why? And if yes, wouldn't it be easier to have a wrapper method that allows calling this method without maxIterations?
Edit2:
In MapMatching 65, you specify that this is an edgeCase, but why would one wants to increase the maxIterations to be bigger than the specified radius. Results outside the radius shouldn't be included anyway?
There was a problem hiding this comment.
I don't get the purpose of maxIterations and radius.
The purpose is to find everything within radius. The maxIterations is there to bound to a certain amounts of tiles - as discussed in MapMatching 65. (Personally, I don't think it's required - as long as we always search one tile index 'greater' than the radius - but that's what was in the code - and I'd prefer to keep this a moving of the method as opposed to a rewrite. Yes, I did rewrite it somewhat so that the method actually reflected it's purpose and implementation.)
To me this sounds contradicting
Good point. I think I changed the logic to throw an error after I'd written the first part of the doc. Will update.
So maxIterations can increase the radius?
No. The purpose (I think) is to say "OK, give me all the results within 100m - but don't look more than 2 tiles away". As far as I'm aware, it's there for performance.
Is it necessary to have maxIterations?
Yes and no. I believe it's necessary to e.g. always do at least two iterations, even if you find something in the first. However, we could rewrite the logic to reflect this (i.e. always one 'greater' than the radius). It's not necessary for actually bounding the edges - radius does that. (Again, I'm going with what's there - if we want to change it, that's fine with me.)
wouldn't it be easier to have a wrapper method that allows calling this method without maxIterations?
If you wish - I allowed it to be called with maxIterations = null which does this.
In MapMatching 65, you specify that this is an edgeCase, but why would one wants to increase the maxIterations to be bigger than the specified radius. Results outside the radius shouldn't be included anyway?
See comment by @karussell in MapMatching 65 (which is what I was referring to above) - you always need to do at least two. Maybe my description of it is misleading ...
@karussell - maybe you have some comments? I was hoping to leave the logic generalisations until later, but if it's confusing in it's existing state, we should probably do it now.
There was a problem hiding this comment.
The purpose is to find everything within radius. The maxIterations is there to bound to a certain amounts of tiles - as discussed in MapMatching 65.
Sorry, I still don't really get it. Shouldn't this be the default? If we actually want something like this, could we create a boolean like: "includeSurroundingTiles". This would increase the requiredRadius by one. I think this parameter requires too much knowledge about the actual method. Since this is a public method and is intended to be used by everyone, we should keep it simple.
There was a problem hiding this comment.
We have to do that even for the normal version but this parameter allows for even longer searches. See #221
I would also prefer to avoid this extra parameter in the method - isn't this also more a static configuration like 'maximum allowed visited nodes' and not per request?
There was a problem hiding this comment.
I dont know = ) I think I may have confused it with how I interpreted maxIterations originally - it's not "iterate through no more than this many tiles" it's "iterate through this many tiles". On second thought, I now think it should really just be making sure that we always include the extra surrounding tiles - which should have nothing to do with the user.
| } | ||
|
|
||
| final double returnAllResultsWithin = distCalc.calcNormalizedDist(radius); | ||
| // implement a cheap priority queue via List, sublist and Collections.sort |
There was a problem hiding this comment.
Why aren't we using a PriorityQueue?
I assume there is a reason, maybe we could add the reason to the comment?
There was a problem hiding this comment.
No idea - that's how it was done in map-matching, and I was just shifting it across.
There was a problem hiding this comment.
Good question. Lets address in a different issue or via discuss :)
| // check the max iterations: | ||
| int requiredIterationsForThisRadius = (int) Math.ceil(radius / this.minResolutionInMeter) | ||
| + 1; // note that this is a conservative upper bound | ||
| int _maxIterations; |
There was a problem hiding this comment.
Why do we prefix with _? Wouldn't be a good name for the variable better?
There was a problem hiding this comment.
Just my convention - something like tmpMaxIterations?
There was a problem hiding this comment.
Not sure, as it's not really tmp. I would favor removing maxIterations from the parameter list :). But let's discuss this in the comment above.
| final double returnAllResultsWithin = distCalc.calcNormalizedDist(radius); | ||
| // implement a cheap priority queue via List, sublist and Collections.sort | ||
| final List<QueryResult> queryResults = new ArrayList<QueryResult>(); | ||
| GHIntHashSet set = new GHIntHashSet(); |
There was a problem hiding this comment.
What does the set contain? Needed check the code again to see where it was passed.
There was a problem hiding this comment.
See third argument of findNetworkEntries - I can't remember now, but I believe it's all of the nodes found up to and including that iteration of findNetworkEntries.
There was a problem hiding this comment.
Sorry, I should have written the comment differently. I would just prefer a different name, as set can contain everything.
| @Override | ||
| protected boolean check(int node, double normedDist, int wayIndex, | ||
| EdgeIteratorState edge, QueryResult.Position pos) { | ||
| if (normedDist < returnAllResultsWithin || queryResults.isEmpty() |
There was a problem hiding this comment.
isEmpty check to make sure that at least one result is returned? Should we remove that result later?
There was a problem hiding this comment.
That's how the current code is structured. I agree with you - see my comments. Maybe it should be removed, as it doesn't behave as described. @karussell - is there a reason we need to keep this? Should we make it optional?
There was a problem hiding this comment.
The idea was to have at least one candidate even if outside, so maybe this is not necessary, yes.
Here again let us try to minimize this issue and create improvement issues separately to make merging this faster.
| } | ||
|
|
||
| // avoid duplicate edges | ||
| if (qr.getClosestEdge().getEdge() == edge.getEdge()) { |
There was a problem hiding this comment.
Why aren't we using a set/map here and filter potential unwanted results after the for loop?
With for loop I mean:
for (int iteration = 0; iteration < _maxIterations; iteration++) {
There was a problem hiding this comment.
I agree (I think) as per my comment about 'clean[ing] up the index tracking business'. However, again, I wanted to port the functionality and tests before tweaking. We can rewrite if you prefer ...
|
As a general comment, there's possibly cause for a more thorough rewrite. I feel a lot of the machinery is aligned with the GH use cases, which are to find the nearest candidates to a point. If we want to be fully generic, then we could probably e.g. make better use of the quadtree (as opposed to always looping through leaf nodes - I think that's the term). |
Yes maybe. Sorry for being so petty about the implementation, as this PR is only about moving the method :). |
|
Thanks a lot @kodonnell ! To make merging this a no-brainer would you mind to remove the maxIterations parameter? We can then discuss the improvements or rewrite in a separate issue or in a dev discuss topic
What do you mean here? |
Done - and to remove the brain completely, I've just reverted to the original map-matching code - I didn't change the name as it'd be wrong too, and it probably makes sense to clarify the purpose before editing it further.
At the moment we're manually iterating through every leaf node (I think). If we've got a radius of 8km, with leaf node size of 1km, then (heuristically) we'd first find the four covering 8km-radius nodes, and then drill down through each using the quadtree until we get to the leaf nodes that contain stuff (which might be e.g. the 4km one in some cases, the 2km in others, etc.). It's a more natural use of a quadtree, and could have better performance in the case where a lot of the search radius is empty (i.e. we know the parent is empty, so no need to check the children). That'd also be especially true if we're traversing the quadtree every time we seach a leaf node. That all said, I've got no idea how the GH quadtree is implemented, so the above might all be baloney = )
No worries - though I feel like me doing PR's actually takes you guys more time that if you did it yourselves! Hopefully I'll get better. |
Aha, makes sense. Still the quadtree implementation is very fast so even if we do this a couple of times without success I guess the improvements will be not really comparable to the routing time.
no no :). I'm/we're thankfully for every work being done from others, as the repository activity is nicely/overwhelming increasing :) |
|
Thanks @karussell = ) Opened #997 for the issues discussed above. |
This is for #993
and map-matching 65. Comments:no real logic changed excepted made maxIterations configurable (from hardcoded value of 2 in map-matching) and throws an error if maxIterations 'truncates' the radius (as discussed in map-matching 65).I've added some comments for tidy-ups (that can be made later).renamed tofindWithinRadiusto better reflect the method (as opposed to the somewhat misleadingfindNClosest).and added one to check the error is thrown for maxIterations truncation.