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
Graph constructor : Graph(edges=[ ... ] ) #7709
Comments
comment:4
Here is a patch to update graph.py. I have been sitting a while, trying to find a efficient way to write this, and found none, so I ended up converting it all to a dict_of_lists of dict_of_dicts... As it took some time to write, I would gladly ask for your advice before rewriting it all for digraphs.py (if you agree). Otherwise, let's try to find a better solution together :-) Nathann |
comment:5
Oh, by the way... This is no a new feature, as it was already possible to create a Graph by giving as an argument a list of edges, but until now it was forwarded to NetworkX.. Nathann |
comment:6
I think |
comment:7
Actually, I wondered... Faster to write, of course, but do you think it is also more efficient ? I had no idea, so I stuck to the most basic tools :-) Nathann |
comment:8
sorry, forget my comment, data.setdefault(...[]).append(u) is slower than your solution. |
comment:9
I would change the ValueError message to something much shorter and more comprehensive, such as "Edges input must all be of the same format" or length or something... |
comment:10
Replying to @rlmill:
Also, the doctests don't expose this error. |
comment:11
I just updated the ticket to fix it ! Do you think this method is acceptable and I can now do the same for DiGraphs ? Nathann |
comment:12
Replying to @nathanncohen:
Nathann, This looks good (maybe in the multiedges=False test you can show the list of edges afterward to demonstrate what actually happens). Please implement this in the DiGraph case as well! |
comment:13
Here it is ! Actually, the constructor raises an exception when the same edge receives different labels with multiedges = False. I had forgotten to fill the doctests, as it was just a preview ! Nathann |
Author: Nathann Cohen |
Reviewer: Robert Miller |
comment:14
Attachment: trac_7709.patch.gz |
Merged: sage-4.6.1.alpha1 |
I often need to create graphs defined by a set of edges, and it should not be hard to add a new constructor of this shape :
Nathann
CC: @nthiery @rlmill
Component: graph theory
Author: Nathann Cohen
Reviewer: Robert Miller
Merged: sage-4.6.1.alpha1
Issue created by migration from https://trac.sagemath.org/ticket/7709
The text was updated successfully, but these errors were encountered: