Skip to content

Refactor unfavoring of virtual edges (#885) - #909

Merged
boldtrn merged 3 commits into
graphhopper:masterfrom
stefanholder:issue_885
Dec 16, 2016
Merged

boldtrn merged 3 commits into
graphhopper:masterfrom
stefanholder:issue_885

Conversation

@stefanholder

@stefanholder stefanholder commented Dec 13, 2016 •

Copy link
Copy Markdown
Contributor

This addresses issue #885.

Also needed for graphhopper/map-matching#70

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The intention was to make the semantics of enforceHeadingByEdgeId more clear by renaming this method to unfavorVirtualEdgePair.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed bug.

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.

Do you have a test case showing this bug?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The bug was that multiple invocations of enforceHeadingByEdgeId added more and more edges to modifiedEdges. clearUnfavoredStatus() would then go over all previous edges again although their unfavored status had already been cleared.

However, this bug was not observable before because modifiedEdges could not be accessed from outside this class.

@stefanholder stefanholder Dec 13, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Can we reduce this to List<EdgeIteratorState> or is the implementation necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The implementation class should not be necessary for graphhopper/map-matching#70.

One thing I didn't like about VirtualEdgeIteratorState is that detach() is not supported. If we return List<VirtualEdgeIteratorState> here, the user can at least figure out if it is supported. (Unfortunately, he would have to figure this out from the code since it is not explained in the javadoc.)

@karussell karussell Dec 14, 2016 •

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.

Then I think we should still use EdgeIteratorState and if people need detach we have to implement this :) (in another issue). The less stuff is public the better for refactoring later on.

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

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.

Do you have a test case showing this bug?

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.

Can we reduce this to List<EdgeIteratorState> or is the implementation necessary?

@karussell karussell added this to the 0.9 milestone Dec 13, 2016

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

Nice PR @stefanholder. Would you mind adding a Testcase that shows the issue described in #885 and that it is solved by your PR?

@stefanholder

Copy link
Copy Markdown
Contributor Author

Can we reduce this to List<EdgeIteratorState>?

Done.

Would you mind adding a Testcase that shows the issue described in #885 and that it is solved by your PR?

Done.

private List<VirtualEdgeIteratorState> modifiedEdges = new ArrayList<VirtualEdgeIteratorState>(5);

// Use LinkedHashSet for predictable iteration order.
private final Set<VirtualEdgeIteratorState> unfavoredEdges = new LinkedHashSet<>(5);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now using Set instead of List to store unfavoredEdges.

@karussell

Copy link
Copy Markdown
Member

@boldtrn please confirm & merge (as here just one author it is safe to 'squash and merge')
@kodonnell can we close #885 then?

@stefanholder

Copy link
Copy Markdown
Contributor Author

@boldtrn please confirm & merge (as here just one author it is safe to 'squash and merge')

If both commits are squashed then the test case showing the issue described in #885 is lost.

@karussell

Copy link
Copy Markdown
Member

Hmmh, why isn't it added to the latest commit?

@stefanholder

stefanholder commented Dec 15, 2016 •

Copy link
Copy Markdown
Contributor Author

Hmmh, why isn't it added to the latest commit?

Simply speaking, because adding something and deleting the same in a single commit results in no change. The test cases of the first commit test enforceHeadingByEdgeId as it is described in the original javadoc of this method and hence reveal the problems with this method. The second commit changes the contract of the method and the unit tests to match its behavior.

@karussell

Copy link
Copy Markdown
Member

Ok, then you mean 'lost' in the sense for historical reasons. Makes sense. @boldtrn

@kodonnell

Copy link
Copy Markdown
Contributor

@kodonnell can we close #885 then?

Sure. Happy for you to close it when merged, or I can.

VirtualEdgeIteratorState incomingEdgeReverse = (VirtualEdgeIteratorState) queryGraph.getEdgeIteratorState(1, incomingEdge.getBaseNode());
boolean expect = true; // expect incoming edge to be avoided
assertEquals(expect, incomingEdge.getBool(EdgeIteratorState.K_UNFAVORED_EDGE, !expect));
expect = false; // expect reverse incoming edge not to be avoided

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.

