| cliques {igraph} | R Documentation |
Functions to find cliques, i.e. complete subgraphs in a graph
Description
These functions find all, the largest or all the maximal cliques in an undirected graph. The size of the largest clique can also be calculated.
Tests if all pairs within a set of vertices are adjacent, i.e. whether they form a clique. An empty set and singleton set are considered to be a clique.
Usage
cliques(graph, min = 0, max = 0)
largest_cliques(graph)
max_cliques(graph, min = NULL, max = NULL, subset = NULL, file = NULL)
count_max_cliques(graph, min = NULL, max = NULL, subset = NULL)
clique_num(graph)
largest_weighted_cliques(graph, vertex.weights = NULL)
weighted_clique_num(graph, vertex.weights = NULL)
clique_size_counts(graph, min = 0, max = 0, maximal = FALSE)
is_clique(graph, candidate, directed = FALSE)
Arguments
graph |
The input graph. |
min |
Numeric constant, lower limit on the size of the cliques to find.
|
max |
Numeric constant, upper limit on the size of the cliques to find.
|
subset |
If not |
file |
If not |
vertex.weights |
Vertex weight vector. If the graph has a |
maximal |
Specifies whether to look for all weighted cliques ( |
candidate |
The vertex set to test for being a clique. |
directed |
Whether to consider edge directions. |
Details
cliques() find all complete subgraphs in the input graph, obeying the
size limitations given in the min and max arguments.
largest_cliques() finds all largest cliques in the input graph. A
clique is largest if there is no other clique including more vertices.
max_cliques() finds all maximal cliques in the input graph. A
clique is maximal if it cannot be extended to a larger clique. The largest
cliques are always maximal, but a maximal clique is not necessarily the
largest.
count_max_cliques() counts the maximal cliques.
clique_num() calculates the size of the largest clique(s).
clique_size_counts() returns a numeric vector representing a histogram
of clique sizes, between the given minimum and maximum clique size.
is_clique() tests whether all pairs within a vertex set are connected.
Value
cliques(), largest_cliques() and clique_num()
return a list containing numeric vectors of vertex ids. Each list element is
a clique, i.e. a vertex sequence of class igraph.vs.
max_cliques() returns NULL, invisibly, if its file
argument is not NULL. The output is written to the specified file in
this case.
clique_num() and count_max_cliques() return an integer
scalar.
clique_size_counts() returns a numeric vector with the clique sizes such that
the i-th item belongs to cliques of size i. Trailing zeros are currently
truncated, but this might change in future versions.
is_clique() returns TRUE if the candidate vertex set forms
a clique.
Related documentation in the C library
cliques(), largest_cliques(), clique_number(), largest_weighted_cliques(), weighted_clique_number(), maximal_cliques_hist(), clique_size_hist(), is_clique().
Author(s)
Tamas Nepusz ntamas@gmail.com and Gabor Csardi csardi.gabor@gmail.com
References
For maximal cliques the following algorithm is implemented: David Eppstein, Maarten Loffler, Darren Strash: Listing All Maximal Cliques in Sparse Graphs in Near-optimal Time. https://arxiv.org/abs/1006.5440
See Also
Other cliques:
is_complete(),
ivs(),
weighted_cliques()
Examples
# this usually contains cliques of size six
g <- sample_gnp(100, 0.3)
clique_num(g)
cliques(g, min = 6)
largest_cliques(g)
# To have a bit less maximal cliques, about 100-200 usually
g <- sample_gnp(100, 0.03)
max_cliques(g)
# Check that all returned vertex sets are indeed cliques
all(sapply(max_cliques(g), function (c) is_clique(g, c)))