igraph (version 1.2.4.2)

which_multiple: Find the multiple or loop edges in a graph

Description

A loop edge is an edge from a vertex to itself. An edge is a multiple edge if it has exactly the same head and tail vertices as another edge. A graph without multiple and loop edges is called a simple graph.

Usage

which_multiple(graph, eids = E(graph))

Arguments

graph

The input graph.

eids

The edges to which the query is restricted. By default this is all edges in the graph.

Value

any_multiple returns a logical scalar. which_loop and which_multiple return a logical vector. count_multiple returns a numeric vector.

Details

which_loop decides whether the edges of the graph are loop edges.

any_multiple decides whether the graph has any multiple edges.

which_multiple decides whether the edges of the graph are multiple edges.

count_multiple counts the multiplicity of each edge of a graph.

Note that the semantics for which_multiple and count_multiple is different. which_multiple gives TRUE for all occurences of a multiple edge except for one. Ie. if there are three i-j edges in the graph then which_multiple returns TRUE for only two of them while count_multiple returns ‘3’ for all three.

See the examples for getting rid of multiple edges while keeping their original multiplicity as an edge attribute.

See Also

simplify to eliminate loop and multiple edges.

Examples

Run this code
# NOT RUN {
# Loops
g <- graph( c(1,1,2,2,3,3,4,5) )
which_loop(g)

# Multiple edges
g <- barabasi.game(10, m=3, algorithm="bag")
any_multiple(g)
which_multiple(g)
count_multiple(g)
which_multiple(simplify(g))
all(count_multiple(simplify(g)) == 1)

# Direction of the edge is important
which_multiple(graph( c(1,2, 2,1) ))
which_multiple(graph( c(1,2, 2,1), dir=FALSE ))

# Remove multiple edges but keep multiplicity
g <- barabasi.game(10, m=3, algorithm="bag")
E(g)$weight <- count_multiple(g)
g <- simplify(g)
any(which_multiple(g))
E(g)$weight

# }

Run the code above in your browser using DataCamp Workspace