Why not remove expect = false. That way it would fail before your PR => Showing the issue. Then you add your PR and therefore fix the failing test case. The order is not important at this point :).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, it only fails with expect = false, which shows the issue. However, this test becomes obsolete with this PR, see above.

@boldtrn

boldtrn commented Dec 16, 2016

Copy link
Copy Markdown
Member

@stefanholder Thanks for adding a test.

If both commits are squashed then the test case showing the issue described in #885 is lost.

The reason why I asked you to add a test was to document the issue and make sure that we don't add a similar issue by mistake in the future. See my comment. But maybe I am overthinking this issue? I will approve my review, that's probably somethin @karussell has to decide.

@stefanholder

Copy link
Copy Markdown
Contributor Author

as here just one author it is safe to 'squash and merge'

@karussell, squashing a PR via the github UI always changes the author to the person that does the squash merging. I just verified this with a test squash. The reason behind this is that github uses the git merge --squash to create the squashed changes and then commits them under the maintainer's name. (See also graphhopper/map-matching#83 for the previous discussion on this topic.)

Note that it's possible to disable squash merging in the github repository options. Squashing without changing authorship can be done manually using git rebase -i.

@boldtrn
boldtrn merged commit ab8cdeb into graphhopper:master Dec 16, 2016
@boldtrn

boldtrn commented Dec 16, 2016 •

Copy link
Copy Markdown
Member

Merged, thanks @stefanholder.

@boldtrn please confirm & merge (as here just one author it is safe to 'squash and merge')

Sorry, I think I was over complicating things with this test. I was hoping to write a test that shows #885, but since we changed the API of the method, this is not possible.

@karussell

Copy link
Copy Markdown
Member

@karussell, squashing a PR via the github UI always changes the author to the person that does the squash merging. I just verified this with a test squash

The author will be still the original author (see 'git log'), still github will show the one who merged it.

@karussell

Copy link
Copy Markdown
Member

Note that it's possible to disable squash merging in the github repository options.

Sure, still this is useful e.g. if the pull requester does not know about this and the PR contains several intermediate commits.

For the future I would suggest the following (where we can disable squashing): we merge the PR even if some commits are 'superfluous' but ask the contributor to squash as much as possible.

WDYT?

Squashing without changing authorship can be done manually using git rebase -i.

From my experiences with github this has the same effect to the author entry as doing the squash in the UI

@devemux86

devemux86 commented Dec 17, 2016 •

Copy link
Copy Markdown
Contributor

The author will be still the original author (see 'git log'), still github will show the one who merged it.

Doesn't GitHub show both?
Commits history has the author's picture (with commiter's smaller picture).
And the commits mention "<author> commited with <committer>".

@karussell

Copy link
Copy Markdown
Member

Doesn't GitHub show both?

That was what I meant. In the git log you only see the original author.

@boldtrn

boldtrn commented Dec 17, 2016

Copy link
Copy Markdown
Member

@stefanholder I hope it was ok that I squashed the PR? Do you think we should add the test in the commit history?

@stefanholder

Copy link
Copy Markdown
Contributor Author

@stefanholder I hope it was ok that I squashed the PR? Do you think we should add the test in the commit history?

Yes, it's OK. I think it would have been better to merge both commits so that the failing test would still be in the git history but this is a minor thing.

@stefanholder

Copy link
Copy Markdown
Contributor Author

For the future I would suggest the following (where we can disable squashing): we merge the PR even if some commits are 'superfluous' but ask the contributor to squash as much as possible.

In general I think this is a good idea but some contributors might not be familiar with squashing via git rebase -i and then doing a forced push. However, it's not that hard and we could provide a guideline how to publish a good contribution.

Doesn't GitHub show both?
Commits history has the author's picture (with commiter's smaller picture).
And the commits mention " commited with ".

Not for squashed merges via the github UI. I just tested this with a fork of https://github.com/graphhopper/jsprit. After a squashed merge of the last two commits github changes the author to me and sets [email protected] as the committer (I used git log --pretty=full).
2

1

I guess that github sets the person as the author who created the pull request. This would explain why @karussell was set as the committer for graphhopper/map-matching#49.

When I did a rebase merging of the last two commits with github UI, the author stayed the same but the committer was changed to the person doing the rebase merging:

4

3

This also happens when manually merging a commit of somebody else into another branch.

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.

5 participants