id,summary,reporter,owner,description,type,status,priority,milestone,component,resolution,keywords,cc,merged,author,reviewer,upstream,work_issues,branch,commit,dependencies,stopgaps
18067,sage/graphs/graph.py: multigraph recognition in init fails,darij,,"Sage is slightly inconsistent when it comes to detect multiple edges in
`Graph(list_of_edges)`:
{{{
sage: Graph([[1,2],[1,2]])
Multi-graph on 2 vertices
sage: Graph([[1,2],[2,1]])
Graph on 2 vertices
}}}
This branch fixes that bug while removing code from `Graph.__init__` and
`DiGraph.__init__`, which now relies `GenericGraph.add_edges`. More precisely:
- Make Sage build a (di)graph from a list of edges with the following procedure:
- Create an empty graph allowing loops and multiple edges
- Call `self.add_edges(list_of_edges)`
- Check whether multiedges/loops have been created, and display the
pre-existing warnings accordingly.
- Update the `allow_loops` and `allow_multiple_edges` parameters
accordingly.
- When Sage does not know how to create a graph from the provided data, it
currently gives it to NetworkX hoping that it will work, then convert the
result into a Sage graph. With this branch, we now raise an exception instead.
- As a consequence it is not possible to create a graph from a Numpy matrix
anymore, though that can be done easily through `Graph(Matrix(my_matrix))` so
it is not that bad either (in particular, copying the matrix is not more
expensive than creating a NetworkX graph)
Furthermore, the graphs created from a Numpy matrix inherited the 'weird'
NetworkX standards:
{{{
sage: import numpy
sage: A = numpy.array([[0,1,1],[1,0,1],[1,1,0]])
sage: Graph(A).edges()
[(0, 1, {0: {'weight': 1}, 1: {'weight': 1}}),
(0, 2, {0: {'weight': 1}, 1: {'weight': 1}}),
(1, 2, {0: {'weight': 1}, 1: {'weight': 1}})]
}}}
- Several corner-cases of Graph creation are now handled differently as a
result. I merely removed the doctests, thinking that they were not actually
testing a property that we want to keep, e.g.:
Before:
{{{
sage: g = Graph([(1,2,3),(1,2,4)], multiedges = False)
...
ValueError: Two different labels given for the same edge in a graph without multiple edges.
}}}
After:
{{{
sage: g = Graph([(1,2,3),(1,2,4)], multiedges = False)
sage: g.edges()
[(1, 2, 4)]
}}}
Note that it actually makes `Graph(list_of_edges)` behave as `add_edges`
already does, as in the latest release we have:
{{{
sage: g = Graph()
sage: g.add_edges([(1,2,3),(1,2,4)])
sage: g.edges()
[(1, 2, 4)]
}}}
- Fix a bug in `GenericGraph.has_multiple_edges`:
{{{
sage: g = Graph(loops=True,multiedges=True)
sage: g.add_edge(0,0)
sage: g.has_multiple_edges()
True
}}}
What this branch does will also help us reduce further the complexity of those
(awful) `__init__` functions.
Nathann",defect,closed,major,sage-6.6,graph theory,fixed,"graphs, sage-combinat,",ncohen sage-combinat tmonteil vdelecroix dcoudert,,Nathann Cohen,David Coudert,N/A,,197bc184f518fd6a773b2a28aea72507c3908ac2,197bc184f518fd6a773b2a28aea72507c3908ac2,,