简体   繁体   中英

Networkx - How to change edge id's?

I'm using networkx to create graphml files. I have parallel links so I'm using the MultiDiGraph function. After generating the file I open it in yED but I don't have all the connections that I created between the nodes. The only connections (edges) I have are the ones created for the parallel links. I've realized it is because the graphml file only have two edge ids ('0' and '1') for all the edges. I modified the file and set a unique id for each edge. For example:

<edge id="0" source="Hostname_A" target="Hostname_B">
  <data key="d1">100GE1/0/0</data>
  <data key="d2">100GE1/0/0</data>
</edge>
<edge id="1" source="Hostname_A" target="Hostname_B">
  <data key="d1">100GE1/0/1</data>
  <data key="d2">100GE1/0/1</data>
</edge>
<edge id="2" source="Hostname_B" target="Hostname_C">
  <data key="d1">100GE1/1/0</data>
  <data key="d2">100GE1/0/0</data>
</edge>

If i do this then everything works fine in yED. Is there any way to modify the edge ID's in networkx? I thought I could modify the 'edge id' if I set it like an attribute like this:

g.add_edge(host,neighbor,source = intsource, destination = intdest, id=idcount)

But I realized it didnt change the edge id only added another attribute for that edge:

<edge id="0" source="Hostname_A" target="Hostname_B">
  <data key="d1">100GE1/0/0</data>
  <data key="d2">100GE1/0/0</data>
  <data key="d3">1</data>   <-- This is the idcount value
</edge>

Solved this. If you need to change 'edge ids' in MultiDiGraphs you have to use the 'key' attribute like this:

g.add_edge(host,neighbor,key=idcount) <-- idcount is an int value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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