2
votes

I am attempting to read a gml file into a multigraph object; however, I am receiving the following error:

NetworkXError: edge #1 (0--3) is duplicated

In the gml file the the edge is duplicated:

  edge [
    source 0
    target 3
    LinkLabel "Green"
  ]
  edge [
    source 0
    target 3
    LinkLabel "Brown"
  ]

As I understand it, the read_gml function should return a multigraph when the input is a multigraph. What am I missing?

1
It would be nice if you are able to show a minimum gml file. - SparkAndShine

1 Answers

3
votes

Your gml file probably lacks of multigraph 1 below graph [. Here is a MWE.

import networkx as nx
G = nx.read_gml('test.gml')

print(type(G))              # <class 'networkx.classes.multigraph.MultiGraph'>
print(G.edges(data=True))   # [(0, 3, {u'LinkLabel': u'Green'}), (0, 3, {u'LinkLabel': u'Brown'})]

The content of test.gml,

graph [
  multigraph 1
  node [
    id 0
    label 0
  ]
  node [
    id 3
    label 3
  ]
  edge [
    source 0
    target 3
    LinkLabel "Green"
  ]
  edge [
    source 0
    target 3
    LinkLabel "Brown"
  ]
]