Skip to content

Commit

Permalink
feat: is_clique() and is_ivs() test whether a set of vertices for…
Browse files Browse the repository at this point in the history
…ms a clique or an independent set
  • Loading branch information
szhorvat committed Nov 12, 2024
1 parent 5c67c4d commit 271d0f7
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 23 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ export(is_acyclic)
export(is_biconnected)
export(is_bipartite)
export(is_chordal)
export(is_clique)
export(is_complete)
export(is_connected)
export(is_dag)
Expand All @@ -558,6 +559,7 @@ export(is_graphical)
export(is_hierarchical)
export(is_igraph)
export(is_isomorphic_to)
export(is_ivs)
export(is_matching)
export(is_max_matching)
export(is_min_separator)
Expand Down
34 changes: 34 additions & 0 deletions R/cliques.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ clique.number <- function(graph) { # nocov start
#' `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.
#'
#' @inheritParams weighted_cliques
#' @param graph The input graph, directed graphs will be considered as
#' undirected ones, multiple edges and loops are ignored.
Expand Down Expand Up @@ -205,6 +207,9 @@ clique.number <- function(graph) { # nocov start
#' # 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)))
#' @cdocs igraph_cliques
cliques <- cliques_impl

Expand Down Expand Up @@ -395,6 +400,8 @@ weighted_clique_num <- weighted_clique_number_impl
#' These functions use the algorithm described by Tsukiyama et al., see
#' reference below.
#'
#' `is_ivs()` tests if no pairs within a vertex set are connected.
#'
#' @param graph The input graph, directed graphs are considered as undirected,
#' loop edges and multiple edges are ignored.
#' @param min Numeric constant, limit for the minimum size of the independent
Expand Down Expand Up @@ -550,3 +557,30 @@ clique_size_counts <- function(graph, min = 0, max = 0, maximal = FALSE) {
#' g <- as_undirected(g)
#' is_complete(g)
is_complete <- is_complete_impl

#' @rdname cliques
#'
#' @description
#' 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.
#'
#' @param graph The input graph.
#' @param candidate The vertex set to test for being a clique.
#' @param directed Whether to consider edge directions.
#' @return `is_clique()` returns `TRUE` if the candidate vertex set forms
#' a clique.
#' @keywords graphs
#' @export
#' @cdocs igraph_is_clique
is_clique <- is_clique_impl

#' @rdname ivs
#'
#' @param graph The input graph.
#' @param candidate The vertex set to test for being an independent set.
#' @return `is_ivs()` returns `TRUE` if the candidate vertex set forms an
#' independent set.
#' @keywords graphs
#' @export
#' @cdocs igraph_is_independent_vertex_set
is_ivs <- is_independent_vertex_set_impl
3 changes: 1 addition & 2 deletions man/clique.number.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions man/cliques.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/independence.number.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/independent.vertex.sets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions man/ivs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/largest.cliques.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/largest.independent.vertex.sets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/maximal.cliques.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/maximal.cliques.count.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/maximal.independent.vertex.sets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/maximal_ivs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 271d0f7

Please sign in to comment.