Home:ALL Converter>Maintaining edge attributes when converting to linegraph with python igraph

Maintaining edge attributes when converting to linegraph with python igraph

Ask Time:2018-11-06T09:51:33         Author:Michal SD

Json Formatter

I am using the python-igraph library with Python 3. I am trying to code a community detection algorithm which involves converting a graph to its linegraph, using the function linegraph().

There are attributes associated with each edge in the original graph, and I would like them to be copied over as vertex attributes in the linegraph, however this is not the case at the moment.

Does anyone know how I can do this?

What I've tried:

# Setting attributes for edge in originalGraph.es: edge['name'] = "".join(str(edge.tuple))

linegraph = originalGraph.linegraph()

# Testing print(orginalGraph.es[0].attributes()) print(linegraph.vs[0].attributes())

Prints out:

{'name': '(1, 7)'} {}

As you can see, the 'name' attribute is correctly associated with the edge of the original graph, but not with the vertex of the linegraph.

I might have to code my own function for converting to a linegraph, but I would prefer not to have to do this.

Author:Michal SD,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53164731/maintaining-edge-attributes-when-converting-to-linegraph-with-python-igraph
yy