Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose is_complete(), is_clique() and is_ivs() #1581

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ export(is_acyclic)
export(is_biconnected)
export(is_bipartite)
export(is_chordal)
export(is_clique)
export(is_complete)
export(is_connected)
export(is_dag)
export(is_degseq)
Expand All @@ -557,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
57 changes: 57 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 @@ -527,3 +534,53 @@ clique_size_counts <- function(graph, min = 0, max = 0, maximal = FALSE) {
clique_size_hist_impl(graph, min, max)
}
}

#' Is this a complete graph?
#'
#' A graph is considered complete if there is an edge between all distinct
#' directed pairs of vertices. igraph considers both the singleton graph
#' and the null graph complete.
#'
#' @param graph The input graph.
#' @return True if the graph is complete.
#' @family cliques
#' @keywords graphs
#' @seealso [make_full_graph()]
#' @export
#' @cdocs igraph_is_complete
#' @examples
#'
#' g <- make_full_graph(6, directed = TRUE)
#' is_complete(g)
#' g <- delete_edges(g, 1)
#' is_complete(g)
#' 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.

24 changes: 21 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.

40 changes: 40 additions & 0 deletions man/is_complete.Rd

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

16 changes: 14 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.

1 change: 1 addition & 0 deletions man/weighted_cliques.Rd

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

Loading