Skip to content

Fixes some issues with turn cost times. - #1586

Merged
easbar merged 6 commits into
masterfrom
time_problems
Apr 1, 2019
Merged

easbar merged 6 commits into
masterfrom
time_problems

Conversation

@easbar

@easbar easbar commented Mar 29, 2019 •

Copy link
Copy Markdown
Member

Fixes two of the three issues mentioned in #1585.

Added some tests and did some cleanup in some tests, but the actual fixes are one-liners.

reverseOrder();
currEdge = edgeTo;
int prevEdge = nextEdgeValid ? sptEntry.edge : EdgeIterator.NO_EDGE;
int prevEdge = EdgeIterator.Edge.isValid(sptEntry.edge) ? sptEntry.edge : EdgeIterator.NO_EDGE;

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.

This fixes the turn cost time evaluation at the meeting node

turnCostsInSeconds = (long) calcTurnWeight(prevOrNextEdgeId, edgeState.getBaseNode(), edgeState.getEdge());

return millis + turnCostsInMillis;
return millis + 1000 * turnCostsInSeconds;

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.

Here we have to convert the turn costs to milliseconds to make the turn cost time calculation consistent with the weight calculation.

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.

Maybe we should decide before going more public with turn costs to make a breaking change and use the same unit for turn costs? I think I stumbled over the same problem somewhere.

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.

You mean store the turn costs as milliseconds ? In this PR or is this just a reminder for later ? Storing turn costs as milliseconds seems a bit extreme, seconds should be enough ? Maybe use 0.1 seconds ?

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.

You mean store the turn costs as milliseconds ?

I would keep storing them as seconds (and later use the same EncodedValue classes to define a different precision), but shouldn't we use the same unit ms in the Java API turnCostEncoder.getTurnCost? Furthermore to make it more clear maybe we should rename calcTurnWeight into calcTurnCost? Or even introduce a separate method calcTurnMillis like we have for normal weighting ... but are there really cases where a priority to avoid a turn is different to the turn time?

In this PR or is this just a reminder for later?

Good question - probably later :)

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.

but shouldn't we use the same unit ms in the Java API turnCostEncoder.getTurnCost

The way I understood it so far is that the turn costs do not necessarily have to be turn times, maybe someone is using an advanced weighting and drivers just do not want to take turns so each turn adds some penalty (but not necessarily time) to some advanced weight function ?

Furthermore to make it more clear maybe we should rename calcTurnWeight into calcTurnCost?

Hmm yeah makes sense because we call it turn cost everywhere else, then again calcTurnWeight fits calcWeight in the TurnWeighting class.. no idea.

but are there really cases where a priority to avoid a turn is different to the turn time

Hmm I could imagine this, but don't know if anybody does this :)

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.

Hmm I could imagine this, but don't know if anybody does this :)

But which use case do you have in mind where "time != weight"?

The only thing that comes to my mind is an efficient storage. E.g. only two bits are stored and the 0 maps to no turn time, the 1 maps to 5 seconds, the 2 maps to 10 seconds and the 3 maps to infinity (turn restriction). But once we would introduce something like the MappedDecimalEncodedValue I do not see a reason to use the same ms as unit.

Maybe there are already users of this more generic turn cost feature, but if we document this change this is no problem IMO. And we should not hesitate to make this API more consistent before it is used more widespread.

BTW: As the defaultUTurnCost is in seconds - is this correct?

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.

see #1590

TurnWeighting turnWeighting = new TurnWeighting(new ShortestWeighting(encoder), turnCostExt);
// todo: for the shortest weighting turn costs cannot be interpreted as seconds ? at least when they are added
// to the weight ? how much should they contribute ?
// assertEquals(105, turnWeighting.calcWeight(edge, false, 0), 1.e-6);

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.

Any thoughts 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.

What do you think about deprecating shortest weighting in general? It does not make sense in practise. Most people say they need "shortest" for car (hear this often for taxis as they calculate the cost based on the distance), but what they really mean is a "fastest" cost calculation with a tight distance weight.

@easbar easbar Mar 31, 2019 •

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 I see. But not sure if it should be really deprecated, because someone might find it still useful. We could emphasize somewhere that the ShortestFastestWeighting is typically what most people are looking for. Anyway the question how turn costs should contribute to weightings that are not purely based on time remains also for the ShortestFastestWeighting. In ShortestFastestWeighting this relation is controlled by the time/distanceFactors.

@karussell karussell Mar 31, 2019 •

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.

For now IMO the turn costs for ShortestWeighting must be 0 as there are no ways to introduce a timely slow down or priority stuff.

In ShortestFastestWeighting the turn cost adds to the time (and gets multiplied by the timeFactor)?

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, I agree as long as we do not allow giving less priority to routes with many turns etc. the shortest weighting should pay attention to turn restrictions, but the turn costs (assuming they are turn times) should not be included. However to make this work we would in fact have to do this:

Or even introduce a separate method calcTurnMillis like we have for normal weighting ... but are there really cases where a priority to avoid a turn is different to the turn time?

because right now the TurnWeighting simply adds the turn costs without knowing what it's underlying Weighting is.

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, indeed. This is ugly and one reason more (for me) to remove ShortestWeighting :D

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.

see #1590

@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.

Thanks for this PR - impressive how small the actual changes are 👍

@karussell karussell added the bug label Mar 30, 2019
@karussell karussell added this to the 0.13 milestone Mar 30, 2019
@easbar

easbar commented Apr 1, 2019

Copy link
Copy Markdown
Member Author

Will merge this and open separate issue for the turn cost issues discussed here.

@easbar
easbar merged commit ff5590c into master Apr 1, 2019
@karussell
karussell deleted the time_problems branch April 1, 2019 08:40
@easbar easbar mentioned this pull request Apr 1, 2019
4 tasks done
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