iterators {igraph} | R Documentation |
Vertex and edge sequences are the central concept of igraph.
igraph.vs.all(graph) igraph.vs.vector(graph, iterator) igraph.vs.adj(graph, vid, mode="all") igraph.vs.end(graph, iterator) igraph.vs.get(graph, iterator) igraph.vs.next(graph, iterator) igraph.vs.reset(graph, iterator) vs$end vs$step vs$v igraph.es.all(graph) igraph.es.fromorder(graph) igraph.es.vector(graph, iterator) igraph.es.adj(graph, vid, mode="all") igraph.es.end(graph, iterator) igraph.es.get(graph, iterator) igraph.es.from(graph, iterator) igraph.es.to(graph, iterator) igraph.es.next(graph, iterator) igraph.es.reset(graph, iterator) es$end es$e es$from es$to as.vector(iterator)
graph |
A graph object. |
iterator |
A vertex or edge sequence. |
vid |
Id of the vertex of which the adjacent vertices or edges will be selected. |
mode |
Defines the type of adjacent vertices/edges to
select. out is for outgoing edges, in for incoming
ones, while all is both both of them. |
vs |
A vertex sequence. |
es |
An edge sequence. |
end |
Not a real parameter, vs$end is TRUE if the
vs sequence has no more vertices/edges to visit. See example
below. |
step |
Not a real parameter, vs$step is a shorthand for
igraph.vs.next(graph,vs) and igraph.es.next(graph,es) . |
v |
Shorthand for igraph.vs.get . |
e |
Shorthand for igraph.es.get . |
from |
es$from(graph) is a shorthand for
igraph.es.from(graph, es) . |
to |
es$to(graph) is a shorthand for
igraph.es.to(graph, es) . |
igraph.vs.all
creates a vertex sequence with all vertices of a
graph.
igraph.vs.vector
creates a vertex sequence from a vector of
vertex ids.
igraph.vs.adj
creates a vertex sequence containing the adjacent
vertices of a vertex.
igraph.vs.end
, igraph.vs.step
, igraph.vs.get
provide an iterator abstraction of a vertex set.
igraph.vs.end
checks whether there is another vertex to step to
with the iterator. igraph.vs.get
returns the vertex id at the
current position of the iterator. igraph.vs.step
moves to the
next position.
igraph.vs.reset
resets the iterator, this is equivalent to
creating a new iterator of the same type, with the same parameters.
vs$end
, vs$step
, vs$v
provide a simpler
iterator-like interface. See the examples section below.
as.vector
can be used on a vertex and edge sequence to coerce
it to a regular numeric vector.
igraph.es.all
creates an edge sequence containing all edges in
the graph, their order will be arbitrary.
igraph.es.fromorder
creates an edge sequence with all edges. It is somewhat less efficient
than igraph.es.all
, but the order of the edges is defined by
the starting vertex of the edge.
igraph.es.vector
creates an edge set from a vector containing
edge ids.
igraph.es.adj
creates an edge set containing the adjacent edges
of a vertex.
igraph.es.get
returns the id of the edge at the current
iterator position.
igraph.es.from
returns the starting vertex
of the current edge.
igraph.es.to
returns the end vertex of the current edge.
igraph.es.end
checks whether there are more edges in the edge
set to step to.
igraph.es.next
steps to the next edge in the edge sequence.
igraph.es.reset
resets the iterator, it is equivalent to but slightly
more efficient than creating a new edge sequence of the same type with
the same parameters.
es$end
, es$e
, es$from(graph)
and
es$to(graph)
provide a simpler iterator interface to edge
sequences, see the examples below.
Note that igraph.vs.next
, igraph.vs.reset
,
igraph.es.next
and igraph.es.reset
don't change the
iterator supplied as a parameter, but return the new, modified
iterator.
igraph.vs.all
, igraph.vs.vector
, igraph.vs.adj
return a vertex sequence.
igraph.vs.end
and igraph.es.end
return a logical
constant.
igraph.vs.get
, igraph.es.get
, igraph.es.get
,
igraph.es.from
and igraph.es.to
return a numeric
constant.
igraph.vs.next
and igraph.vs.reset
return the new vertex
sequence.
igraph.es.next
and igraph.es.reset
return the new vertex
sequence.
as.vector
returns a numeric vector.
Gabor Csardi csardi@rmki.kfki.hu
# mean degree of vertices in the largest cluster in a random graph g <- erdos.renyi.game(100, 2/100) c <- clusters(g) vsl <- igraph.vs.vector(g, which(which.max(c$csize)-1==c$membership)-1) mean(degree(g, vsl)) # set the color of these vertices to red, others greens g <- add.vertex.attribute(g, "color", type="string") v.a(g, "color") <- "green" v.a(g, "color", vsl) <- "red" ## Not run: plot(g, vertex.size=3, labels=NA, vertex.color="a:color") # the longest geodesic within the largest cluster vsl <- igraph.vs.reset(g, vsl) # just to be sure long <- numeric() while (!vsl$end) { paths <- get.shortest.paths(g, vsl$v) paths <- paths[ as.vector(vsl)+1 ] fl <- paths[[ which.max(sapply(paths, length)) ]] if (length(fl) > length(long)) { long <- fl } vsl <- vsl$step }