3

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>
john doe
  • 81
  • 4

1 Answers1

2

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
john doe
  • 81
  • 4