Search code examples
pythonnetworkxgml-geographic-markup-lan

Duplicate edges in .gml file using networkx.read_gml python


I want to use networkx in python to read a .gml file.

However when I do,

import networkx as nx
nx.read_gml("myfilename.gml")

it raises the error

networkx.exception.NetworkXError: edge #213 (103->400) is duplicated 

which is true that in the .gml file there are duplicate edges.

Is there any way to read a .gml file with duplicate edges without raising an error?


Solution

  • You should simply add "multigraph 1" to the file header, which allows the graph to have multiple edges and will result in nx.read_gml returning a MultiDiGraph.

    Already, the full error trace should already give you this answer

    Hint: If multigraph add "multigraph 1" to file header.
    

    taken from parse_gml_lines, if you are using the latest networkx version.