igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Nodes at a given distance


From: Tamas Nepusz
Subject: Re: [igraph] Nodes at a given distance
Date: Sun, 27 Jul 2008 14:09:54 +0200

Alternatively, you can just calculate shortest paths to all
vertices from the given vertex, and take the ones that are at
the desired distance.
Another possibility is to use a breadth first search iterator over the vertices, starting from your source vertex:

g=Graph.GRG(100, 0.2)
source_vertex=0
distance=2
for vertex, d, parent in g.bfsiter(source_vertex, advanced=True):
  if d == distance:
    # If the current vertex is at the desired distance, print its index
    print vertex.index
  elif d > distance:
# The current vertex is farther than the desired distance. Since this is # a BFS iterator, no vertex with the desired distance will come up in the
    # sequence, so we can safely cancel the iteration
    break

(Sorry for the long delay, I'm abroad and I don't have too much chance to check my emails)

--
T.





reply via email to

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