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?

ashutosh
(ashutosh)
#2
It's because the graph definition in graph tool by default is directed.

Declare your graph as

myGraph = Graph (directed=False)

attachment.html (1.43 KB)

tiago
(Tiago Peixoto)
#3
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

tiago
(Tiago Peixoto)
#4
This has absolutely nothing to do with it. The behavior reported is

consistent with a undirected multigraph, as I explained.