Skip to content

Incorporate filter search into the finding of the closest node search. - #318

Closed
crowmagnumb wants to merge 3 commits into
masterfrom
unknown repository
Closed

crowmagnumb wants to merge 3 commits into
masterfrom
unknown repository

Conversation

@crowmagnumb

Copy link
Copy Markdown

The problem is as I discussed about the filtering. It's not a question of does the expanded search find a node or not, it's does the expanded search find a node that passes my filter. Inside of findClosest the findNetworkEntries returns a set of node ids, then we loop through these nodes using the edge explorer and the supplied filter. The basic search does not find a node that passes my filter so findClosest returns a "null" QueryResult. If I try and expand the search further I still don't find my node because no matter what value of maxRegionSearch, findNetworkEntries returns the first set of nodes that it finds but I already know those don't pass my filter, so once again they don't pass my filter and I get a "null" result.

I've added the boolean to allow the filtering of the edges to be built into the search mechanism. I only added it to maintain backwards compatibility. I honestly don't see why this is not just done automatically.

@karussell

Copy link
Copy Markdown
Member

Hmmh, I don't understand your usecase. Can you give me an example of how you use this? E.g. You want to find the closest bus station(s) or something?

Also we need tests for this feature otherwise your use case will be lost or broken when a new refactoring comes in.

Furthermore I would prefer to avoid exploring within findNetworkEntries as this method is just about collecting nodes. So we need some kind of a loop over 'collect & explore & filter the edges' where the filter can also decide if the search should be stopped or not.

@karussell

Copy link
Copy Markdown
Member

Hmmh, you are holding more vehicles and location index returns earlier with only 'car edges' but you need e.g. 'bike edges'?

@crowmagnumb

Copy link
Copy Markdown
Author

Well, that is a pretty good example you just gave, and in a sense I am
doing something similar. I have a bunch of utility poles that I have to
visit. For each one I find the edge it is on and thus make a list of all
the edges I need to visit. Then starting with the first I route the user to
that edge, after that I route them to an adjacent edge if there is one in
the list. If not, I then use the findClosest() to find the closest edge
that is in my list of edges that I have to visit and then route them there,
and so on until I have visited all my edges.

On Wed Feb 04 2015 at 1:09:21 PM Peter [email protected] wrote:

Hmmh, I don't understand your usecase. Can you give me an example of how
you use this? E.g. You want to find the closest bus station or something?

Also we need tests for this feature otherwise your use case will be lost
or broken when a new refactoring comes in.

Furthermore I would prefer to avoid exploring within findNetworkEntries as
this method is just about collecting nodes. So we need some kind of a loop
over 'collect & explore & filter the edges' where the filter can also
decide if the search should be stopped or not.

—
Reply to this email directly or view it on GitHub
#318 (comment)
.

@crowmagnumb

Copy link
Copy Markdown
Author

I'm not sure what you meant by that question about the car vs. bike edges.

On Wed Feb 04 2015 at 1:20:10 PM Ken Southerland [email protected]
wrote:

Well, that is a pretty good example you just gave, and in a sense I am
doing something similar. I have a bunch of utility poles that I have to
visit. For each one I find the edge it is on and thus make a list of all
the edges I need to visit. Then starting with the first I route the user to
that edge, after that I route them to an adjacent edge if there is one in
the list. If not, I then use the findClosest() to find the closest edge
that is in my list of edges that I have to visit and then route them there,
and so on until I have visited all my edges.

On Wed Feb 04 2015 at 1:09:21 PM Peter [email protected] wrote:

Hmmh, I don't understand your usecase. Can you give me an example of how
you use this? E.g. You want to find the closest bus station or something?

Also we need tests for this feature otherwise your use case will be lost
or broken when a new refactoring comes in.

Furthermore I would prefer to avoid exploring within findNetworkEntries
as this method is just about collecting nodes. So we need some kind of a
loop over 'collect & explore & filter the edges' where the filter can also
decide if the search should be stopped or not.

—
Reply to this email directly or view it on GitHub
#318 (comment)
.

@karussell

Copy link
Copy Markdown
Member

So what you want is the best tour for N points? And what you currently do is a heuristic solution to that problem, it is not optimial, right?

@crowmagnumb

Copy link
Copy Markdown
Author

It is absolutely not optimal because N can be as large as say 1000. i.e. very large. It is not possible in our lifetimes to find the optimal solution. What I find is a damn fine route that is pretty darn good. Optimal? No.

@crowmagnumb

Copy link
Copy Markdown
Author

And incorporating the explore in the find results in a much more efficient algorithm. If this is not the desired behavior for all cases (again, I really can't see why not, at least from the stand-point of the findClosest() routine) then I propose a separate routine for this.

@karussell

Copy link
Copy Markdown
Member

That heuristic should be good, yes.

Still the LocationIndex is the wrong tool for what you want IMO. What you could do is to use Dijkstra with many destinations:

QueryGraph qGraph = new QueryGraph(graph);
qGraph.lookup(yourLocations);
Dijkstra dijkstra = new Dijkstra(qGraph, encoder, weighting, TraversalMode.NODE_BASED) {
   @Override protected boolean finished() {
        // your condition e.g. a set of (virtual) nodes
    }            
};
// TODO currently not public
dijkstra.runAlgo();

Or just calculate ALL distances between ALL locations and feed an optimization tool (for <10 you can do brute force search). Calculating all distances or times is easy and fast with our Matrix API but with plain GraphHopper and two simple for-loops that is often also acceptable fast.

@karussell

Copy link
Copy Markdown
Member

The problem with the LocationIndex and your usecase is that there is no order guaranteed, where Dijkstra guarantees that it visits the closer edges first.

@karussell

Copy link
Copy Markdown
Member

Still there might be indeed a problem if e.g. your graph contains car and bike streets, now you search for the closest bike street but the findNetworkEntries method returns only nodes exploring car streets (e.g. close to a motorway)

@crowmagnumb

Copy link
Copy Markdown
Author

It is not the routing problem I need solved. I have my routing problem and it's solved. What I wrote above was a great oversimplification of the problem, giving you just enough info necessary for this discussion. Telling me to use Dijkstra to solve my problem is missing the mark.

But you keep getting glimpses of my problem. Your example of bike vs. car streets is exactly the same issue as I am having. If you use my version, that problem goes away. :)

@karussell

Copy link
Copy Markdown
Member

I've fixed this issue - see my new pull request: #488

Slightly more refactoring was necessary. It also should be faster on average now.

@crowmagnumb if my new change is not working as expected in your case, please let me know!

@karussell karussell closed this Aug 10, 2015
@crowmagnumb

Copy link
Copy Markdown
Author

Thanks! Sorry I haven't had time to check as I've sinced changed jobs and have not been working on this for a while. If I get back to that, and some day I hope to, I will definitely check it out. Cheers.

dabiih pushed a commit to dabiih/graphhopper that referenced this pull request Jan 7, 2025
dabiih pushed a commit to dabiih/graphhopper that referenced this pull request Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants