Skip to content

Eulerian cycles/trails for undirected graphs #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 27, 2023
Merged

Conversation

thchr
Copy link
Contributor

@thchr thchr commented Mar 7, 2023

The implementation is mostly adapted from SimpleGraphs.jl.

Tagging @etiennedeg who pointed out the lack of tooling for Eulerian tours/cycles as well as the implementation in SimpleGraphs.jl.

I didn't add similar functionality for directed graphs: that could be a follow up for anyone needing it.

@thchr thchr changed the title Eulerian cycles/tours for undirected graphs Eulerian cycles/trails for undirected graphs Mar 15, 2023
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Merging #232 (322bed2) into master (d29e1f2) will increase coverage by 0.11%.
The diff coverage is 96.15%.

@@            Coverage Diff             @@
##           master     #232      +/-   ##
==========================================
+ Coverage   97.19%   97.30%   +0.11%     
==========================================
  Files         114      115       +1     
  Lines        6658     6709      +51     
==========================================
+ Hits         6471     6528      +57     
+ Misses        187      181       -6     

@gdalle gdalle added the enhancement New feature or request label Jun 16, 2023
@thchr
Copy link
Contributor Author

thchr commented Jun 28, 2023

Gentle bump: this should be good to go (new commit today: I had forgotten to include the new tests in test/runtests.jl, hence the poor coverage above; fixed now).

@gdalle
Copy link
Member

gdalle commented Jun 28, 2023

I just gave approval to run the tests, if they pass I'll review, if not I will haunt your nightmares forever

@gdalle
Copy link
Member

gdalle commented Jun 28, 2023

WELL WELL

@gdalle
Copy link
Member

gdalle commented Jun 29, 2023

I think it's a matter of dealing with exceptions in a 1.6-compatible manner

@thchr
Copy link
Contributor Author

thchr commented Jun 29, 2023

Yeah, I will push a fix later today 👍

@thchr
Copy link
Contributor Author

thchr commented Jun 29, 2023

Okay, should be fixed now 👍 !

@gdalle
Copy link
Member

gdalle commented Jun 29, 2023

Okay, should be fixed now 👍 !

Oh really?

@thchr
Copy link
Contributor Author

thchr commented Jun 29, 2023

Okay, should be fixed now 👍 !

Oh really?

😭
Should be now though, for real this time, again...

@gdalle
Copy link
Member

gdalle commented Jun 29, 2023

I do love a good old running gag

@gdalle
Copy link
Member

gdalle commented Jun 30, 2023

Do you need a hand?

@thchr
Copy link
Contributor Author

thchr commented Jun 30, 2023

My god; somehow I didn't commit or push the fix yesterday... The pain :(

@gdalle
Copy link
Member

gdalle commented Jun 30, 2023

The suspense is at its highest

@thchr
Copy link
Contributor Author

thchr commented Jul 2, 2023

Remaining failures on v1 and nightly appear to just be spurious Missing-issues from JET, i.e., unimportant cf. #271.

@gdalle
Copy link
Member

gdalle commented Jul 2, 2023

#271 has been merged, so you can probably merge master into this branch and the errors will be fixed

@thchr
Copy link
Contributor Author

thchr commented Jul 2, 2023

#271 has been merged, so you can probably merge master into this branch and the errors will be fixed

Oki, done 👍

@gdalle
Copy link
Member

gdalle commented Jul 5, 2023

Oh my, look at that! The sweet sweet perfume of passing tests

@gdalle gdalle self-assigned this Jul 5, 2023
Copy link
Member

@gdalle gdalle left a comment

Choose a reason for hiding this comment

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

Nice contribution! A few remarks but overall good job and solid test suite

@thchr
Copy link
Contributor Author

thchr commented Jul 7, 2023

Thanks for review @gdalle - latest version should address all issues, I believe.
For once, I also tested locally and things pass there - so the CI suspense should be slightly lower than previously :)

@thchr thchr requested a review from gdalle July 24, 2023 20:44
gdalle
gdalle previously requested changes Jul 26, 2023
error("unreachable reached")
end

@inline function _excludes_edge(u, w, e::AbstractEdge)
Copy link
Member

Choose a reason for hiding this comment

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

I think this belongs in the core utilities somewhere


Returns a [Eulerian trail or cycle](https://en.wikipedia.org/wiki/Eulerian_path) through an
undirected graph `g`, starting at vertex `u`, returning a vector listing the vertices of `g`
in the order that they are traversed. If no such trail or cycle exists, throws an error.
Copy link
Member

Choose a reason for hiding this comment

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

How do I know whether the result will be a trail or a cycle? What does it depend on?

Copy link
Member

Choose a reason for hiding this comment

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

Only on the degree of the starting vertex?

error("graph is not connected: a eulerian cycle/trail does not exist")
else
# otherwise, pick whichever neighbor is not a bridge/cut-edge
bs = bridges(g)
Copy link
Member

Choose a reason for hiding this comment

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

Add a TODO here for complexity

@gdalle
Copy link
Member

gdalle commented Jul 27, 2023

Actually, you know what? This is plenty good enough to merge.

@gdalle gdalle dismissed their stale review July 27, 2023 16:41

Stale

@gdalle gdalle merged commit 1cb789d into JuliaGraphs:master Jul 27, 2023
Comment on lines +39 to +41
function GenericGraph(elist::Vector{Graphs.SimpleGraphEdge{T}}) where {T<:Integer}
GenericGraph{T}(SimpleGraph(elist))
end
Copy link
Member

Choose a reason for hiding this comment

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

@thchr I spotted this too late - I think we should not implement any method (this includes constructors) that specialize on a GenericGraph or GenericDiGraph. The reason is, that we want to use GenericGraph as a placeholder for an arbitrary AbstractGraph to verify functions that take an AbstractGraph work correctly.

Copy link
Member

Choose a reason for hiding this comment

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

wdym by specialize on a GenericGraph?

Copy link
Member

Choose a reason for hiding this comment

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

do you want to revert that part?

Copy link
Member

@simonschoelly simonschoelly Jul 27, 2023

Choose a reason for hiding this comment

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

I mean the issue I see here is, if someone writes a function like

function f(g::AbstractGraph)
    T = typeof(g)
    return T([Edge(1, 2)])
end

then this function might fail for an arbitrary AbstractGraph but not for a GenericGraph. I don't think it will break anything soon though, so there is no rush, but I can make a PR that works around that.

I would propose, if we need a workaround for constructors so that it will be easier to write tests, we just implement the functions generic_graph and generic_digraph - maybe I already did such a thing in one of my PRs but I don't remember exactly.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me :)

@thchr thchr deleted the euler branch July 28, 2023 08:12
@simonschoelly simonschoelly mentioned this pull request Sep 20, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants