Skip to content

Remove acceptWay optimization - #2471

Merged
easbar merged 11 commits into
masterfrom
accept_way_optimization
Nov 28, 2021
Merged

easbar merged 11 commits into
masterfrom
accept_way_optimization

Conversation

@easbar

@easbar easbar commented Nov 19, 2021

Copy link
Copy Markdown
Member

Fixes #2462

@easbar easbar added this to the 5.0 milestone Nov 19, 2021

@easbar easbar left a comment

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 was pretty straight-forward with the exception of a few tests that test the priority calculation under the assumption that there is access for ways that do not have access, something that never happens in the production code currently. However, in the future this is what we actually might do: Calculate priorities regardless of the access flags as the access flags might change depending on the custom model.

Comment on lines 580 to 584
// important: UNCHANGED should not get 0 priority!
osmWay = new ReaderWay(1);
osmWay.setTag("highway", "somethingelse");
flags = encodingManager.handleWayTags(osmWay, accessMap, encodingManager.createRelationFlags());
osmWay.setTag("highway", "track");
flags = encodingManager.handleWayTags(osmWay, encodingManager.createRelationFlags());
assertEquals(PriorityCode.getValue(UNCHANGED.getValue()), priorityEnc.getDecimal(false, flags), .1);

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.

@karussell do you remember what this comment

// important: UNCHANGED should not get 0 priority!

is supposed to say? The issue with this test is that previously we called AbstractFlagEncoder#getAccess before handleWayTags and passed the AcceptWay into handleWayTags. This allowed us in this test to pass Access=WAY and test the priority even for ways that aren't even accessible. This is why the test used to work even for highway=somethingelse. I now changed it to track because then we also get priority==UNCHANGED. But I don't understand why the comment says the priority should not be 0, but then we do not even test whether the priority is not 0...

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.

I think I meant that the default value is 0. And the default meaning should be "unchanged priority" but we do not have an option for this (anymore) and we need to set this UNCHANGED explicitly. But not sure.

Should we ensure that priority is UNCHANGED for unknown highway values (?)

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 think I meant that the default value is 0.

Ok, this makes sense. It does get the default value 0 as long as the access is false though.

Should we ensure that priority is UNCHANGED for unknown highway values (?)

Probably, but maybe this is not needed yet (at least for this PR), because for unknown highway values the access will be false anyway. The test only works in master because we pass Access.WAY even though in reality it would be CAN_SKIP.

Comment on lines -637 to +625
EncodingManager.AcceptWay map = new EncodingManager.AcceptWay();
assertTrue(em.acceptWay(way, map));
IntsRef edgeFlags = em.handleWayTags(way, map, em.createRelationFlags());
assertEquals(EncodingManager.Access.CAN_SKIP, encoder.getAccess(way));
assertNotEquals(EncodingManager.Access.CAN_SKIP, ((AbstractFlagEncoder) em.getEncoder("bike")).getAccess(way));
IntsRef edgeFlags = em.handleWayTags(way, em.createRelationFlags());

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.

Not sure why we use a bike encoder for this car encoder test, but I just kept the logic the same.

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.

Likely because initially there were a couple of bit handling bugs in EncodingManager (and/or EncodedValue) when using multiple flag encoders like overlapping ranges or similar and we needed the test against that somewhere I guess but yes those tests do not belong 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, I'll leave it as it is then

Comment on lines +211 to +219
public void testPriority_avoidanceOfHighMaxSpeed() {
// here we test the priority that would be calculated if the way was accessible (even when it is not)
// therefore we need a modified encoder that always yields access=WAY
BikeCommonFlagEncoder encoder = new RacingBikeFlagEncoder(new PMap("block_fords=true")) {
@Override
public EncodingManager.Access getAccess(ReaderWay way) {
return WAY;
}
};

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 is the same problem I described in the other comment: We used to be able to test the priority by ignoring access by just passing in Access.WAY. Since this is no longer possible I worked around this by using a modified encoder here. The much better approach would of course be testing the priority calculation in isolation, but this is not possible yet, because handleWayTags does a bit of everything.

@easbar easbar mentioned this pull request Nov 20, 2021
@easbar
easbar merged commit d0bf465 into master Nov 28, 2021
@easbar
easbar deleted the accept_way_optimization branch November 28, 2021 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove acceptWay optimization

2 participants