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
Determine if an edge in a graph is a cut-edge (bridge) #13242
Comments
comment:1
I looked for cut-edge/bridge/isthmus in Sage and in trac tickets, but didn't find anything. Let me know if you see anything though! |
comment:2
Apply only trac_13242.patch |
comment:5
Since this function is working for undirected graphs only, it should not be in generic_graph.py. The following function should be way faster and avoids a copy of the graph.
|
Reviewer: David Coudert |
comment:6
Above code should be improved to cope with multiple edges. |
comment:7
Thanks, I will move this to graph.py if that is the correct place? I tried this code for K_3 with a leaf (G = Graph([[0,1],[0,2],[1,2],[0,3]]) ) and if I ask if the leaf is a cut-edge it returns False, but it should be True. I haven't been able to figure out why this isn't working - any ideas? It seems to work with the slower code. |
comment:8
Replying to @sagetrac-lkeough:
Well, you can let it in generic_graph since it has also some interest for connectivity in digraphs.
My fault (last test in the return).
Last, I don't know if the function should be named is_edge_cut or is_cut_edge |
comment:9
Replying to @dcoudert:
Sounds good, I do believe your code works on digraphs as well.
Thanks! I'm new to Sage developing so this might take me a bit, but I'll work on it today.
I've always referred to this as either cut-edge or bridge (and it seems Wikipedia does too, for what that is worth). |
comment:11
I believe it should be called is_cut_edge, as "edge cut" means a set of edges whose deletion disconnects the graph. |
comment:12
Install OK, long tests OK, functionality OK. However I'm unable to test docbuild (working remote today), and I saw a small alignment problem line 4024. Also, I'm not sure of the behavior of 'EXAMPLES' versus 'TESTS'. Are examples also considered as tests for 'sage -t'? Is anyone able to answer? |
This comment has been minimized.
This comment has been minimized.
comment:13
Replying to @dcoudert:
I tested docbuild and it looks fine. Is your issue at 4024 that """ should be 4 spaces back. I fixed that and uploaded again.
I'm at Sage Days 40 and was told that examples are tested, but are different from tests in that they show up if the user asks for documentation. |
comment:14
For me the patch is now OK so I give positive review. Enjoy the Sage Days. |
comment:15
Hello, I had some discussions with Nathann, and he said that the following should be faster:
I tried it on large graphs and it is definitively faster (10x to 100x). It is in fact the same algorithm behind, but the distance function is in cython, so it's fast. Sorry for the extra work, but it would be better to replace the lines from # We search for a path from till the end with above code. |
comment:16
Faster is certainly better so I don't mind. When I replace this and run the tests it fails the very first example - if an edge in K_4 is a cut edge. I messed around in the Sage notebook and it also seems to be a problem there. The algorithm is correct so I'm probably just implementing this wrong. All I did was replace the lines after #We search for a path.. |
comment:17
Replying to @sagetrac-lkeough:
I see now..we want return not ans. Because if self.distance(u,v) < self.order() then (u,v) is not a cut-edge. |
comment:18
This no longer works for digraphs. It returns that an edge in a directed cycle is a cut edge because if we remove that edge there is no directed path between those two vertices. There is a connected_components_number function for digraphs, but comparing connected_components_number(G) and connected_components_number(G-e) is probably not the fastest way to make it work for digraphs. |
comment:19
Another option is:
the self.is_connected() function would be sufficient, but the distance function is faster for undirected graphs. Don't forget to explain the behavior for directed graphs in the description of the function. |
comment:20
I need connected_components_number since an edge is a cut-edge if it increases the number of connected components. So you may be trying to figure out if an edge in an already disconnected graph is a cut edge. I used this:
I ran tests and built the documentation and it looks fine. I'm going to upload a new patch, but I'm willing to change it if this is a terrible algorithm. |
comment:21
Apparently you did something wrong when updating the patch. It contains only parts of the function (last modifications). Your proposition for directed graphs can be improved because you don't need to copy the graph. It is sufficient to remove edge (u,v), and to later restore it. For instance, you can do:
In fact, the connected_components_number function uses the connected_component_containing_vertex function. So it is easier that way. |
Use this one. |
comment:22
Attachment: trac_13242.patch.gz I think I fixed the patch updating problem and used your code for the directed graph. |
Attachment: trac_13242-rev.patch.gz |
This comment has been minimized.
This comment has been minimized.
comment:23
I did some minor edit (removal of useless spaces, alignments, etc.) in the complementary patch trac_13242-rev.patch (you have to apply both files). If it is OK for you, I will give a positive review to this patch. For me everything is fine (install, tests, docbuild, functionality, etc.). |
comment:25
All these things worked for me as well. Thanks for all of your help! |
comment:27
attachment: trac_13242.patch needs a proper commit message. |
This comment has been minimized.
This comment has been minimized.
comment:28
Attachment: 13242_cutedge.patch.gz Fixed myself (and put both patches together). |
comment:29
Sorry, had been away from a computer for a few days. Thank you for fixing this! |
Merged: sage-5.3.beta1 |
is_cut_edge is needed to compute the Tutte polynomial (#1314)
APPLY:
CC: @sagetrac-jeremy-l-martin @nathanncohen @dcoudert
Component: graph theory
Keywords: days40
Author: Jeremy Martin, Lauren Keough
Reviewer: David Coudert
Merged: sage-5.3.beta1
Issue created by migration from https://trac.sagemath.org/ticket/13242
The text was updated successfully, but these errors were encountered: