News for hackers. Stuff that matters.
Re:Possibly all the ways to get loop-finding in graphs wrong by vouwfietsman on Wednesday September 11, 2024 @12:36PM (#41512980)
Funny I've had to do this occasionally and I always do the following: for each edge E, attempt to construct a clockwise loop from that edge by traversing each vertex and picking the edge that is "most clockwise" compared to the incoming edge. Converse for counter clockwise. This gives you, for each edge, the two loops the edge is a part of (if they exist).

It sounds horribly slow, but isn't because the loop finding process for one edge can mark all edges it traverses as either being on the same loop, or not having a loop, for the orientation its checking. These edges can be skipped henceforth.

This does not find all loops, only the smallest disjoint loops (as every edge is at most part of two disjoint loops). But basically results in a similar planar "face" partition the author describes.

Its not clear to me whether my approach does not work (perhaps the angle compares fail on a torus? I've never had to deal with torii), or simply isn't suited because it misses some loops, but I thought I'd share it anyway :-)

Re:Possibly all the ways to get loop-finding in graphs wrong by cvoss on Wednesday September 11, 2024 @12:58PM (#41513207)
Notwithstanding the limitation of assuming the graph is embedded in a coordinate space where you can try to measure angles, I think this algorithm still doesn't work.

I may be missing a detail, but it seems to fail on a graph consisting of a loop with some extra edges branching off the loop toward its interior and some edges branching off toward the exterior. The left hand walk hits a dead end in one branch, and the right hand walk dead ends in the other, no matter where on the loop you start (except for some special cases).

Edit: strengthening the proposed counterexample

Re:Possibly all the ways to get loop-finding in graphs wrong by vouwfietsman on Wednesday September 11, 2024 @01:07PM (#41513317)
Hmm I'm having a hard time visualizing your counter example, I'll try to think of it some more. An important detail I left out though is that in my problem sets edges do not cross, which I suppose simplifies the entire problem a lot :-)
Re:Possibly all the ways to get loop-finding in graphs wrong by mrgoldenbrown on Wednesday September 11, 2024 @02:42PM (#41514124)
I think you are trying to say your method only works if the graph is "planar", ie it can be drawn on a flat piece of paper with no lines crossing.
Re:Possibly all the ways to get loop-finding in graphs wrong by vouwfietsman on Wednesday September 11, 2024 @03:03PM (#41514333)
Indeed, thanks for the clarification!
Re:Possibly all the ways to get loop-finding in graphs wrong by eigenket on Wednesday September 11, 2024 @05:28PM (#41515497)
If I understand your algorithm correctly I think it fails on this graph (drawn on my phone, using an online implementation of Paint).

https://imgur.com/a/ihPrwrX

I think this is roughly the counterexample the person above was suggesting.

Re:Possibly all the ways to get loop-finding in graphs wrong by vouwfietsman on Thursday September 12, 2024 @03:05AM (#41518272)
Aha! Yes to fix these cases a bit of bookkeeping is needed: a protruding edge like that would force the "walking" to back up, because its a dead end indeed. However, it also immediately means such an edge is not part of any loops, can be marked as such, and ignored upon retracing the steps.

It's an edge case that should be handled, but does not prevent the general algo from working.

Re:Possibly all the ways to get loop-finding in graphs wrong by eigenket on Thursday September 12, 2024 @07:18AM (#41519542)
Ah yeah, if you're not trying to identify all loops but just check if some loops exist then that works. I think you can dispense with the "walking around taking clockwise/anticlockwise edges" part though. If you repeatedly do the "remove all nodes with only 1 edge going to them" step then you've already identified whether or not at least one loop exists.
Re:Possibly all the ways to get loop-finding in graphs wrong by vouwfietsman on Friday September 13, 2024 @01:57AM (#41528365)
Repeatedly removing those edges would help indeed! I am interested in finding the loops, but in the example provided the "dead end" edges do not contribute to the loop. Officially a loop is not allowed to contain the same vertex twice (besides start/end), otherwise any sequence of vertices could be considered a loop just by repeating them in reverse order.

However, indeed it remains true that it does not find all loops, only the smallest set of loops that cover all edges.

Re:Possibly all the ways to get loop-finding in graphs wrong by konstantinua00 on Wednesday September 11, 2024 @03:10PM (#41514415)
how is it different from the "sidewalk" algo in the article?

you'd get the same pitfall of torus topology with 2 perpendicular loops