-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Improve add_edge in BipartiteGraph to make it independent from the current coloring #8744
Comments
comment:6
I just tested this out using the example in the description. It worked without any error message. So it's safe to say this has been fixed? |
This comment has been minimized.
This comment has been minimized.
comment:7
Not fully as this ticket raises the question of the addition of edges between vertices lying in different connected components. So far, the order in which edges are added matters.
I have no opinion on the best solution. Regular users of this class should clarify expected behavior. |
comment:10
Made a start on this ticket. Seeing as there is already an inherited .connected_components() method, that calculates them on the fly (rather than maintaining an invariant), I'm using that. |
Branch: /u/gh-Bruno-TT/improved-add-edge |
Commit: |
comment:12
You should use For coding style, prefer New commits:
|
comment:13
Replying to David Coudert:
Good spot, thanks!
Thanks, will do this tomorrow. New commits:
|
comment:14
There is something wrong in the proposed behavior for |
comment:15
Replying to David Coudert:
Thanks, good spot - removed it.
Cool, I've removed the warning and updated the tests + documentation.
Good idea, I didn't think of that. I'll try and implement an algorithm now. |
Changed branch from /u/gh-Bruno-TT/improved-add-edge to public/graphs/8744_add_edge |
Reviewer: David Coudert |
comment:18
Why have you added the statement |
comment:19
Replying to David Coudert:
Assuming this is a typo and you mean review commit? If not then I can't find the ticket
I don't quite understand why you've chosen to remove the
and replace it with
I understand that vertex_in_left contains all the info needed to reconstruct the sets, but surely it's more efficient to just return the set objects and replace the references inside the graph, rather than adding another loop to reconstruct them? Other than that, I like all the changes you made. It was a good idea having one edges_to_add list instead of us,vs,labels. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:21
The reason for not returning |
comment:22
For me this ticket is good to go. |
Author: Bruno Edwards, David Coudert |
comment:23
Replying to David Coudert:
I second that |
Changed branch from public/graphs/8744_add_edge to |
The current add_edge method in BipartiteGraph refuses to add an edge between two vertices belonging to the same set. This may seem perfectly fine, but when the two vertices are in distinct connected components, the graph may stay bipartite with a new edge even if the vertices are in the same partition :
From the discussion on #8425 :
//////
To be honest, I really would like to be able to deal with Bipartite Graphs without having to specify myself in which set my vertices are... What would you think of setting a vertex to "left" if the users does not specify left=True or right=True, and modify a bit add_edge ? This way, the edge could be added immediately if the two vertices at its ends are in different sets, and if they are not the colors could be changed whenever possible to fit the graph with a new edge ?
Actually, when a graph is bipartite and split in two sets, you can add an edge in exactly two situations :
The colors between the endpoints are different
The colors are the same, but the vertices belong to two different connected components
So two solutions :
Add an edge if the colors are different. If they are not, check that there is no path from one vertex to the other, and if it is the case reverse the coloring of one of the two components and add the edge
Fix a partition for any connected component, and maintain them updated.
The problem is that the first makes of add_edge a linear-time function. The second way keeps it to O(1), but we would have to update the list of connected components, even if it is not so hard. The truth is I do not know what is best for this class, and I'm eager to learn your advice on it. It is also possible to add a flag like "allow_set_modifications" if you want to keep the possibility to refuse an addition in some cases... But anyway this should be mentionned in the docstrings :-)
///////
If anybody working on the BipartiteGraph class is willing to give all this a try.... :-)
Nathann
CC: @rhinton @sagetrac-brunellus
Component: graph theory
Author: Bruno Edwards, David Coudert
Branch/Commit:
8eb29c8
Reviewer: David Coudert
Issue created by migration from https://trac.sagemath.org/ticket/8744
The text was updated successfully, but these errors were encountered: