igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Direction of edges along shortest path


From: Tamas Nepusz
Subject: Re: [igraph] Direction of edges along shortest path
Date: Mon, 7 Dec 2015 10:00:41 +0100

> But how can I get the directions of the edges that are passed along the way
> for each path?
If your network is not too large, the easiest is probably to:

1. Convert your original graph into another one where each edge is
present in both directions:

g2 = g.as_undirected()
g2.to_directed(mutual=True)

2. Call g2.get_shortest_paths(v=0, weights="length", output="vpath") -
this will give you each path as a list of vertex indices

3. For each consecutive vertex index pair (i, j), check whether there
is an edge between them in present in g. If so, this is an edge that
follows the directions in the original graph, otherwise it goes
against them:

from itertools import izip

def pairs(iterable):
    return izip(iterable, iterable[1:])

for path in shortest_paths_from_some_source_vertex:
    edge_follows_direction = [g.are_connected(u, v) for u, v in pairs(path)]

Best,
T.



reply via email to

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