From bdf530ef77a4468afc5ecf1ee95d827db8e5c838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Tue, 6 Feb 2024 19:07:13 +0000 Subject: [PATCH 01/11] feat: weight support for `eccentricity()` and `radius()` --- R/aaa-auto.R | 33 +++--------------- R/paths.R | 27 +++++--------- R/structural.properties.R | 7 ++-- man/average.path.length.Rd | 3 +- man/distances.Rd | 7 ++-- man/eccentricity.Rd | 20 +++++++++-- man/get.all.shortest.paths.Rd | 7 ++-- man/get.shortest.paths.Rd | 7 ++-- man/k_shortest_paths.Rd | 7 ++-- man/radius.Rd | 21 +++++++---- man/shortest.paths.Rd | 7 ++-- src/cpp11.cpp | 4 --- src/rinterface.c | 62 --------------------------------- tools/stimulus/functions-R.yaml | 6 ++++ 14 files changed, 76 insertions(+), 142 deletions(-) diff --git a/R/aaa-auto.R b/R/aaa-auto.R index 5199d5679b3..772f9b3b9a5 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -1749,23 +1749,9 @@ contract_vertices_impl <- function(graph, mapping, vertex.attr.comb=igraph_opt(" res } -eccentricity_impl <- function(graph, vids=V(graph), mode=c("all", "out", "in", "total")) { - # Argument checks - ensure_igraph(graph) - vids <- as_igraph_vs(graph, vids) - mode <- switch(igraph.match.arg(mode), "out"=1L, "in"=2L, "all"=3L, "total"=3L) - - on.exit( .Call(R_igraph_finalizer) ) - # Function call - res <- .Call(R_igraph_eccentricity, graph, vids-1, mode) - if (igraph_opt("add.vertex.names") && is_named(graph)) { - names(res) <- vertex_attr(graph, "name", vids) - } - res -} - -eccentricity_dijkstra_impl <- function(graph, weights=NULL, vids=V(graph), mode=c("all", "out", "in", "total")) { +eccentricity_dijkstra_impl <- function(graph, vids=V(graph), ..., weights=NULL, mode=c("all", "out", "in", "total")) { # Argument checks + check_dots_empty() ensure_igraph(graph) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight @@ -1823,20 +1809,9 @@ graph_center_dijkstra_impl <- function(graph, weights=NULL, mode=c("all", "out", res } -radius_impl <- function(graph, mode=c("all", "out", "in", "total")) { - # Argument checks - ensure_igraph(graph) - mode <- switch(igraph.match.arg(mode), "out"=1L, "in"=2L, "all"=3L, "total"=3L) - - on.exit( .Call(R_igraph_finalizer) ) - # Function call - res <- .Call(R_igraph_radius, graph, mode) - - res -} - -radius_dijkstra_impl <- function(graph, weights=NULL, mode=c("all", "out", "in", "total")) { +radius_dijkstra_impl <- function(graph, ..., weights=NULL, mode=c("all", "out", "in", "total")) { # Argument checks + check_dots_empty() ensure_igraph(graph) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight diff --git a/R/paths.R b/R/paths.R index 2ea02fbd8ce..c6bd50f9a38 100644 --- a/R/paths.R +++ b/R/paths.R @@ -242,12 +242,8 @@ max_cardinality <- maximum_cardinality_search_impl #' #' @param graph The input graph, it can be directed or undirected. #' @param vids The vertices for which the eccentricity is calculated. -#' @param mode Character constant, gives whether the shortest paths to or from -#' the given vertices should be calculated for directed graphs. If `out` -#' then the shortest paths *from* the vertex, if `in` then *to* -#' it will be considered. If `all`, the default, then the corresponding -#' undirected graph will be used, edge directions will be ignored. This -#' argument is ignored for undirected graphs. +#' @inheritParams distances +#' @inheritParams rlang::args_dots_empty #' @return `eccentricity()` returns a numeric vector, containing the #' eccentricity score of each given vertex. #' @seealso [radius()] for a related concept, @@ -259,29 +255,24 @@ max_cardinality <- maximum_cardinality_search_impl #' eccentricity(g) #' @family paths #' @export -eccentricity <- eccentricity_impl +eccentricity <- eccentricity_dijkstra_impl #' Radius of a graph #' -#' The eccentricity of a vertex is its shortest path distance from the -#' farthest other node in the graph. The smallest eccentricity in a graph -#' is called its radius +#' The eccentricity of a vertex is its distance from the farthest other node +#' in the graph. The smallest eccentricity in a graph is called its radius. #' #' The eccentricity of a vertex is calculated by measuring the shortest #' distance from (or to) the vertex, to (or from) all vertices in the #' graph, and taking the maximum. #' #' This implementation ignores vertex pairs that are in different -#' components. Isolate vertices have eccentricity zero. +#' components. Isolated vertices have eccentricity zero. #' #' @param graph The input graph, it can be directed or undirected. -#' @param mode Character constant, gives whether the shortest paths to or from -#' the given vertices should be calculated for directed graphs. If `out` -#' then the shortest paths *from* the vertex, if `in` then *to* -#' it will be considered. If `all`, the default, then the corresponding -#' undirected graph will be used, edge directions will be ignored. This -#' argument is ignored for undirected graphs. +#' @inheritParams eccentricity +#' @inheritParams rlang::args_dots_empty #' @return A numeric scalar, the radius of the graph. #' @seealso [eccentricity()] for the underlying #' calculations, [distances] for general shortest path @@ -294,7 +285,7 @@ eccentricity <- eccentricity_impl #' radius(g) #' @family paths #' @export -radius <- radius_impl +radius <- radius_dijkstra_impl #' @rdname distances #' @param directed Whether to consider directed paths in directed graphs, diff --git a/R/structural.properties.R b/R/structural.properties.R index 0f43fdca69c..f20bd742574 100644 --- a/R/structural.properties.R +++ b/R/structural.properties.R @@ -728,13 +728,14 @@ degree_distribution <- function(graph, cumulative = FALSE, ...) { #' @param mode Character constant, gives whether the shortest paths to or from #' the given vertices should be calculated for directed graphs. If `out` #' then the shortest paths *from* the vertex, if `in` then *to* -#' it will be considered. If `all`, the default, then the corresponding -#' undirected graph will be used, i.e. not directed paths are searched. This +#' it will be considered. If `all`, the default, then the graph is treated +#' as undirected, i.e. edge directions are not taken into account. This #' argument is ignored for undirected graphs. #' @param weights Possibly a numeric vector giving edge weights. If this is #' `NULL` and the graph has a `weight` edge attribute, then the #' attribute is used. If this is `NA` then no weights are used (even if -#' the graph has a `weight` attribute). +#' the graph has a `weight` attribute). In a weighted graph, the length +#' of a path is the sum of the weights of its constituent edges. #' @param algorithm Which algorithm to use for the calculation. By default #' igraph tries to select the fastest suitable algorithm. If there are no #' weights, then an unweighted breadth-first search is used, otherwise if all diff --git a/man/average.path.length.Rd b/man/average.path.length.Rd index 0ecb47a7177..833881dd9a9 100644 --- a/man/average.path.length.Rd +++ b/man/average.path.length.Rd @@ -18,7 +18,8 @@ average.path.length( \item{weights}{Possibly a numeric vector giving edge weights. If this is \code{NULL} and the graph has a \code{weight} edge attribute, then the attribute is used. If this is \code{NA} then no weights are used (even if -the graph has a \code{weight} attribute).} +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} \item{directed}{Whether to consider directed paths in directed graphs, this argument is ignored for undirected graphs.} diff --git a/man/distances.Rd b/man/distances.Rd index a5481dbeb51..1e46f8d59d3 100644 --- a/man/distances.Rd +++ b/man/distances.Rd @@ -57,7 +57,8 @@ this argument is ignored for undirected graphs.} \item{weights}{Possibly a numeric vector giving edge weights. If this is \code{NULL} and the graph has a \code{weight} edge attribute, then the attribute is used. If this is \code{NA} then no weights are used (even if -the graph has a \code{weight} attribute).} +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} \item{unconnected}{What to do if the graph is unconnected (not strongly connected if directed paths are considered). If TRUE, only @@ -81,8 +82,8 @@ is not required for \code{shortest_paths()}.} \item{mode}{Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If \code{out} then the shortest paths \emph{from} the vertex, if \verb{in} then \emph{to} -it will be considered. If \code{all}, the default, then the corresponding -undirected graph will be used, i.e. not directed paths are searched. This +it will be considered. If \code{all}, the default, then the graph is treated +as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs.} \item{algorithm}{Which algorithm to use for the calculation. By default diff --git a/man/eccentricity.Rd b/man/eccentricity.Rd index 33480743d96..bd105dc5d22 100644 --- a/man/eccentricity.Rd +++ b/man/eccentricity.Rd @@ -4,18 +4,32 @@ \alias{eccentricity} \title{Eccentricity of the vertices in a graph} \usage{ -eccentricity(graph, vids = V(graph), mode = c("all", "out", "in", "total")) +eccentricity( + graph, + vids = V(graph), + ..., + weights = NULL, + mode = c("all", "out", "in", "total") +) } \arguments{ \item{graph}{The input graph, it can be directed or undirected.} \item{vids}{The vertices for which the eccentricity is calculated.} +\item{...}{These dots are for future extensions and must be empty.} + +\item{weights}{Possibly a numeric vector giving edge weights. If this is +\code{NULL} and the graph has a \code{weight} edge attribute, then the +attribute is used. If this is \code{NA} then no weights are used (even if +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} + \item{mode}{Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If \code{out} then the shortest paths \emph{from} the vertex, if \verb{in} then \emph{to} -it will be considered. If \code{all}, the default, then the corresponding -undirected graph will be used, edge directions will be ignored. This +it will be considered. If \code{all}, the default, then the graph is treated +as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs.} } \value{ diff --git a/man/get.all.shortest.paths.Rd b/man/get.all.shortest.paths.Rd index 5d6b2ac4886..4e96cbd7344 100644 --- a/man/get.all.shortest.paths.Rd +++ b/man/get.all.shortest.paths.Rd @@ -27,14 +27,15 @@ is not required for \code{shortest_paths()}.} \item{mode}{Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If \code{out} then the shortest paths \emph{from} the vertex, if \verb{in} then \emph{to} -it will be considered. If \code{all}, the default, then the corresponding -undirected graph will be used, i.e. not directed paths are searched. This +it will be considered. If \code{all}, the default, then the graph is treated +as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs.} \item{weights}{Possibly a numeric vector giving edge weights. If this is \code{NULL} and the graph has a \code{weight} edge attribute, then the attribute is used. If this is \code{NA} then no weights are used (even if -the graph has a \code{weight} attribute).} +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} diff --git a/man/get.shortest.paths.Rd b/man/get.shortest.paths.Rd index 38077feeae4..488a420ad5b 100644 --- a/man/get.shortest.paths.Rd +++ b/man/get.shortest.paths.Rd @@ -31,14 +31,15 @@ is not required for \code{shortest_paths()}.} \item{mode}{Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If \code{out} then the shortest paths \emph{from} the vertex, if \verb{in} then \emph{to} -it will be considered. If \code{all}, the default, then the corresponding -undirected graph will be used, i.e. not directed paths are searched. This +it will be considered. If \code{all}, the default, then the graph is treated +as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs.} \item{weights}{Possibly a numeric vector giving edge weights. If this is \code{NULL} and the graph has a \code{weight} edge attribute, then the attribute is used. If this is \code{NA} then no weights are used (even if -the graph has a \code{weight} attribute).} +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} \item{output}{Character scalar, defines how to report the shortest paths. \dQuote{vpath} means that the vertices along the paths are reported, this diff --git a/man/k_shortest_paths.Rd b/man/k_shortest_paths.Rd index f8e5d3b4a03..ca54c2be225 100644 --- a/man/k_shortest_paths.Rd +++ b/man/k_shortest_paths.Rd @@ -29,13 +29,14 @@ increasing length.} \item{weights}{Possibly a numeric vector giving edge weights. If this is \code{NULL} and the graph has a \code{weight} edge attribute, then the attribute is used. If this is \code{NA} then no weights are used (even if -the graph has a \code{weight} attribute).} +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} \item{mode}{Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If \code{out} then the shortest paths \emph{from} the vertex, if \verb{in} then \emph{to} -it will be considered. If \code{all}, the default, then the corresponding -undirected graph will be used, i.e. not directed paths are searched. This +it will be considered. If \code{all}, the default, then the graph is treated +as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs.} } \value{ diff --git a/man/radius.Rd b/man/radius.Rd index f54e67ac4d5..9391173fce0 100644 --- a/man/radius.Rd +++ b/man/radius.Rd @@ -4,25 +4,32 @@ \alias{radius} \title{Radius of a graph} \usage{ -radius(graph, mode = c("all", "out", "in", "total")) +radius(graph, ..., weights = NULL, mode = c("all", "out", "in", "total")) } \arguments{ \item{graph}{The input graph, it can be directed or undirected.} +\item{...}{These dots are for future extensions and must be empty.} + +\item{weights}{Possibly a numeric vector giving edge weights. If this is +\code{NULL} and the graph has a \code{weight} edge attribute, then the +attribute is used. If this is \code{NA} then no weights are used (even if +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} + \item{mode}{Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If \code{out} then the shortest paths \emph{from} the vertex, if \verb{in} then \emph{to} -it will be considered. If \code{all}, the default, then the corresponding -undirected graph will be used, edge directions will be ignored. This +it will be considered. If \code{all}, the default, then the graph is treated +as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs.} } \value{ A numeric scalar, the radius of the graph. } \description{ -The eccentricity of a vertex is its shortest path distance from the -farthest other node in the graph. The smallest eccentricity in a graph -is called its radius +The eccentricity of a vertex is its distance from the farthest other node +in the graph. The smallest eccentricity in a graph is called its radius. } \details{ The eccentricity of a vertex is calculated by measuring the shortest @@ -30,7 +37,7 @@ distance from (or to) the vertex, to (or from) all vertices in the graph, and taking the maximum. This implementation ignores vertex pairs that are in different -components. Isolate vertices have eccentricity zero. +components. Isolated vertices have eccentricity zero. } \examples{ g <- make_star(10, mode = "undirected") diff --git a/man/shortest.paths.Rd b/man/shortest.paths.Rd index 40394f4051a..f4e4ca173fb 100644 --- a/man/shortest.paths.Rd +++ b/man/shortest.paths.Rd @@ -27,14 +27,15 @@ is not required for \code{shortest_paths()}.} \item{mode}{Character constant, gives whether the shortest paths to or from the given vertices should be calculated for directed graphs. If \code{out} then the shortest paths \emph{from} the vertex, if \verb{in} then \emph{to} -it will be considered. If \code{all}, the default, then the corresponding -undirected graph will be used, i.e. not directed paths are searched. This +it will be considered. If \code{all}, the default, then the graph is treated +as undirected, i.e. edge directions are not taken into account. This argument is ignored for undirected graphs.} \item{weights}{Possibly a numeric vector giving edge weights. If this is \code{NULL} and the graph has a \code{weight} edge attribute, then the attribute is used. If this is \code{NA} then no weights are used (even if -the graph has a \code{weight} attribute).} +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} \item{algorithm}{Which algorithm to use for the calculation. By default igraph tries to select the fastest suitable algorithm. If there are no diff --git a/src/cpp11.cpp b/src/cpp11.cpp index 69569d526b4..9b42456c8d5 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -145,7 +145,6 @@ extern SEXP R_igraph_dominator_tree(void *, void *, void *); extern SEXP R_igraph_dot_product_game(void *, void *); extern SEXP R_igraph_dyad_census(void *); extern SEXP R_igraph_ecc(void *, void *, void *, void *, void *); -extern SEXP R_igraph_eccentricity(void *, void *, void *); extern SEXP R_igraph_eccentricity_dijkstra(void *, void *, void *, void *); extern SEXP R_igraph_ecount(void *); extern SEXP R_igraph_edge_betweenness_cutoff(void *, void *, void *, void *); @@ -361,7 +360,6 @@ extern SEXP R_igraph_power_law_fit(void *, void *, void *); extern SEXP R_igraph_preference_game(void *, void *, void *, void *, void *, void *, void *); extern SEXP R_igraph_pseudo_diameter(void *, void *, void *, void *); extern SEXP R_igraph_pseudo_diameter_dijkstra(void *, void *, void *, void *, void *); -extern SEXP R_igraph_radius(void *, void *); extern SEXP R_igraph_radius_dijkstra(void *, void *, void *); extern SEXP R_igraph_random_edge_walk(void *, void *, void *, void *, void *, void *); extern SEXP R_igraph_random_sample(void *, void *, void *); @@ -605,7 +603,6 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_dot_product_game", (DL_FUNC) &R_igraph_dot_product_game, 2}, {"R_igraph_dyad_census", (DL_FUNC) &R_igraph_dyad_census, 1}, {"R_igraph_ecc", (DL_FUNC) &R_igraph_ecc, 5}, - {"R_igraph_eccentricity", (DL_FUNC) &R_igraph_eccentricity, 3}, {"R_igraph_eccentricity_dijkstra", (DL_FUNC) &R_igraph_eccentricity_dijkstra, 4}, {"R_igraph_ecount", (DL_FUNC) &R_igraph_ecount, 1}, {"R_igraph_edge_betweenness_cutoff", (DL_FUNC) &R_igraph_edge_betweenness_cutoff, 4}, @@ -821,7 +818,6 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_preference_game", (DL_FUNC) &R_igraph_preference_game, 7}, {"R_igraph_pseudo_diameter", (DL_FUNC) &R_igraph_pseudo_diameter, 4}, {"R_igraph_pseudo_diameter_dijkstra", (DL_FUNC) &R_igraph_pseudo_diameter_dijkstra, 5}, - {"R_igraph_radius", (DL_FUNC) &R_igraph_radius, 2}, {"R_igraph_radius_dijkstra", (DL_FUNC) &R_igraph_radius_dijkstra, 3}, {"R_igraph_random_edge_walk", (DL_FUNC) &R_igraph_random_edge_walk, 6}, {"R_igraph_random_sample", (DL_FUNC) &R_igraph_random_sample, 3}, diff --git a/src/rinterface.c b/src/rinterface.c index a1973d73a6d..efc4098ca85 100644 --- a/src/rinterface.c +++ b/src/rinterface.c @@ -4893,42 +4893,6 @@ SEXP R_igraph_contract_vertices(SEXP graph, SEXP mapping, SEXP vertex_attr_comb) return(r_result); } -/*-------------------------------------------/ -/ igraph_eccentricity / -/-------------------------------------------*/ -SEXP R_igraph_eccentricity(SEXP graph, SEXP vids, SEXP mode) { - /* Declarations */ - igraph_t c_graph; - igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - SEXP res; - - SEXP r_result; - /* Convert input */ - R_SEXP_to_igraph(graph, &c_graph); - if (0 != igraph_vector_init(&c_res, 0)) { - igraph_error("", __FILE__, __LINE__, IGRAPH_ENOMEM); - } - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - R_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - /* Call igraph */ - IGRAPH_R_CHECK(igraph_eccentricity(&c_graph, &c_res, c_vids, c_mode)); - - /* Convert output */ - PROTECT(res=R_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - r_result = res; - - UNPROTECT(1); - return(r_result); -} - /*-------------------------------------------/ / igraph_eccentricity_dijkstra / /-------------------------------------------*/ @@ -5031,32 +4995,6 @@ SEXP R_igraph_graph_center_dijkstra(SEXP graph, SEXP weights, SEXP mode) { return(r_result); } -/*-------------------------------------------/ -/ igraph_radius / -/-------------------------------------------*/ -SEXP R_igraph_radius(SEXP graph, SEXP mode) { - /* Declarations */ - igraph_t c_graph; - igraph_real_t c_radius; - igraph_neimode_t c_mode; - SEXP radius; - - SEXP r_result; - /* Convert input */ - R_SEXP_to_igraph(graph, &c_graph); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - /* Call igraph */ - IGRAPH_R_CHECK(igraph_radius(&c_graph, &c_radius, c_mode)); - - /* Convert output */ - PROTECT(radius=NEW_NUMERIC(1)); - REAL(radius)[0]=c_radius; - r_result = radius; - - UNPROTECT(1); - return(r_result); -} - /*-------------------------------------------/ / igraph_radius_dijkstra / /-------------------------------------------*/ diff --git a/tools/stimulus/functions-R.yaml b/tools/stimulus/functions-R.yaml index b03cfae9648..01bfd1e471b 100644 --- a/tools/stimulus/functions-R.yaml +++ b/tools/stimulus/functions-R.yaml @@ -608,17 +608,23 @@ igraph_joint_type_distribution: igraph_contract_vertices: +# We use igraph_eccentricity_dijkstra instead igraph_eccentricity: + IGNORE: RR, RC igraph_eccentricity_dijkstra: + PARAM_ORDER: graph, vids, *, weights, ... igraph_graph_center: igraph_graph_center_dijkstra: +# We use igraph_radius_dijkstra instead igraph_radius: + IGNORE: RR, RC igraph_radius_dijkstra: + FIRST_KW_PARAM: weights igraph_pseudo_diameter: DEPS: start_vid ON graph From 84213acb2296309b8abfc2672371f39adb5047cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Tue, 6 Feb 2024 19:43:22 +0000 Subject: [PATCH 02/11] feat: `graph_center()` returns the central vertices of a graph --- NAMESPACE | 1 + R/aaa-auto.R | 17 ++----------- R/paths.R | 15 +++++++++++ man/all_simple_paths.Rd | 1 + man/diameter.Rd | 1 + man/distances.Rd | 1 + man/eccentricity.Rd | 1 + man/graph_center.Rd | 45 +++++++++++++++++++++++++++++++++ man/radius.Rd | 3 ++- src/cpp11.cpp | 2 -- src/rinterface.c | 31 ----------------------- tools/stimulus/functions-R.yaml | 3 +++ 12 files changed, 72 insertions(+), 49 deletions(-) create mode 100644 man/graph_center.Rd diff --git a/NAMESPACE b/NAMESPACE index e1c4ab5393f..25b0c0238bd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -439,6 +439,7 @@ export(graph.union) export(graph_) export(graph_attr) export(graph_attr_names) +export(graph_center) export(graph_from_adj_list) export(graph_from_adjacency_matrix) export(graph_from_atlas) diff --git a/R/aaa-auto.R b/R/aaa-auto.R index 772f9b3b9a5..de65bee31c7 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -1773,22 +1773,9 @@ eccentricity_dijkstra_impl <- function(graph, vids=V(graph), ..., weights=NULL, res } -graph_center_impl <- function(graph, mode=c("all", "out", "in", "total")) { - # Argument checks - ensure_igraph(graph) - mode <- switch(igraph.match.arg(mode), "out"=1L, "in"=2L, "all"=3L, "total"=3L) - - on.exit( .Call(R_igraph_finalizer) ) - # Function call - res <- .Call(R_igraph_graph_center, graph, mode) - if (igraph_opt("return.vs.es")) { - res <- create_vs(graph, res) - } - res -} - -graph_center_dijkstra_impl <- function(graph, weights=NULL, mode=c("all", "out", "in", "total")) { +graph_center_dijkstra_impl <- function(graph, ..., weights=NULL, mode=c("all", "out", "in", "total")) { # Argument checks + check_dots_empty() ensure_igraph(graph) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight diff --git a/R/paths.R b/R/paths.R index c6bd50f9a38..547d8c007ef 100644 --- a/R/paths.R +++ b/R/paths.R @@ -287,6 +287,21 @@ eccentricity <- eccentricity_dijkstra_impl #' @export radius <- radius_dijkstra_impl +#' Central vertices of a graph +#' +#' @description +#' `r lifecycle::badge("experimental")` +#' +#' The center of a graph is the set of its vertices with minimal eccentricity. +#' +#' @inheritParams eccentricity +#' @inheritParams rlang::args_dots_empty +#' @return The vertex IDs of the central vertices. +#' @seealso [eccentricity()], [radius()] +#' @family paths +#' @export +graph_center <- graph_center_dijkstra_impl + #' @rdname distances #' @param directed Whether to consider directed paths in directed graphs, #' this argument is ignored for undirected graphs. diff --git a/man/all_simple_paths.Rd b/man/all_simple_paths.Rd index 0bba46fb2cb..f08193d093b 100644 --- a/man/all_simple_paths.Rd +++ b/man/all_simple_paths.Rd @@ -57,6 +57,7 @@ Other paths: \code{\link{diameter}()}, \code{\link{distance_table}()}, \code{\link{eccentricity}()}, +\code{\link{graph_center}()}, \code{\link{radius}()} } \concept{paths} diff --git a/man/diameter.Rd b/man/diameter.Rd index f791e616f87..0b249648fad 100644 --- a/man/diameter.Rd +++ b/man/diameter.Rd @@ -73,6 +73,7 @@ Other paths: \code{\link{all_simple_paths}()}, \code{\link{distance_table}()}, \code{\link{eccentricity}()}, +\code{\link{graph_center}()}, \code{\link{radius}()} } \author{ diff --git a/man/distances.Rd b/man/distances.Rd index 1e46f8d59d3..6a956e97ca6 100644 --- a/man/distances.Rd +++ b/man/distances.Rd @@ -292,6 +292,7 @@ Other paths: \code{\link{all_simple_paths}()}, \code{\link{diameter}()}, \code{\link{eccentricity}()}, +\code{\link{graph_center}()}, \code{\link{radius}()} } \author{ diff --git a/man/eccentricity.Rd b/man/eccentricity.Rd index bd105dc5d22..c52b65f5c04 100644 --- a/man/eccentricity.Rd +++ b/man/eccentricity.Rd @@ -64,6 +64,7 @@ Other paths: \code{\link{all_simple_paths}()}, \code{\link{diameter}()}, \code{\link{distance_table}()}, +\code{\link{graph_center}()}, \code{\link{radius}()} } \concept{paths} diff --git a/man/graph_center.Rd b/man/graph_center.Rd new file mode 100644 index 00000000000..ca6b9618409 --- /dev/null +++ b/man/graph_center.Rd @@ -0,0 +1,45 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/paths.R +\name{graph_center} +\alias{graph_center} +\title{Central vertices of a graph} +\usage{ +graph_center(graph, ..., weights = NULL, mode = c("all", "out", "in", "total")) +} +\arguments{ +\item{graph}{The input graph, it can be directed or undirected.} + +\item{...}{These dots are for future extensions and must be empty.} + +\item{weights}{Possibly a numeric vector giving edge weights. If this is +\code{NULL} and the graph has a \code{weight} edge attribute, then the +attribute is used. If this is \code{NA} then no weights are used (even if +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} + +\item{mode}{Character constant, gives whether the shortest paths to or from +the given vertices should be calculated for directed graphs. If \code{out} +then the shortest paths \emph{from} the vertex, if \verb{in} then \emph{to} +it will be considered. If \code{all}, the default, then the graph is treated +as undirected, i.e. edge directions are not taken into account. This +argument is ignored for undirected graphs.} +} +\value{ +The vertex IDs of the central vertices. +} +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} + +The center of a graph is the set of its vertices with minimal eccentricity. +} +\seealso{ +\code{\link[=eccentricity]{eccentricity()}}, \code{\link[=radius]{radius()}} + +Other paths: +\code{\link{all_simple_paths}()}, +\code{\link{diameter}()}, +\code{\link{distance_table}()}, +\code{\link{eccentricity}()}, +\code{\link{radius}()} +} +\concept{paths} diff --git a/man/radius.Rd b/man/radius.Rd index 9391173fce0..5fdfa592b46 100644 --- a/man/radius.Rd +++ b/man/radius.Rd @@ -57,6 +57,7 @@ Other paths: \code{\link{all_simple_paths}()}, \code{\link{diameter}()}, \code{\link{distance_table}()}, -\code{\link{eccentricity}()} +\code{\link{eccentricity}()}, +\code{\link{graph_center}()} } \concept{paths} diff --git a/src/cpp11.cpp b/src/cpp11.cpp index 9b42456c8d5..2ce654ba8c3 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -209,7 +209,6 @@ extern SEXP R_igraph_get_widest_paths(void *, void *, void *, void *, void *); extern SEXP R_igraph_girth(void *, void *); extern SEXP R_igraph_global_efficiency(void *, void *, void *); extern SEXP R_igraph_gomory_hu_tree(void *, void *); -extern SEXP R_igraph_graph_center(void *, void *); extern SEXP R_igraph_graph_center_dijkstra(void *, void *, void *); extern SEXP R_igraph_graph_count(void *, void *); extern SEXP R_igraph_graph_power(void *, void *, void *); @@ -667,7 +666,6 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_girth", (DL_FUNC) &R_igraph_girth, 2}, {"R_igraph_global_efficiency", (DL_FUNC) &R_igraph_global_efficiency, 3}, {"R_igraph_gomory_hu_tree", (DL_FUNC) &R_igraph_gomory_hu_tree, 2}, - {"R_igraph_graph_center", (DL_FUNC) &R_igraph_graph_center, 2}, {"R_igraph_graph_center_dijkstra", (DL_FUNC) &R_igraph_graph_center_dijkstra, 3}, {"R_igraph_graph_count", (DL_FUNC) &R_igraph_graph_count, 2}, {"R_igraph_graph_power", (DL_FUNC) &R_igraph_graph_power, 3}, diff --git a/src/rinterface.c b/src/rinterface.c index efc4098ca85..2f2c87f8f7b 100644 --- a/src/rinterface.c +++ b/src/rinterface.c @@ -4931,37 +4931,6 @@ SEXP R_igraph_eccentricity_dijkstra(SEXP graph, SEXP weights, SEXP vids, SEXP mo return(r_result); } -/*-------------------------------------------/ -/ igraph_graph_center / -/-------------------------------------------*/ -SEXP R_igraph_graph_center(SEXP graph, SEXP mode) { - /* Declarations */ - igraph_t c_graph; - igraph_vector_int_t c_res; - igraph_neimode_t c_mode; - SEXP res; - - SEXP r_result; - /* Convert input */ - R_SEXP_to_igraph(graph, &c_graph); - if (0 != igraph_vector_int_init(&c_res, 0)) { - igraph_error("", __FILE__, __LINE__, IGRAPH_ENOMEM); - } - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - /* Call igraph */ - IGRAPH_R_CHECK(igraph_graph_center(&c_graph, &c_res, c_mode)); - - /* Convert output */ - PROTECT(res=R_igraph_vector_int_to_SEXPp1(&c_res)); - igraph_vector_int_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - r_result = res; - - UNPROTECT(1); - return(r_result); -} - /*-------------------------------------------/ / igraph_graph_center_dijkstra / /-------------------------------------------*/ diff --git a/tools/stimulus/functions-R.yaml b/tools/stimulus/functions-R.yaml index 01bfd1e471b..4813bd00009 100644 --- a/tools/stimulus/functions-R.yaml +++ b/tools/stimulus/functions-R.yaml @@ -615,9 +615,12 @@ igraph_eccentricity: igraph_eccentricity_dijkstra: PARAM_ORDER: graph, vids, *, weights, ... +# We use igraph_graph_center_dijkstra instead igraph_graph_center: + IGNORE: RR, RC igraph_graph_center_dijkstra: + FIRST_KW_PARAM: weights # We use igraph_radius_dijkstra instead igraph_radius: From ec5e2681846e725ca9eb9947d228c98f63136790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 18 Mar 2024 14:50:45 +0100 Subject: [PATCH 03/11] radius() including tests --- R/paths.R | 25 ++++++++++++++++++++++++- tests/testthat/_snaps/paths.md | 11 +++++++++++ tests/testthat/test-paths.R | 24 ++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/_snaps/paths.md create mode 100644 tests/testthat/test-paths.R diff --git a/R/paths.R b/R/paths.R index 547d8c007ef..4d8ba4fd324 100644 --- a/R/paths.R +++ b/R/paths.R @@ -285,7 +285,30 @@ eccentricity <- eccentricity_dijkstra_impl #' radius(g) #' @family paths #' @export -radius <- radius_dijkstra_impl +radius <- function(graph, ..., weights = NULL, mode = c("all", "out", "in", "total")) { + if (...length() > 0) { + lifecycle::deprecate_soft( + "2.0.2", + "radius(... =)", + details = "The arguments `weights` and `mode` must be named." + ) + + rlang::check_dots_unnamed() + + dots <- list(...) + + if (is.null(weights) && length(dots) > 0) { + weights <- dots[[1]] + dots <- dots[-1] + } + + if (missing(mode) && length(dots) > 0) { + mode <- dots[[1]] + } + } + + radius_dijkstra_impl(graph, weights = weights, mode = mode) +} #' Central vertices of a graph #' diff --git a/tests/testthat/_snaps/paths.md b/tests/testthat/_snaps/paths.md new file mode 100644 index 00000000000..bd92e641df4 --- /dev/null +++ b/tests/testthat/_snaps/paths.md @@ -0,0 +1,11 @@ +# radius() works -- lifecycle + + Code + radius(g, NULL, "out") + Condition + Warning: + The `...` argument of `radius()` is deprecated as of igraph 2.0.2. + i The arguments `weights` and `mode` must be named. + Output + [1] 0 + diff --git a/tests/testthat/test-paths.R b/tests/testthat/test-paths.R new file mode 100644 index 00000000000..177f9a8ee1b --- /dev/null +++ b/tests/testthat/test-paths.R @@ -0,0 +1,24 @@ +test_that("radius() works", { + withr::local_seed(42) + g <- make_tree(10, 2) + + expect_equal(radius(g), 3) + expect_equal(radius(g, mode = "in"), 0) + expect_equal(radius(g, mode = "out"), 0) +}) + +test_that("radius() works -- weights", { + g <- make_ring(10) + expect_equal(radius(g), 5) + + E(g)$weight <- seq_len(ecount(g)) + expect_equal(radius(g), 24) +}) + +test_that("radius() works -- lifecycle", { + withr::local_seed(42) + g <- make_tree(10, 2) + + expect_snapshot(radius(g, NULL, "out")) + +}) From c60f7cdbec46ac1ac40b9a0618c2e8008f25c772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 18 Mar 2024 14:58:00 +0100 Subject: [PATCH 04/11] eccentricity() + tests --- R/paths.R | 25 ++++++++++++++++++++++++- tests/testthat/_snaps/paths.md | 11 +++++++++++ tests/testthat/test-paths.R | 26 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/R/paths.R b/R/paths.R index 4d8ba4fd324..c680a3b3884 100644 --- a/R/paths.R +++ b/R/paths.R @@ -255,7 +255,30 @@ max_cardinality <- maximum_cardinality_search_impl #' eccentricity(g) #' @family paths #' @export -eccentricity <- eccentricity_dijkstra_impl +eccentricity <- function(graph, vids = V(graph), ..., weights = NULL, mode = c("all", "out", "in", "total")) { + if (...length() > 0) { + lifecycle::deprecate_soft( + "2.0.2", + "eccentricity(... =)", + details = "The arguments `weights` and `mode` must be named." + ) + + rlang::check_dots_unnamed() + + dots <- list(...) + + if (is.null(weights) && length(dots) > 0) { + weights <- dots[[1]] + dots <- dots[-1] + } + + if (missing(mode) && length(dots) > 0) { + mode <- dots[[1]] + } + } + + eccentricity_dijkstra_impl(graph, vids = vids, weights = weights, mode = mode) +} #' Radius of a graph diff --git a/tests/testthat/_snaps/paths.md b/tests/testthat/_snaps/paths.md index bd92e641df4..466cc397486 100644 --- a/tests/testthat/_snaps/paths.md +++ b/tests/testthat/_snaps/paths.md @@ -9,3 +9,14 @@ Output [1] 0 +# eccentricity() works -- lifecycle + + Code + eccentricity(g, vids = V(g), NULL, "out") + Condition + Warning: + The `...` argument of `eccentricity()` is deprecated as of igraph 2.0.2. + i The arguments `weights` and `mode` must be named. + Output + [1] 3 2 1 1 1 0 0 0 0 0 + diff --git a/tests/testthat/test-paths.R b/tests/testthat/test-paths.R index 177f9a8ee1b..bedf2faea91 100644 --- a/tests/testthat/test-paths.R +++ b/tests/testthat/test-paths.R @@ -22,3 +22,29 @@ test_that("radius() works -- lifecycle", { expect_snapshot(radius(g, NULL, "out")) }) + +test_that("eccentricity() works", { + withr::local_seed(42) + g <- make_tree(10, 2) + + expect_equal(eccentricity(g), c(3, 3, 4, 4, 4, 5, 5, 5, 5, 5)) + expect_equal(eccentricity(g, mode = "in"), c(0, 1, 1, 2, 2, 2, 2, 3, 3, 3)) + expect_equal(eccentricity(g, mode = "out"), c(3, 2, 1, 1, 1, 0, 0, 0, 0, 0)) +}) + +test_that("eccentricity() works -- weights", { + g <- make_ring(10) + expect_equal(eccentricity(g), rep(5, 10)) + + E(g)$weight <- seq_len(ecount(g)) + expect_equal(eccentricity(g), c(27, 27, 25, 25, 26, 25, 24, 27, 26, 25)) +}) + +test_that("eccentricity() works -- lifecycle", { + withr::local_seed(42) + g <- make_tree(10, 2) + + expect_snapshot(eccentricity(g, vids = V(g), NULL, "out")) + +}) + From 572845fb1c3a65e9e06c1f4c673f29b927c85dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 18 Mar 2024 15:11:36 +0100 Subject: [PATCH 05/11] tests for graph_center() --- tests/testthat/test-paths.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test-paths.R b/tests/testthat/test-paths.R index bedf2faea91..af1fb4030d9 100644 --- a/tests/testthat/test-paths.R +++ b/tests/testthat/test-paths.R @@ -48,3 +48,20 @@ test_that("eccentricity() works -- lifecycle", { }) +test_that("graph_center() works", { + withr::local_seed(42) + g <- make_tree(100, 7) + expect_equal(as.numeric(graph_center(g)), c(1, 2)) + expect_equal(as.numeric(graph_center(g, mode = "in")), 1) + expect_equal(as.numeric(graph_center(g, mode = "out")), 16:100) + +}) + +test_that("graph_center() works -- weights", { + g <- make_ring(10) + expect_equal(as.numeric(graph_center(g)), 1:10) + + E(g)$weight <- seq_len(ecount(g)) + expect_equal(as.numeric(graph_center(g)), 7) +}) + From 7cbc3709eb1edf8d51504f1992b30a17f7197346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 22 Mar 2024 11:04:38 +0100 Subject: [PATCH 06/11] Update R/paths.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kirill Müller --- R/paths.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/paths.R b/R/paths.R index c680a3b3884..59843a59eec 100644 --- a/R/paths.R +++ b/R/paths.R @@ -258,7 +258,7 @@ max_cardinality <- maximum_cardinality_search_impl eccentricity <- function(graph, vids = V(graph), ..., weights = NULL, mode = c("all", "out", "in", "total")) { if (...length() > 0) { lifecycle::deprecate_soft( - "2.0.2", + "2.1.0", "eccentricity(... =)", details = "The arguments `weights` and `mode` must be named." ) From df6e2054efc82628a18294e8a653d836b70e8917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 22 Mar 2024 11:08:52 +0100 Subject: [PATCH 07/11] fix version number --- R/paths.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/paths.R b/R/paths.R index 59843a59eec..fa2e701ad34 100644 --- a/R/paths.R +++ b/R/paths.R @@ -311,7 +311,7 @@ eccentricity <- function(graph, vids = V(graph), ..., weights = NULL, mode = c(" radius <- function(graph, ..., weights = NULL, mode = c("all", "out", "in", "total")) { if (...length() > 0) { lifecycle::deprecate_soft( - "2.0.2", + "2.1.0", "radius(... =)", details = "The arguments `weights` and `mode` must be named." ) From 165da0983ee9d405009b45caee9f405e6ee086ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 22 Mar 2024 11:21:33 +0100 Subject: [PATCH 08/11] add example for graph_center() --- R/paths.R | 13 +++++++++++++ man/graph_center.Rd | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/R/paths.R b/R/paths.R index fa2e701ad34..59a8d304083 100644 --- a/R/paths.R +++ b/R/paths.R @@ -345,6 +345,19 @@ radius <- function(graph, ..., weights = NULL, mode = c("all", "out", "in", "tot #' @return The vertex IDs of the central vertices. #' @seealso [eccentricity()], [radius()] #' @family paths +#' @examples +#' tree <- make_tree(100, 7) +#' graph_center(tree) +#' graph_center(tree, mode = "in") +#' graph_center(tree, mode = "out") +#' +#' # Without and with weights +#' ring <- make_ring(10) +#' graph_center(g)) +#' # Add weights +#' E(g)$weight <- seq_len(ecount(g)) +#' graph_center(g) +#' #' @export graph_center <- graph_center_dijkstra_impl diff --git a/man/graph_center.Rd b/man/graph_center.Rd index ca6b9618409..09c5856c281 100644 --- a/man/graph_center.Rd +++ b/man/graph_center.Rd @@ -31,6 +31,20 @@ The vertex IDs of the central vertices. \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} The center of a graph is the set of its vertices with minimal eccentricity. +} +\examples{ +tree <- make_tree(100, 7) +graph_center(tree) +graph_center(tree, mode = "in") +graph_center(tree, mode = "out") + +# Without and with weights +ring <- make_ring(10) +graph_center(g)) +# Add weights +E(g)$weight <- seq_len(ecount(g)) +graph_center(g) + } \seealso{ \code{\link[=eccentricity]{eccentricity()}}, \code{\link[=radius]{radius()}} From b23993489bcb0a6392f1b5146cde3f0dc8a549eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 22 Mar 2024 11:40:06 +0100 Subject: [PATCH 09/11] update snap --- tests/testthat/_snaps/paths.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/_snaps/paths.md b/tests/testthat/_snaps/paths.md index 466cc397486..751a5d6b2b5 100644 --- a/tests/testthat/_snaps/paths.md +++ b/tests/testthat/_snaps/paths.md @@ -4,7 +4,7 @@ radius(g, NULL, "out") Condition Warning: - The `...` argument of `radius()` is deprecated as of igraph 2.0.2. + The `...` argument of `radius()` is deprecated as of igraph 2.1.0. i The arguments `weights` and `mode` must be named. Output [1] 0 @@ -15,7 +15,7 @@ eccentricity(g, vids = V(g), NULL, "out") Condition Warning: - The `...` argument of `eccentricity()` is deprecated as of igraph 2.0.2. + The `...` argument of `eccentricity()` is deprecated as of igraph 2.1.0. i The arguments `weights` and `mode` must be named. Output [1] 3 2 1 1 1 0 0 0 0 0 From a50883e3654bc728b66e3fbbfa4f47e9b85ba468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 25 Mar 2024 14:01:04 +0100 Subject: [PATCH 10/11] fix: remove stay parenthesis in example code --- R/paths.R | 2 +- man/graph_center.Rd | 2 +- man/voronoi_cells.Rd | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/R/paths.R b/R/paths.R index 59a8d304083..0896fb8f234 100644 --- a/R/paths.R +++ b/R/paths.R @@ -353,7 +353,7 @@ radius <- function(graph, ..., weights = NULL, mode = c("all", "out", "in", "tot #' #' # Without and with weights #' ring <- make_ring(10) -#' graph_center(g)) +#' graph_center(g) #' # Add weights #' E(g)$weight <- seq_len(ecount(g)) #' graph_center(g) diff --git a/man/graph_center.Rd b/man/graph_center.Rd index 09c5856c281..f8f01e2d4ca 100644 --- a/man/graph_center.Rd +++ b/man/graph_center.Rd @@ -40,7 +40,7 @@ graph_center(tree, mode = "out") # Without and with weights ring <- make_ring(10) -graph_center(g)) +graph_center(g) # Add weights E(g)$weight <- seq_len(ecount(g)) graph_center(g) diff --git a/man/voronoi_cells.Rd b/man/voronoi_cells.Rd index ffd2619e515..8c0d7336524 100644 --- a/man/voronoi_cells.Rd +++ b/man/voronoi_cells.Rd @@ -23,7 +23,8 @@ voronoi_cells( \item{weights}{Possibly a numeric vector giving edge weights. If this is \code{NULL} and the graph has a \code{weight} edge attribute, then the attribute is used. If this is \code{NA} then no weights are used (even if -the graph has a \code{weight} attribute).} +the graph has a \code{weight} attribute). In a weighted graph, the length +of a path is the sum of the weights of its constituent edges.} \item{mode}{Character string. In directed graphs, whether to compute distances from generator vertices to other vertices (\code{"out"}), to From 1943c265ec846964d68916afcd92ed7c0bf14fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Mon, 25 Mar 2024 14:11:44 +0100 Subject: [PATCH 11/11] fix: use right names in example --- R/paths.R | 6 +++--- man/graph_center.Rd | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/paths.R b/R/paths.R index 0896fb8f234..28db6ed5db9 100644 --- a/R/paths.R +++ b/R/paths.R @@ -353,10 +353,10 @@ radius <- function(graph, ..., weights = NULL, mode = c("all", "out", "in", "tot #' #' # Without and with weights #' ring <- make_ring(10) -#' graph_center(g) +#' graph_center(ring) #' # Add weights -#' E(g)$weight <- seq_len(ecount(g)) -#' graph_center(g) +#' E(ring)$weight <- seq_len(ecount(ring)) +#' graph_center(ring) #' #' @export graph_center <- graph_center_dijkstra_impl diff --git a/man/graph_center.Rd b/man/graph_center.Rd index f8f01e2d4ca..d2d1f8449a6 100644 --- a/man/graph_center.Rd +++ b/man/graph_center.Rd @@ -40,10 +40,10 @@ graph_center(tree, mode = "out") # Without and with weights ring <- make_ring(10) -graph_center(g) +graph_center(ring) # Add weights -E(g)$weight <- seq_len(ecount(g)) -graph_center(g) +E(ring)$weight <- seq_len(ecount(ring)) +graph_center(ring) } \seealso{