igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] line graph + multiple edges + newbie


From: Raphael Clifford
Subject: [igraph] line graph + multiple edges + newbie
Date: Thu, 6 Sep 2012 20:15:38 +0100

Hi,

I am still pretty new at igraph and am stuck doing something that I
feel ought to be simple.

I would like to do pretty much exactly what linegraph() does but with
a couple of twists.  From the manual linegraph() on a directed graph
is defined as follows

"The line graph L(G) of an undirected graph is defined as follows: L(G) has
one vertex for each edge in G and two vertices in L(G) are connected iff their
corresponding edges in the original graph share an end point.

The line graph of a directed graph is slightly different: two vertices are
connected by a directed edge iff the target of the first vertex’s corresponding
edge is the same as the source of the second vertex’s corresponding edge."

In my case the original graph is directed, the edges have weights and
there can be multiple edges.  New definition: Two vertices are
connected by a directed edge iff the target of the first vertex's
corresponding edge is the same as the source of the second vertex's
corresponding edge AND the weight of the second vertex's corresponding
edge is larger than the weight of the first vertex's corresponding
edge.

In principle this is a simple change to make but I don't fully
understand the syntax yet of igraph+python. I would like something
like the following

#Read in the graph.
#First problem is that it seems multiple edges are not supported?
g = Read_Ncol("test.ncol", weights= True, directed = True)
# Set the new line graph to have the same number of nodes as g has edges
h = Graph.(g.ecount())

for e in g.es:
    for vnext in g.neighbors(e[1], mode = OUT):
        if (weight of edge e < weight of edge (e[1], vnext)):
             h.add_edges(ID of edge e, ID of (v, vnext))

The second problem is just that I don't understand the syntax well
enough to see how to write this loop correctly using igraph.

Any help is much appreciated.

Raphael



reply via email to

[Prev in Thread] Current Thread [Next in Thread]