hans glick
hans glick

Reputation: 2611

python igraph edges as nodes graph

I have a graph in igraph :

import igraph as ig
vertices = [i for i in range(7)]
edges = [(0,2),(0,1),(0,3),(1,0),(1,2),(1,3),(2,0),(2,1),(2,3),(3,0),(3,1),(3,2),(2,4),(4,5),(4,6),(5,4),(5,6),(6,4),(6,5)]
g = ig.Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)

But I'm wondering if there is something already implemented in Igraph in order to get the graph with edges as nodes of the actual g graph as shown in the picture below.

enter image description here

Upvotes: 1

Views: 102

Answers (2)

hans glick
hans glick

Reputation: 2611

Like Romain said, you can do the trick with linegraph().

import igraph as ig

vertices = [i for i in range(7)]
edges = [(0,2),(0,1),(0,3),(1,0),(1,2),(1,3),(2,0),(2,1),(2,3),(3,0),(3,1),(3,2),(2,4),(4,5),(4,6),(5,4),(5,6),(6,4),(6,5)]
g = ig.Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)

# Graph g with edges as nodes
g = g.linegraph()

Upvotes: 0

RomainL.
RomainL.

Reputation: 1014

If I am not mistaken this transformation is called a line graph, Igraph python have function call linegraph().

I believe this is what you are looking for.

Upvotes: 1

Related Questions