Given an *undirected* graph g with four vertices, I add edges by
g.add_edge_list([(0, 1), (0, 2), (0, 3), (1, 0), (1, 2), (1, 3), (2, 0), (2, 1), (2, 3), (3, 0), (3, 1), (3, 2)]) .
When calling g.num_edges() the result is 12. In my opinion it should be 6, as the graph is undirected? Any ideas?
It's because the graph definition in graph tool by default is directed. Declare your graph as myGraph = Graph (directed=False)
On Mon, Jan 7, 2019, 23:49 Christopher Morris < christopher.morris@tu-dortmund.de wrote:
Given an *undirected* graph g with four vertices, I add edges by
g.add_edge_list([(0, 1), (0, 2), (0, 3), (1, 0), (1, 2), (1, 3), (2, 0), (2, 1), (2, 3), (3, 0), (3, 1), (3, 2)]) .
When calling g.num_edges() the result is 12. In my opinion it should be 6, as the graph is undirected? Any ideas?
-- Christopher Morris Algorithm Engineering, Department of Computer Science, TU Dortmund University
https://ls11-www.cs.tu-dortmund.de/staff/morris
graph-tool mailing list graph-tool@skewed.de https://lists.skewed.de/mailman/listinfo/graph-tool
Am 07.01.19 um 19:22 schrieb ashutosh pandey:
It's because the graph definition in graph tool by default is directed. Declare your graph as myGraph = Graph (directed=False)
This has absolutely nothing to do with it. The behavior reported is consistent with a undirected multigraph, as I explained.
Am 14.12.18 um 11:36 schrieb Christopher Morris:
Given an *undirected* graph g with four vertices, I add edges by
g.add_edge_list([(0, 1), (0, 2), (0, 3), (1, 0), (1, 2), (1, 3), (2, 0), (2, 1), (2, 3), (3, 0), (3, 1), (3, 2)]) .
When calling g.num_edges() the result is 12. In my opinion it should be 6, as the graph is undirected? Any ideas?
Since the graph is undirected, adding (1, 2) and (2, 1) just amounts to adding the same edge _twice_.
In graph-tool, the Graph data structure store multigraphs (directed or not). It's up to the user to ensure that there are no parallel edges.
Best, Tiago