Reputation: 2611
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.
Upvotes: 1
Views: 102
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
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