简体   繁体   English

从gml文件读取NetworkX中的Multigraph

[英]Reading a Multigraph in NetworkX from gml file

I am attempting to read a gml file into a multigraph object; 我正在尝试将gml文件读入多图对象; however, I am receiving the following error: 但是,我收到以下错误:

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

In the gml file the the edge is duplicated: 在gml文件中,边缘是重复的:

  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. 据我了解,当输入为多图时,read_gml函数应返回多图。 What am I missing? 我想念什么?

Your gml file probably lacks of multigraph 1 below graph [ . 您的gml文件可能缺少graph [之下的multigraph 1 Here is a MWE. 这是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 , 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"
  ]
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM