To answer a bit more precisely, the behaviour of Graph(edges) and g=Graph;
g.add_edges(edges) is not exactly the same.

For instance, if you run the second there will never be any multiple edge
in your graph, for that is the default behaviour of a Graph() object, built
without argument. If, on the other hand, you create Graph([(1,2), (1,2)]),
the graph will contain this edge twice and support multiple edges:

sage: Graph([(1,2),(1,2)])
Multi-graph on 2 vertices
sage: g=Graph();g.add_edges([(1,2),(1,2)]);g
Graph on 2 vertices

Same with loops :

sage: Graph([(0,0)])
Looped graph on 1 vertex
sage: g=Graph();g.add_edge(0,0);g
Graph on 0 vertices

To do that (and remember that I totally hate everything that has to do with
multiple edges/loops/labels), you have to know the list of all edges, and
go through it, and decide whether you allow loops/multiple edges. I
personally wouldn't mind saying that all Sage graphs aer loopless and do
not contain any multiple edges so that the two syntaxes would be
equivalent. And Graph(list_of_edges, multiple_edges=True) would return what
we expect. But then, that's explicit.

That would also be sufficient to fix the bug you reported, as there would
be no need to analyse the whole list of edges. Create the graph, add the
edges, and that's settled. The two commands would be equivalent.

There is another difference, about the homogeneity of the data (some edges
have labels, others don't)

sage: Graph([(1,2),(1,3,"a label")])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-5065db547344> in <module>()
----> 1 Graph([(Integer(1),Integer(2)),(Integer(1),Integer(3),"a label")])

/home/ncohen/.Sage/local/lib/python2.7/site-packages/sage/graphs/graph.pyc
in __init__(self, data, pos, loops, format, boundary, weighted,
implementation, data_structure, vertex_labels, name, multiedges,
convert_empty_dict_labels_to_None, sparse)
   1181                     raise ValueError("Two different labels given
for the same edge in a graph without multiple edges.")
   1182                 else:
-> 1183                     raise ValueError("Edges input must all follow
the same format.")
   1184
   1185

ValueError: Edges input must all follow the same format.
sage: g = Graph(); g.add_edges([(1,2),(1,3,"a label")]);g
Graph on 3 vertices

Of course, there is no problem with explicitly saying that the first edge
should have no label :

sage: Graph([(1,2,None),(1,3,"a label")])
Graph on 3 vertices

Sooo, well. That's the kind of differences you can expect between the two
syntaxes.

My own opinion on this is that we would be better off if the two were
equivalent, as you reported. This would also make the Graph's constructor
shorter and easier to understand. This would also make the "type" of the
graph (i.e. does it allow multiple edges and loops) more predictable, for
then the user would have to specify it clearly and live with the
consequences. As they are now, *unless you specify it*, you don't know what
the type of the graph you will get is going to be. Maybe we should say that
"default graphs" are "simple graphs" (no loops, no multiple edges) unless
explicitly said otherwise.

My problem with this is that I am not an user of these kind of graphs, and
I don't feel legitimate to make decisions on features I don't use. Though
if those who use these graphs feel like this would be a nice change, I'd be
glad to work on it :-P

Nathann

P.S. : I hate labels. I hate loops. I hate multiple edges. Once more,
that's what costs all this running time :-P

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to