% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cliques.R
\name{cliques}
\alias{cliques}
\alias{largest_cliques}
\alias{max_cliques}
\alias{count_max_cliques}
\alias{clique_num}
\alias{largest_weighted_cliques}
\alias{weighted_clique_num}
\alias{clique_size_counts}
\alias{is_clique}
\title{Functions to find cliques, i.e. complete subgraphs in a graph}
\usage{
cliques(graph, min = NULL, max = NULL, ..., callback = NULL)

largest_cliques(graph)

max_cliques(
  graph,
  min = NULL,
  max = NULL,
  subset = NULL,
  file = NULL,
  ...,
  callback = 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{
\item{graph}{The input graph.}

\item{min}{Numeric constant, lower limit on the size of the cliques to find.
\code{NULL} means no limit, i.e. it is the same as 0.}

\item{max}{Numeric constant, upper limit on the size of the cliques to find.
\code{NULL} means no limit.}

\item{...}{These dots are for future extensions and must be empty.}

\item{callback}{Optional function to call for each clique found. If provided,
the function should accept one argument: \code{clique} (integer vector of vertex
IDs in the clique, 1-based indexing). The function should return \code{FALSE} to
continue the search or \code{TRUE} to stop it. If \code{NULL} (the default), all
cliques are collected and returned as a list.

\strong{Important limitation:} Callback functions must NOT call any igraph
functions (including simple queries like \code{vcount()} or \code{ecount()}). Doing
so will cause R to crash due to reentrancy issues. Extract
any needed graph information before calling the function with a callback, or
use collector mode (the default) and process results afterward.}

\item{subset}{If not \code{NULL}, then it must be a vector of vertex ids,
numeric or symbolic if the graph is named. The algorithm is run from these
vertices only, so only a subset of all maximal cliques is returned. See the
Eppstein paper for details. This argument makes it possible to easily
parallelize the finding of maximal cliques.}

\item{file}{If not \code{NULL}, then it must be a file name, i.e. a
character scalar. The output of the algorithm is written to this file. (If
it exists, then it will be overwritten.) Each clique will be a separate line
in the file, given with the numeric ids of its vertices, separated by
whitespace.}

\item{vertex.weights}{Vertex weight vector. If the graph has a \code{weight}
vertex attribute, then this is used by default. If the graph does not have a
\code{weight} vertex attribute and this argument is \code{NULL}, then every
vertex is assumed to have a weight of 1. Note that the current implementation
of the weighted clique finder supports positive integer weights only.}

\item{maximal}{Specifies whether to look for all weighted cliques (\code{FALSE})
or only the maximal ones (\code{TRUE}).}

\item{candidate}{The vertex set to test for being a clique.}

\item{directed}{Whether to consider edge directions.}
}
\value{
\code{cliques()} returns a list containing numeric vectors of vertex ids if
\code{callback} is \code{NULL}. Each list element is a clique, i.e. a vertex sequence
of class \link[=V]{igraph.vs}. If \code{callback} is provided, returns \code{NULL} invisibly.

\code{largest_cliques()} and \code{clique_num()} return a list containing numeric
vectors of vertex ids. Each list element is a clique, i.e. a vertex sequence
of class \link[=V]{igraph.vs}.

\code{max_cliques()} returns \code{NULL}, invisibly, if its \code{file}
argument is not \code{NULL}. The output is written to the specified file in
this case.

\code{clique_num()} and \code{count_max_cliques()} return an integer
scalar.

\code{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.

\code{is_clique()} returns \code{TRUE} if the candidate vertex set forms
a clique.
}
\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.
}
\details{
\code{cliques()} find all complete subgraphs in the input graph, obeying the
size limitations given in the \code{min} and \code{max} arguments.

\code{largest_cliques()} finds all largest cliques in the input graph. A
clique is largest if there is no other clique including more vertices.

\code{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.

\code{count_max_cliques()} counts the maximal cliques.

\code{clique_num()} calculates the size of the largest clique(s).

\code{clique_size_counts()} returns a numeric vector representing a histogram
of clique sizes, between the given minimum and maximum clique size.

\code{is_clique()} tests whether all pairs within a vertex set are connected.
}
\section{Related documentation in the C library}{
\href{https://igraph.org/c/html/0.10.17/igraph-Cliques.html#igraph_cliques}{\code{cliques()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Basic.html#igraph_vcount}{\code{vcount()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Cliques.html#igraph_largest_cliques}{\code{largest_cliques()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Cliques.html#igraph_clique_number}{\code{clique_number()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Cliques.html#igraph_largest_weighted_cliques}{\code{largest_weighted_cliques()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Cliques.html#igraph_weighted_clique_number}{\code{weighted_clique_number()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Cliques.html#igraph_clique_size_hist}{\code{clique_size_hist()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Cliques.html#igraph_maximal_cliques_hist}{\code{maximal_cliques_hist()}}, \href{https://igraph.org/c/html/0.10.17/igraph-Cliques.html#igraph_is_clique}{\code{is_clique()}}
}

\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)))
}
\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.  \url{https://arxiv.org/abs/1006.5440}
}
\seealso{
Other cliques: 
\code{\link{is_complete}()},
\code{\link{ivs}()},
\code{\link{weighted_cliques}()}
}
\author{
Tamas Nepusz \email{ntamas@gmail.com} and Gabor Csardi
\email{csardi.gabor@gmail.com}
}
\concept{cliques}
\keyword{graphs}
