Skip to content

Adds AbstractBidirAlgo#calcPath with restricted source/target edges. - #1665

Merged
easbar merged 12 commits into
masterfrom
issue_1647_restricted_edges
Aug 19, 2019
Merged

easbar merged 12 commits into
masterfrom
issue_1647_restricted_edges

Conversation

@easbar

@easbar easbar commented Jul 16, 2019 •

Copy link
Copy Markdown
Member

For #1647 I have added a new calcPath method to AbstractBidirAlgo that, additionally to the from/to node ids, also takes two edge ids that are enforced as start/target edges. This allows to strictly enforce the first and last edge of a path.

For now this is only supported on the low-level java API level and how to obtain the edge ids for the edges one wants to restrict is another question (?).

* @param toInEdge the edge id of the last edge of the path. using {@link EdgeIterator.ANY_EDGE} means
* not enforcing the last edge of the path
*/
public Path calcPath(int from, int to, int fromOutEdge, int toInEdge) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In principle we could also move this to the RoutingAlgorithm, but for now it was easier to implement this only for bidirectional algorithms. Not sure if we really need this for the others as well and we can add this later if needed (?)

/**
* integer value used to indicate that any edge is accepted
*/
int ANY_EDGE = Integer.MIN_VALUE;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

what is a bit ugly here is that EdgeIterator.Edge.isValid only checks if an edge id is positive or not. this does not allow us to have other special values like this one here. maybe we should make isValid check if ==-1 ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, this is a good idea. Additionally we should have a look if we use ==-1 instead of isValid call. Have created #1666

{Algo.CH_ASTAR, Double.POSITIVE_INFINITY, true, false},
{Algo.CH_DIJKSTRA, Double.POSITIVE_INFINITY, true, false},
// todo: yields warnings and fails
// {Algo.LM, Double.POSITIVE_INFINITY, false, true}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

With landmarks the test fails sometimes, maybe its the same problem as in #1557 ? Or maybe I am using bad settings (there were also some warnings about some weights being maxed out)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is ugly. Wasn't #1557 only for shortest weighting and shouldn't happen here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, I might need your help here. I guess the test for LM fails because I am getting these warnings:

com.graphhopper.routing.lm.LandmarkStorage - landmark 1 (49.40121656807996,9.705012881122817): too many delta weights were maxed out (17/82). Factor is too small 0.003551062425503072. To fix this increase maximum in config.yml: prepare.lm.weighting: fastest|maximum=363.056352875689

I tried setting the maximum weight with LandmarkStorage#setMaximumWeight and also setting it to -1 (automatic determination of maximum weight), but the warnings remain. I do not really understand what the problem is here. The random graph is created within a rather small bounding box (just the size of a village): http://tools.geofabrik.de/calc/#type=geofabrik_standard&bbox=9.7,49.41,9.71,49.4&tab=1&proj=EPSG:4326&places=2
and I checked that the edge distances are all something like 100-1000m. The speeds used are all between 10 and 120 so there should not be any unusual values for the weights (I checked and they are all somewhere between 60 and 420 (one to seven minutes).
However the fromWeight here:

int fromWeight = getFromWeight(lmIdx, nodeId);
seems to be really large (something like 30-80k, so several hours up to a full day) and because of this the delta in the same method is often below DELTA_MIN, which eventually leads to the warnings I mentioned above.

What I do not understand is how fromWeight can get so large ? I would expect in such a small area no matter where the landmarks are the weights should be much smaller ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, will investigate! This sounds like a bug in LM code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmmh, there are a few confusing things in the code like 16 bits for the precision although we should have 18 for the "from" and 13 for the "delta", plus old comments making it hard to "re-understand" this. It will take me a bit more time before I can understand this problem here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, thanks for taking a look! Maybe we can leave this test commented out for this PR ? The problem seems to be unrelated to the source/target edge restrictions that are new here ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will let you know when I know if it is indeed unrelated. (But maybe it is related as the preparation and also parts of the algo are node based)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried looking into this a bit and found failing cases also without the new feature discussed here (and also for node-based routing). See #1687

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot!!

@easbar easbar mentioned this pull request Aug 18, 2019
2 tasks
}

protected void postInitFrom() {
// using a local reference is important to prevent stack overflow after calling setEdgeFilter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the problem here exactly? Is it due to the not fully initialized AbstractBidirAlgo constructor?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, no. It seems we use additionalEdgeFilter inside the method. Wouldn't it then be safer to handle this inside the method especially since it is protected?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, I would say fillEdgesFrom/ToUsingFilter is 'sane': It sets additionalEdgeFilter to some other filter, calls fillEdges and sets additionalEdgeFilter back to the value it had before calling the method. So I do not think there is anything we can handle here ? The one thing that we must not do is using the additionalEdgeFilter reference directly in the edgeFilter object we pass into the method (because it will be modified itself). I tried making this a bit clearer in the code now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And should we throw an illegal arg exc if edgeFilter==additionalEdgeFilter?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, passing edgeFilter==additionalEdgeFilter is ok (we even do this here), the only thing that is not ok is passing a new edge filter that uses additionalEdgeFilter directly.

// todo:
// e.g. block area is implemented using infinite weighting
// when an edge filter is used need to think about what should happen if the filter filters out the
// given in out edges etc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting and yes, if we do a block area and restrict the edge (with infinite weight) then we should get "connection not found".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, this is already covered. I added a test for this and removed the todo.

@karussell karussell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@easbar
easbar merged commit 90d2e8f into master Aug 19, 2019
@easbar
easbar deleted the issue_1647_restricted_edges branch August 26, 2019 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants