Skip to content

Commit

Permalink
feat: voronoi()
Browse files Browse the repository at this point in the history
  • Loading branch information
szhorvat committed Feb 1, 2024
1 parent 5205103 commit d40b2e7
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 21 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ Config/testthat/start-first: vs-es, scan, vs-operators, weakref,
watts.strogatz.game
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0.9000
RoxygenNote: 7.3.1
SystemRequirements: gmp, libxml2, glpk (>= 4.57)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ export(vertex_attr_names)
export(vertex_connectivity)
export(vertex_disjoint_paths)
export(vertices)
export(voronoi)
export(walktrap.community)
export(watts.strogatz.game)
export(weighted_clique_num)
Expand Down
3 changes: 2 additions & 1 deletion R/aaa-auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,9 @@ distances_floyd_warshall_impl <- function(graph, from=V(graph), to=V(graph), wei
res
}

voronoi_impl <- function(graph, generators, weights=NULL, mode=c("out", "in", "all", "total"), tiebreaker=c("random", "first", "last")) {
voronoi_impl <- function(graph, generators, ..., weights=NULL, mode=c("out", "in", "all", "total"), tiebreaker=c("random", "first", "last")) {
# Argument checks
check_dots_empty()
ensure_igraph(graph)
generators <- as_igraph_vs(graph, generators)
if (is.null(weights) && "weight" %in% edge_attr_names(graph)) {
Expand Down
41 changes: 41 additions & 0 deletions R/community.R
Original file line number Diff line number Diff line change
Expand Up @@ -2782,3 +2782,44 @@ communities <- groups.communities
#' @export
#' @family functions for manipulating graph structure
contract <- contract_vertices_impl


#' Voronoi partitioning of a graph
#'
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' This function partitions the vertices of a graph based on a set of generator
#' vertices. Each vertex is assigned to the generator vertex from (or to) which
#' it is closest.
#'
#' [groups()] may be used on the output of this function.
#'
#' @param graph The graph to partition into Voronoi cells.
#' @param generators The generator vertices of the Voronoi cells.
#' @param mode Character string. In directed graphs, whether to compute
#' distances from generator vertices to other vertices (`"out"`), to
#' generator vertices from other vertices (`"in"`), or ignore edge
#' directions entirely (`"all"`). Ignored in undirected graphs.
#' @param tiebreaker Character string that specifies what to do when a vertex
#' is at the same distance from multiple generators. `"random"` assigns
#' a minimal-distance generator randomly, `"first"` takes the first one,
#' and `"last"` takes the last one.
#' @inheritParams distances
#' @inheritParams rlang::args_dots_empty
#' @return A named list with two components:
#' \item{membership}{numeric vector giving the cluster id to which each vertex
#' belongs.}
#' \item{distances}{numeric vector giving the distance of each vertex from its
#' generator}
#' @seealso [distances()]
#' @examples
#'
#' g <- make_lattice(c(10,10))
#' clu <- voronoi(g, c(25, 43, 67))
#' groups(clu)
#' plot(g, vertex.color=clu$membership)
#'
#' @export
#' @family community
voronoi <- voronoi_impl
3 changes: 2 additions & 1 deletion man/as_membership.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_edge_betweenness.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_fast_greedy.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_fluid_communities.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_infomap.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_label_prop.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_leading_eigen.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_leiden.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_louvain.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_optimal.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_spinglass.Rd

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

3 changes: 2 additions & 1 deletion man/cluster_walktrap.Rd

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

3 changes: 2 additions & 1 deletion man/communities.Rd

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

3 changes: 2 additions & 1 deletion man/compare.Rd

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

3 changes: 2 additions & 1 deletion man/groups.Rd

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

3 changes: 2 additions & 1 deletion man/make_clusters.Rd

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

3 changes: 2 additions & 1 deletion man/modularity.igraph.Rd

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

3 changes: 2 additions & 1 deletion man/plot_dendrogram.communities.Rd

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

3 changes: 2 additions & 1 deletion man/split_join_distance.Rd

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

86 changes: 86 additions & 0 deletions man/voronoi.Rd

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

1 change: 1 addition & 0 deletions tools/stimulus/functions-R.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ igraph_distances_johnson:
igraph_distances_floyd_warshall:

igraph_voronoi:
FIRST_KW_PARAM: weights

igraph_get_all_simple_paths:
IGNORE: RR
Expand Down

0 comments on commit d40b2e7

Please sign in to comment.