diff --git a/R/aaa-auto.R b/R/aaa-auto.R index 6038a88e11..3b179f5919 100644 --- a/R/aaa-auto.R +++ b/R/aaa-auto.R @@ -38,6 +38,25 @@ add_edges_impl <- function( res } +empty_attrs_impl <- function( + n, + directed +) { + # Argument checks + n <- as.numeric(n) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_empty_attrs, + n, + directed + ) + + res +} + add_vertices_impl <- function( graph, nv @@ -245,6 +264,25 @@ degree_impl <- function( res } +edge_impl <- function( + graph, + eid +) { + # Argument checks + ensure_igraph(graph) + eid <- as.numeric(eid) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_edge, + graph, + eid + ) + + res +} + edges_impl <- function( graph, eids @@ -266,6 +304,32 @@ edges_impl <- function( res } +get_eids_impl <- function( + graph, + pairs, + directed = TRUE, + error = TRUE +) { + # Argument checks + ensure_igraph(graph) + directed <- as.logical(directed) + error <- as.logical(error) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_get_eids, + graph, + pairs, + directed, + error + ) + if (igraph_opt("return.vs.es")) { + res <- create_es(graph, res) + } + res +} + get_all_eids_between_impl <- function( graph, from, @@ -341,6 +405,137 @@ incident_impl <- function( res } +is_same_graph_impl <- function( + graph1, + graph2 +) { + # Argument checks + ensure_igraph(graph1) + ensure_igraph(graph2) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_is_same_graph, + graph1, + graph2 + ) + + res +} + +create_impl <- function( + edges, + n = 0, + directed = TRUE +) { + # Argument checks + edges <- as.numeric(edges) + n <- as.numeric(n) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_create, + edges, + n, + directed + ) + + res +} + +adjacency_impl <- function( + adjmatrix, + mode = c("directed", "undirected", "upper", "lower", "min", "plus", "max"), + loops = c("once", "none", "twice") +) { + # Argument checks + adjmatrix[] <- as.numeric(adjmatrix) + mode <- switch_igraph_arg( + mode, + "directed" = 0L, + "undirected" = 1L, + "upper" = 2L, + "lower" = 3L, + "min" = 4L, + "plus" = 5L, + "max" = 6L + ) + loops <- switch_igraph_arg(loops, "none" = 0L, "twice" = 1L, "once" = 2L) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_adjacency, + adjmatrix, + mode, + loops + ) + + res +} + +weighted_adjacency_impl <- function( + adjmatrix, + mode = c("directed", "undirected", "upper", "lower", "min", "plus", "max"), + loops = c("once", "none", "twice") +) { + # Argument checks + adjmatrix[] <- as.numeric(adjmatrix) + mode <- switch_igraph_arg( + mode, + "directed" = 0L, + "undirected" = 1L, + "upper" = 2L, + "lower" = 3L, + "min" = 4L, + "plus" = 5L, + "max" = 6L + ) + loops <- switch_igraph_arg(loops, "none" = 0L, "twice" = 1L, "once" = 2L) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_weighted_adjacency, + adjmatrix, + mode, + loops + ) + + res +} + +star_impl <- function( + n, + mode = c("out", "in", "undirected", "mutual"), + center = 0 +) { + # Argument checks + n <- as.numeric(n) + mode <- switch_igraph_arg( + mode, + "out" = 0L, + "in" = 1L, + "undirected" = 2L, + "mutual" = 3L + ) + center <- as.numeric(center) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_star, + n, + mode, + center + ) + + res +} + wheel_impl <- function( n, mode = c("out", "in", "undirected", "mutual"), @@ -440,6 +635,31 @@ triangular_lattice_impl <- function( res } +ring_impl <- function( + n, + directed = FALSE, + mutual = FALSE, + circular = TRUE +) { + # Argument checks + n <- as.numeric(n) + directed <- as.logical(directed) + mutual <- as.logical(mutual) + circular <- as.logical(circular) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_ring, + n, + directed, + mutual, + circular + ) + + res +} + path_graph_impl <- function( n, directed = FALSE, @@ -484,6 +704,28 @@ cycle_graph_impl <- function( res } +kary_tree_impl <- function( + n, + children = 2, + type = c("out", "in", "undirected") +) { + # Argument checks + n <- as.numeric(n) + children <- as.numeric(children) + type <- switch_igraph_arg(type, "out" = 0L, "in" = 1L, "undirected" = 2L) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_kary_tree, + n, + children, + type + ) + + res +} + symmetric_tree_impl <- function( branches, type = c("out", "in", "undirected") @@ -525,6 +767,28 @@ regular_tree_impl <- function( res } +full_impl <- function( + n, + directed = FALSE, + loops = FALSE +) { + # Argument checks + n <- as.numeric(n) + directed <- as.logical(directed) + loops <- as.logical(loops) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_full, + n, + directed, + loops + ) + + res +} + full_citation_impl <- function( n, directed = TRUE @@ -581,6 +845,34 @@ extended_chordal_ring_impl <- function( res } +connect_neighborhood_impl <- function( + graph, + order = 2, + mode = c("all", "out", "in", "total") +) { + # Argument checks + ensure_igraph(graph) + order <- as.numeric(order) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_connect_neighborhood, + graph, + order, + mode + ) + + res +} + graph_power_impl <- function( graph, order, @@ -965,6 +1257,50 @@ turan_impl <- function( res } +barabasi_game_impl <- function( + n, + power = 1.0, + m = 1, + outseq = NULL, + outpref = FALSE, + A = 1.0, + directed = TRUE, + algo = c("bag", "psumtree", "psumtree_multiple"), + start_from = NULL +) { + # Argument checks + n <- as.numeric(n) + power <- as.numeric(power) + m <- as.numeric(m) + if (!is.null(outseq)) { + outseq <- as.numeric(outseq) + } + outpref <- as.logical(outpref) + A <- as.numeric(A) + directed <- as.logical(directed) + algo <- switch_igraph_arg(algo, "bag" = 0L, "psumtree" = 1L, "psumtree_multiple" = 2L) + if (!is.null(start_from)) { + ensure_igraph(start_from) + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_barabasi_game, + n, + power, + m, + outseq, + outpref, + A, + directed, + algo, + start_from + ) + + res +} + erdos_renyi_game_gnp_impl <- function( n, p, @@ -1015,10 +1351,41 @@ erdos_renyi_game_gnm_impl <- function( res } -growing_random_game_impl <- function( - n, - m = 1, - ..., +degree_sequence_game_impl <- function( + out_deg, + in_deg = NULL, + method = c("configuration", "fast_heur_simple", "configuration_simple", "edge_switching_simple", "vl") +) { + # Argument checks + out_deg <- as.numeric(out_deg) + if (!is.null(in_deg)) { + in_deg <- as.numeric(in_deg) + } + method <- switch_igraph_arg( + method, + "configuration" = 0L, + "vl" = 1L, + "fast_heur_simple" = 2L, + "configuration_simple" = 3L, + "edge_switching_simple" = 4L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_degree_sequence_game, + out_deg, + in_deg, + method + ) + + res +} + +growing_random_game_impl <- function( + n, + m = 1, + ..., directed = TRUE, citation = FALSE ) { @@ -1048,6 +1415,225 @@ growing_random_game_impl <- function( res } +barabasi_aging_game_impl <- function( + nodes, + m = 1, + outseq = NULL, + outpref = FALSE, + pa_exp = 1.0, + aging_exp = 0.0, + aging_bin = 1, + zero_deg_appeal = 1.0, + zero_age_appeal = 0.0, + deg_coef = 1.0, + age_coef = 1.0, + directed = TRUE +) { + # Argument checks + nodes <- as.numeric(nodes) + m <- as.numeric(m) + if (!is.null(outseq)) { + outseq <- as.numeric(outseq) + } + outpref <- as.logical(outpref) + pa_exp <- as.numeric(pa_exp) + aging_exp <- as.numeric(aging_exp) + aging_bin <- as.numeric(aging_bin) + zero_deg_appeal <- as.numeric(zero_deg_appeal) + zero_age_appeal <- as.numeric(zero_age_appeal) + deg_coef <- as.numeric(deg_coef) + age_coef <- as.numeric(age_coef) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_barabasi_aging_game, + nodes, + m, + outseq, + outpref, + pa_exp, + aging_exp, + aging_bin, + zero_deg_appeal, + zero_age_appeal, + deg_coef, + age_coef, + directed + ) + + res +} + +recent_degree_game_impl <- function( + n, + power = 1.0, + window = 1, + m = 1, + outseq = NULL, + outpref = FALSE, + zero_appeal = 1.0, + directed = TRUE +) { + # Argument checks + n <- as.numeric(n) + power <- as.numeric(power) + window <- as.numeric(window) + m <- as.numeric(m) + if (!is.null(outseq)) { + outseq <- as.numeric(outseq) + } + outpref <- as.logical(outpref) + zero_appeal <- as.numeric(zero_appeal) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_recent_degree_game, + n, + power, + window, + m, + outseq, + outpref, + zero_appeal, + directed + ) + + res +} + +recent_degree_aging_game_impl <- function( + nodes, + m = 1, + outseq = NULL, + outpref = FALSE, + pa_exp = 1.0, + aging_exp = 0.0, + aging_bin = 1, + window = 1, + zero_appeal = 1.0, + directed = TRUE +) { + # Argument checks + nodes <- as.numeric(nodes) + m <- as.numeric(m) + if (!is.null(outseq)) { + outseq <- as.numeric(outseq) + } + outpref <- as.logical(outpref) + pa_exp <- as.numeric(pa_exp) + aging_exp <- as.numeric(aging_exp) + aging_bin <- as.numeric(aging_bin) + window <- as.numeric(window) + zero_appeal <- as.numeric(zero_appeal) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_recent_degree_aging_game, + nodes, + m, + outseq, + outpref, + pa_exp, + aging_exp, + aging_bin, + window, + zero_appeal, + directed + ) + + res +} + +callaway_traits_game_impl <- function( + nodes, + types, + edges_per_step = 1, + type_dist, + pref_matrix, + directed = FALSE +) { + # Argument checks + nodes <- as.numeric(nodes) + types <- as.numeric(types) + edges_per_step <- as.numeric(edges_per_step) + type_dist <- as.numeric(type_dist) + pref_matrix[] <- as.numeric(pref_matrix) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_callaway_traits_game, + nodes, + types, + edges_per_step, + type_dist, + pref_matrix, + directed + ) + + res +} + +establishment_game_impl <- function( + nodes, + types, + k = 1, + type_dist, + pref_matrix, + directed = TRUE +) { + # Argument checks + nodes <- as.numeric(nodes) + types <- as.numeric(types) + k <- as.numeric(k) + type_dist <- as.numeric(type_dist) + pref_matrix[] <- as.numeric(pref_matrix) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_establishment_game, + nodes, + types, + k, + type_dist, + pref_matrix, + directed + ) + + res +} + +grg_game_impl <- function( + nodes, + radius, + torus = FALSE +) { + # Argument checks + nodes <- as.numeric(nodes) + radius <- as.numeric(radius) + torus <- as.logical(torus) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_grg_game, + nodes, + radius, + torus + ) + + res +} + preference_game_impl <- function( nodes, types, @@ -1169,6 +1755,121 @@ rewire_directed_edges_impl <- function( res } +watts_strogatz_game_impl <- function( + dim, + size, + nei, + p, + loops = FALSE, + multiple = FALSE +) { + # Argument checks + dim <- as.numeric(dim) + size <- as.numeric(size) + nei <- as.numeric(nei) + p <- as.numeric(p) + loops <- as.logical(loops) + multiple <- as.logical(multiple) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_watts_strogatz_game, + dim, + size, + nei, + p, + loops, + multiple + ) + + res +} + +lastcit_game_impl <- function( + nodes, + edges_per_node = 1, + agebins = 1, + preference, + directed = TRUE +) { + # Argument checks + nodes <- as.numeric(nodes) + edges_per_node <- as.numeric(edges_per_node) + agebins <- as.numeric(agebins) + preference <- as.numeric(preference) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_lastcit_game, + nodes, + edges_per_node, + agebins, + preference, + directed + ) + + res +} + +cited_type_game_impl <- function( + nodes, + types, + pref, + edges_per_step = 1, + directed = TRUE +) { + # Argument checks + nodes <- as.numeric(nodes) + types <- as.numeric(types) - 1 + pref <- as.numeric(pref) + edges_per_step <- as.numeric(edges_per_step) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_cited_type_game, + nodes, + types, + pref, + edges_per_step, + directed + ) + + res +} + +citing_cited_type_game_impl <- function( + nodes, + types, + pref, + edges_per_step = 1, + directed = TRUE +) { + # Argument checks + nodes <- as.numeric(nodes) + types <- as.numeric(types) - 1 + pref[] <- as.numeric(pref) + edges_per_step <- as.numeric(edges_per_step) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_citing_cited_type_game, + nodes, + types, + pref, + edges_per_step, + directed + ) + + res +} + forest_fire_game_impl <- function( nodes, fw_prob, @@ -1665,21 +2366,109 @@ are_adjacent_impl <- function( res } -closeness_impl <- function( +are_connected_impl <- function( graph, - vids = V(graph), - mode = c("out", "in", "all", "total"), - weights = NULL, - normalized = FALSE + v1, + v2 ) { # Argument checks ensure_igraph(graph) - vids <- as_igraph_vs(graph, vids) - mode <- switch_igraph_arg( - mode, - "out" = 1L, - "in" = 2L, - "all" = 3L, + v1 <- as_igraph_vs(graph, v1) + if (length(v1) == 0) { + cli::cli_abort( + "{.arg v1} must specify at least one vertex", + call = rlang::caller_env() + ) + } + v2 <- as_igraph_vs(graph, v2) + if (length(v2) == 0) { + cli::cli_abort( + "{.arg v2} must specify at least one vertex", + call = rlang::caller_env() + ) + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_are_connected, + graph, + v1 - 1, + v2 - 1 + ) + + res +} + +diameter_impl <- function( + graph, + directed = TRUE, + unconnected = TRUE +) { + # Argument checks + ensure_igraph(graph) + directed <- as.logical(directed) + unconnected <- as.logical(unconnected) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_diameter, + graph, + directed, + unconnected + ) + + res +} + +diameter_dijkstra_impl <- function( + graph, + weights = NULL, + directed = TRUE, + unconnected = TRUE +) { + # Argument checks + ensure_igraph(graph) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + directed <- as.logical(directed) + unconnected <- as.logical(unconnected) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_diameter_dijkstra, + graph, + weights, + directed, + unconnected + ) + + res +} + +closeness_impl <- function( + graph, + vids = V(graph), + mode = c("out", "in", "all", "total"), + weights = NULL, + normalized = FALSE +) { + # Argument checks + ensure_igraph(graph) + vids <- as_igraph_vs(graph, vids) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, "total" = 3L ) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { @@ -1754,6 +2543,71 @@ closeness_cutoff_impl <- function( res } +distances_impl <- function( + graph, + from = V(graph), + to = V(graph), + mode = c("out", "in", "all", "total") +) { + # Argument checks + ensure_igraph(graph) + from <- as_igraph_vs(graph, from) + to <- as_igraph_vs(graph, to) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_distances, + graph, + from - 1, + to - 1, + mode + ) + + res +} + +distances_cutoff_impl <- function( + graph, + from = V(graph), + to = V(graph), + mode = c("out", "in", "all", "total"), + cutoff = -1 +) { + # Argument checks + ensure_igraph(graph) + from <- as_igraph_vs(graph, from) + to <- as_igraph_vs(graph, to) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + cutoff <- as.numeric(cutoff) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_distances_cutoff, + graph, + from - 1, + to - 1, + mode, + cutoff + ) + + res +} + get_shortest_path_impl <- function( graph, from, @@ -1918,11 +2772,13 @@ get_shortest_path_dijkstra_impl <- function( res } -get_all_shortest_paths_impl <- function( +get_shortest_path_astar_impl <- function( graph, from, to, - mode = c("out", "in", "all", "total") + weights = NULL, + mode = c("out", "in", "all", "total"), + heuristic = NULL ) { # Argument checks ensure_igraph(graph) @@ -1934,6 +2790,20 @@ get_all_shortest_paths_impl <- function( ) } to <- as_igraph_vs(graph, to) + if (length(to) == 0) { + cli::cli_abort( + "{.arg to} must specify at least one vertex", + call = rlang::caller_env() + ) + } + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } mode <- switch_igraph_arg( mode, "out" = 1L, @@ -1945,26 +2815,27 @@ get_all_shortest_paths_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_get_all_shortest_paths, + R_igraph_get_shortest_path_astar, graph, from - 1, to - 1, - mode + weights, + mode, + heuristic ) if (igraph_opt("return.vs.es")) { - res$vpaths <- lapply(res$vpaths, unsafe_create_vs, graph = graph, verts = V(graph)) + res$vertices <- create_vs(graph, res$vertices) } if (igraph_opt("return.vs.es")) { - res$epaths <- lapply(res$epaths, unsafe_create_es, graph = graph, es = E(graph)) + res$edges <- create_es(graph, res$edges) } res } -get_all_shortest_paths_dijkstra_impl <- function( +get_shortest_paths_impl <- function( graph, from, to = V(graph), - weights = NULL, mode = c("out", "in", "all", "total") ) { # Argument checks @@ -1977,14 +2848,48 @@ get_all_shortest_paths_dijkstra_impl <- function( ) } to <- as_igraph_vs(graph, to) - if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { - weights <- E(graph)$weight + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_get_shortest_paths, + graph, + from - 1, + to - 1, + mode + ) + if (igraph_opt("return.vs.es")) { + res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph)) } - if (!is.null(weights) && !all(is.na(weights))) { - weights <- as.numeric(weights) - } else { - weights <- NULL + if (igraph_opt("return.vs.es")) { + res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph)) + } + res +} + +get_all_shortest_paths_impl <- function( + graph, + from, + to, + mode = c("out", "in", "all", "total") +) { + # Argument checks + ensure_igraph(graph) + from <- as_igraph_vs(graph, from) + if (length(from) == 0) { + cli::cli_abort( + "{.arg from} must specify at least one vertex", + call = rlang::caller_env() + ) } + to <- as_igraph_vs(graph, to) mode <- switch_igraph_arg( mode, "out" = 1L, @@ -1996,11 +2901,10 @@ get_all_shortest_paths_dijkstra_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_get_all_shortest_paths_dijkstra, + R_igraph_get_all_shortest_paths, graph, from - 1, to - 1, - weights, mode ) if (igraph_opt("return.vs.es")) { @@ -2012,18 +2916,17 @@ get_all_shortest_paths_dijkstra_impl <- function( res } -voronoi_impl <- function( +distances_dijkstra_impl <- function( graph, - generators, - ..., + from = V(graph), + to = V(graph), weights = NULL, - mode = c("out", "in", "all", "total"), - tiebreaker = c("random", "first", "last") + mode = c("out", "in", "all", "total") ) { # Argument checks - check_dots_empty() ensure_igraph(graph) - generators <- as_igraph_vs(graph, generators) + from <- as_igraph_vs(graph, from) + to <- as_igraph_vs(graph, to) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight } @@ -2039,40 +2942,41 @@ voronoi_impl <- function( "all" = 3L, "total" = 3L ) - tiebreaker <- switch_igraph_arg(tiebreaker, "first" = 0L, "last" = 1L, "random" = 2L) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_voronoi, + R_igraph_distances_dijkstra, graph, - generators - 1, + from - 1, + to - 1, weights, - mode, - tiebreaker + mode ) res } -get_all_simple_paths_impl <- function( +distances_dijkstra_cutoff_impl <- function( graph, - from, + from = V(graph), to = V(graph), - cutoff = -1, - mode = c("out", "in", "all", "total") -) { - # Argument checks + weights = NULL, + mode = c("out", "in", "all", "total"), + cutoff = -1 +) { + # Argument checks ensure_igraph(graph) from <- as_igraph_vs(graph, from) - if (length(from) == 0) { - cli::cli_abort( - "{.arg from} must specify at least one vertex", - call = rlang::caller_env() - ) - } to <- as_igraph_vs(graph, to) - cutoff <- as.numeric(cutoff) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } mode <- switch_igraph_arg( mode, "out" = 1L, @@ -2080,44 +2984,32 @@ get_all_simple_paths_impl <- function( "all" = 3L, "total" = 3L ) + cutoff <- as.numeric(cutoff) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_get_all_simple_paths, + R_igraph_distances_dijkstra_cutoff, graph, from - 1, to - 1, - cutoff, - mode + weights, + mode, + cutoff ) - if (igraph_opt("return.vs.es")) { - res <- create_vs(graph, res) - } + res } -get_k_shortest_paths_impl <- function( +get_shortest_paths_dijkstra_impl <- function( graph, from, - to, - ..., - k, + to = V(graph), weights = NULL, mode = c("out", "in", "all", "total") ) { # Argument checks - check_dots_empty() ensure_igraph(graph) - if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { - weights <- E(graph)$weight - } - if (!is.null(weights) && !all(is.na(weights))) { - weights <- as.numeric(weights) - } else { - weights <- NULL - } - k <- as.numeric(k) from <- as_igraph_vs(graph, from) if (length(from) == 0) { cli::cli_abort( @@ -2126,11 +3018,13 @@ get_k_shortest_paths_impl <- function( ) } to <- as_igraph_vs(graph, to) - if (length(to) == 0) { - cli::cli_abort( - "{.arg to} must specify at least one vertex", - call = rlang::caller_env() - ) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL } mode <- switch_igraph_arg( mode, @@ -2143,27 +3037,26 @@ get_k_shortest_paths_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_get_k_shortest_paths, + R_igraph_get_shortest_paths_dijkstra, graph, - weights, - k, from - 1, to - 1, + weights, mode ) if (igraph_opt("return.vs.es")) { - res$vpaths <- lapply(res$vpaths, unsafe_create_vs, graph = graph, verts = V(graph)) + res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph)) } if (igraph_opt("return.vs.es")) { - res$epaths <- lapply(res$epaths, unsafe_create_es, graph = graph, es = E(graph)) + res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph)) } res } -get_widest_path_impl <- function( +get_shortest_paths_bellman_ford_impl <- function( graph, from, - to, + to = V(graph), weights = NULL, mode = c("out", "in", "all", "total") ) { @@ -2177,12 +3070,6 @@ get_widest_path_impl <- function( ) } to <- as_igraph_vs(graph, to) - if (length(to) == 0) { - cli::cli_abort( - "{.arg to} must specify at least one vertex", - call = rlang::caller_env() - ) - } if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight } @@ -2202,7 +3089,7 @@ get_widest_path_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_get_widest_path, + R_igraph_get_shortest_paths_bellman_ford, graph, from - 1, to - 1, @@ -2210,15 +3097,15 @@ get_widest_path_impl <- function( mode ) if (igraph_opt("return.vs.es")) { - res$vertices <- create_vs(graph, res$vertices) + res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph)) } if (igraph_opt("return.vs.es")) { - res$edges <- create_es(graph, res$edges) + res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph)) } res } -get_widest_paths_impl <- function( +get_all_shortest_paths_dijkstra_impl <- function( graph, from, to = V(graph), @@ -2254,7 +3141,7 @@ get_widest_paths_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_get_widest_paths, + R_igraph_get_all_shortest_paths_dijkstra, graph, from - 1, to - 1, @@ -2262,15 +3149,15 @@ get_widest_paths_impl <- function( mode ) if (igraph_opt("return.vs.es")) { - res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph)) + res$vpaths <- lapply(res$vpaths, unsafe_create_vs, graph = graph, verts = V(graph)) } if (igraph_opt("return.vs.es")) { - res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph)) + res$epaths <- lapply(res$epaths, unsafe_create_es, graph = graph, es = E(graph)) } res } -widest_path_widths_dijkstra_impl <- function( +distances_bellman_ford_impl <- function( graph, from = V(graph), to = V(graph), @@ -2300,7 +3187,7 @@ widest_path_widths_dijkstra_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_widest_path_widths_dijkstra, + R_igraph_distances_bellman_ford, graph, from - 1, to - 1, @@ -2311,12 +3198,11 @@ widest_path_widths_dijkstra_impl <- function( res } -widest_path_widths_floyd_warshall_impl <- function( +distances_johnson_impl <- function( graph, from = V(graph), to = V(graph), - weights = NULL, - mode = c("out", "in", "all", "total") + weights = NULL ) { # Argument checks ensure_igraph(graph) @@ -2330,36 +3216,32 @@ widest_path_widths_floyd_warshall_impl <- function( } else { weights <- NULL } - mode <- switch_igraph_arg( - mode, - "out" = 1L, - "in" = 2L, - "all" = 3L, - "total" = 3L - ) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_widest_path_widths_floyd_warshall, + R_igraph_distances_johnson, graph, from - 1, to - 1, - weights, - mode + weights ) res } -spanner_impl <- function( +distances_floyd_warshall_impl <- function( graph, - stretch, - weights = NULL + from = V(graph), + to = V(graph), + weights = NULL, + mode = c("out", "in", "all", "total"), + method = c("automatic", "original", "tree") ) { # Argument checks ensure_igraph(graph) - stretch <- as.numeric(stretch) + from <- as_igraph_vs(graph, from) + to <- as_igraph_vs(graph, to) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight } @@ -2368,32 +3250,42 @@ spanner_impl <- function( } else { weights <- NULL } + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + method <- switch_igraph_arg(method, "automatic" = 0L, "original" = 1L, "tree" = 2L) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_spanner, + R_igraph_distances_floyd_warshall, graph, - stretch, - weights + from - 1, + to - 1, + weights, + mode, + method ) - if (igraph_opt("return.vs.es")) { - res <- create_es(graph, res) - } + res } -betweenness_cutoff_impl <- function( +voronoi_impl <- function( graph, - vids = V(graph), - directed = TRUE, + generators, + ..., weights = NULL, - cutoff = -1 + mode = c("out", "in", "all", "total"), + tiebreaker = c("random", "first", "last") ) { # Argument checks + check_dots_empty() ensure_igraph(graph) - vids <- as_igraph_vs(graph, vids) - directed <- as.logical(directed) + generators <- as_igraph_vs(graph, generators) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight } @@ -2402,72 +3294,83 @@ betweenness_cutoff_impl <- function( } else { weights <- NULL } - cutoff <- as.numeric(cutoff) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + tiebreaker <- switch_igraph_arg(tiebreaker, "first" = 0L, "last" = 1L, "random" = 2L) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_betweenness_cutoff, + R_igraph_voronoi, graph, - vids - 1, - directed, + generators - 1, weights, - cutoff + mode, + tiebreaker ) - if (igraph_opt("add.vertex.names") && is_named(graph)) { - names(res) <- vertex_attr(graph, "name", vids) - } + res } -betweenness_subset_impl <- function( +get_all_simple_paths_impl <- function( graph, - vids = V(graph), - directed = TRUE, - sources = V(graph), - targets = V(graph), - weights = NULL + from, + to = V(graph), + cutoff = -1, + mode = c("out", "in", "all", "total") ) { # Argument checks ensure_igraph(graph) - vids <- as_igraph_vs(graph, vids) - directed <- as.logical(directed) - sources <- as_igraph_vs(graph, sources) - targets <- as_igraph_vs(graph, targets) - if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { - weights <- E(graph)$weight - } - if (!is.null(weights) && !all(is.na(weights))) { - weights <- as.numeric(weights) - } else { - weights <- NULL + from <- as_igraph_vs(graph, from) + if (length(from) == 0) { + cli::cli_abort( + "{.arg from} must specify at least one vertex", + call = rlang::caller_env() + ) } + to <- as_igraph_vs(graph, to) + cutoff <- as.numeric(cutoff) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_betweenness_subset, + R_igraph_get_all_simple_paths, graph, - vids - 1, - directed, - sources - 1, - targets - 1, - weights + from - 1, + to - 1, + cutoff, + mode ) - if (igraph_opt("add.vertex.names") && is_named(graph)) { - names(res) <- vertex_attr(graph, "name", vids) + if (igraph_opt("return.vs.es")) { + res <- create_vs(graph, res) } res } -edge_betweenness_impl <- function( +get_k_shortest_paths_impl <- function( graph, - directed = TRUE, - weights = NULL + from, + to, + ..., + k, + weights = NULL, + mode = c("out", "in", "all", "total") ) { # Argument checks + check_dots_empty() ensure_igraph(graph) - directed <- as.logical(directed) if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { weights <- E(graph)$weight } @@ -2476,11 +3379,440 @@ edge_betweenness_impl <- function( } else { weights <- NULL } + k <- as.numeric(k) + from <- as_igraph_vs(graph, from) + if (length(from) == 0) { + cli::cli_abort( + "{.arg from} must specify at least one vertex", + call = rlang::caller_env() + ) + } + to <- as_igraph_vs(graph, to) + if (length(to) == 0) { + cli::cli_abort( + "{.arg to} must specify at least one vertex", + call = rlang::caller_env() + ) + } + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_edge_betweenness, + R_igraph_get_k_shortest_paths, + graph, + weights, + k, + from - 1, + to - 1, + mode + ) + if (igraph_opt("return.vs.es")) { + res$vpaths <- lapply(res$vpaths, unsafe_create_vs, graph = graph, verts = V(graph)) + } + if (igraph_opt("return.vs.es")) { + res$epaths <- lapply(res$epaths, unsafe_create_es, graph = graph, es = E(graph)) + } + res +} + +get_widest_path_impl <- function( + graph, + from, + to, + weights = NULL, + mode = c("out", "in", "all", "total") +) { + # Argument checks + ensure_igraph(graph) + from <- as_igraph_vs(graph, from) + if (length(from) == 0) { + cli::cli_abort( + "{.arg from} must specify at least one vertex", + call = rlang::caller_env() + ) + } + to <- as_igraph_vs(graph, to) + if (length(to) == 0) { + cli::cli_abort( + "{.arg to} must specify at least one vertex", + call = rlang::caller_env() + ) + } + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_get_widest_path, + graph, + from - 1, + to - 1, + weights, + mode + ) + if (igraph_opt("return.vs.es")) { + res$vertices <- create_vs(graph, res$vertices) + } + if (igraph_opt("return.vs.es")) { + res$edges <- create_es(graph, res$edges) + } + res +} + +get_widest_paths_impl <- function( + graph, + from, + to = V(graph), + weights = NULL, + mode = c("out", "in", "all", "total") +) { + # Argument checks + ensure_igraph(graph) + from <- as_igraph_vs(graph, from) + if (length(from) == 0) { + cli::cli_abort( + "{.arg from} must specify at least one vertex", + call = rlang::caller_env() + ) + } + to <- as_igraph_vs(graph, to) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_get_widest_paths, + graph, + from - 1, + to - 1, + weights, + mode + ) + if (igraph_opt("return.vs.es")) { + res$vertices <- lapply(res$vertices, unsafe_create_vs, graph = graph, verts = V(graph)) + } + if (igraph_opt("return.vs.es")) { + res$edges <- lapply(res$edges, unsafe_create_es, graph = graph, es = E(graph)) + } + res +} + +widest_path_widths_dijkstra_impl <- function( + graph, + from = V(graph), + to = V(graph), + weights = NULL, + mode = c("out", "in", "all", "total") +) { + # Argument checks + ensure_igraph(graph) + from <- as_igraph_vs(graph, from) + to <- as_igraph_vs(graph, to) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_widest_path_widths_dijkstra, + graph, + from - 1, + to - 1, + weights, + mode + ) + + res +} + +widest_path_widths_floyd_warshall_impl <- function( + graph, + from = V(graph), + to = V(graph), + weights = NULL, + mode = c("out", "in", "all", "total") +) { + # Argument checks + ensure_igraph(graph) + from <- as_igraph_vs(graph, from) + to <- as_igraph_vs(graph, to) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_widest_path_widths_floyd_warshall, + graph, + from - 1, + to - 1, + weights, + mode + ) + + res +} + +spanner_impl <- function( + graph, + stretch, + weights = NULL +) { + # Argument checks + ensure_igraph(graph) + stretch <- as.numeric(stretch) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_spanner, + graph, + stretch, + weights + ) + if (igraph_opt("return.vs.es")) { + res <- create_es(graph, res) + } + res +} + +subcomponent_impl <- function( + graph, + vid, + mode = c("all", "out", "in", "total") +) { + # Argument checks + ensure_igraph(graph) + vid <- as_igraph_vs(graph, vid) + if (length(vid) == 0) { + cli::cli_abort( + "{.arg vid} must specify at least one vertex", + call = rlang::caller_env() + ) + } + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_subcomponent, + graph, + vid - 1, + mode + ) + if (igraph_opt("return.vs.es")) { + res <- create_vs(graph, res) + } + res +} + +betweenness_impl <- function( + graph, + vids = V(graph), + directed = TRUE, + weights = NULL +) { + # Argument checks + ensure_igraph(graph) + vids <- as_igraph_vs(graph, vids) + directed <- as.logical(directed) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_betweenness, + graph, + vids - 1, + directed, + weights + ) + if (igraph_opt("add.vertex.names") && is_named(graph)) { + names(res) <- vertex_attr(graph, "name", vids) + } + res +} + +betweenness_cutoff_impl <- function( + graph, + vids = V(graph), + directed = TRUE, + weights = NULL, + cutoff = -1 +) { + # Argument checks + ensure_igraph(graph) + vids <- as_igraph_vs(graph, vids) + directed <- as.logical(directed) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + cutoff <- as.numeric(cutoff) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_betweenness_cutoff, + graph, + vids - 1, + directed, + weights, + cutoff + ) + if (igraph_opt("add.vertex.names") && is_named(graph)) { + names(res) <- vertex_attr(graph, "name", vids) + } + res +} + +betweenness_subset_impl <- function( + graph, + vids = V(graph), + directed = TRUE, + sources = V(graph), + targets = V(graph), + weights = NULL +) { + # Argument checks + ensure_igraph(graph) + vids <- as_igraph_vs(graph, vids) + directed <- as.logical(directed) + sources <- as_igraph_vs(graph, sources) + targets <- as_igraph_vs(graph, targets) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_betweenness_subset, + graph, + vids - 1, + directed, + sources - 1, + targets - 1, + weights + ) + if (igraph_opt("add.vertex.names") && is_named(graph)) { + names(res) <- vertex_attr(graph, "name", vids) + } + res +} + +edge_betweenness_impl <- function( + graph, + directed = TRUE, + weights = NULL +) { + # Argument checks + ensure_igraph(graph) + directed <- as.logical(directed) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_edge_betweenness, graph, directed, weights @@ -2559,6 +3891,49 @@ edge_betweenness_subset_impl <- function( res } +harmonic_centrality_impl <- function( + graph, + vids = V(graph), + mode = c("out", "in", "all", "total"), + weights = NULL, + normalized = FALSE +) { + # Argument checks + ensure_igraph(graph) + vids <- as_igraph_vs(graph, vids) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + normalized <- as.logical(normalized) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_harmonic_centrality, + graph, + vids - 1, + mode, + weights, + normalized + ) + if (igraph_opt("add.vertex.names") && is_named(graph)) { + names(res) <- vertex_attr(graph, "name", vids) + } + res +} + harmonic_centrality_cutoff_impl <- function( graph, vids = V(graph), @@ -2605,6 +3980,57 @@ harmonic_centrality_cutoff_impl <- function( res } +pagerank_impl <- function( + graph, + algo = c("prpack", "arpack"), + vids = V(graph), + directed = TRUE, + damping = 0.85, + weights = NULL, + options = NULL +) { + # Argument checks + ensure_igraph(graph) + algo <- switch_igraph_arg(algo, "arpack" = 1L, "prpack" = 2L) + vids <- as_igraph_vs(graph, vids) + directed <- as.logical(directed) + damping <- as.numeric(damping) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + if (is.null(options)) { + if (algo == 0L) { + options <- list(niter = 1000, eps = 0.001) + } else if (algo == 1L) { + options <- arpack_defaults() + } else { + options <- NULL + } + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_pagerank, + graph, + algo, + vids - 1, + directed, + damping, + weights, + options + ) + if (igraph_opt("add.vertex.names") && is_named(graph)) { + names(res$vector) <- vertex_attr(graph, "name", vids) + } + res +} + personalized_pagerank_impl <- function( graph, algo = c("prpack", "arpack"), @@ -2809,6 +4235,31 @@ reverse_edges_impl <- function( res } +average_path_length_impl <- function( + graph, + directed = TRUE, + unconn = TRUE, + details = FALSE +) { + # Argument checks + ensure_igraph(graph) + directed <- as.logical(directed) + unconn <- as.logical(unconn) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_average_path_length, + graph, + directed, + unconn + ) + if (!details) { + res <- res$res + } + res +} + average_path_length_dijkstra_impl <- function( graph, weights = NULL, @@ -3021,55 +4472,126 @@ reciprocity_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_reciprocity, + R_igraph_reciprocity, + graph, + ignore_loops, + mode + ) + + res +} + +constraint_impl <- function( + graph, + vids = V(graph), + weights = NULL +) { + # Argument checks + ensure_igraph(graph) + vids <- as_igraph_vs(graph, vids) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_constraint, + graph, + vids - 1, + weights + ) + + res +} + +maxdegree_impl <- function( + graph, + ..., + v = V(graph), + mode = c("all", "out", "in", "total"), + loops = TRUE +) { + # Argument checks + check_dots_empty() + ensure_igraph(graph) + v <- as_igraph_vs(graph, v) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + loops <- as.logical(loops) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_maxdegree, + graph, + v - 1, + mode, + loops + ) + + res +} + +density_impl <- function( + graph, + loops = FALSE +) { + # Argument checks + ensure_igraph(graph) + loops <- as.logical(loops) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_density, graph, - ignore_loops, - mode + loops ) res } -constraint_impl <- function( +mean_degree_impl <- function( graph, - vids = V(graph), - weights = NULL + loops = TRUE ) { # Argument checks ensure_igraph(graph) - vids <- as_igraph_vs(graph, vids) - if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { - weights <- E(graph)$weight - } - if (!is.null(weights) && !all(is.na(weights))) { - weights <- as.numeric(weights) - } else { - weights <- NULL - } + loops <- as.logical(loops) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_constraint, + R_igraph_mean_degree, graph, - vids - 1, - weights + loops ) res } -maxdegree_impl <- function( +neighborhood_size_impl <- function( graph, - ..., - v = V(graph), + vids, + order, mode = c("all", "out", "in", "total"), - loops = TRUE + mindist = 0 ) { # Argument checks - check_dots_empty() ensure_igraph(graph) - v <- as_igraph_vs(graph, v) + vids <- as_igraph_vs(graph, vids) + order <- as.numeric(order) mode <- switch_igraph_arg( mode, "out" = 1L, @@ -3077,54 +4599,87 @@ maxdegree_impl <- function( "all" = 3L, "total" = 3L ) - loops <- as.logical(loops) + mindist <- as.numeric(mindist) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_maxdegree, + R_igraph_neighborhood_size, graph, - v - 1, + vids - 1, + order, mode, - loops + mindist ) res } -density_impl <- function( +neighborhood_impl <- function( graph, - loops = FALSE + vids, + order, + mode = c("all", "out", "in", "total"), + mindist = 0 ) { # Argument checks ensure_igraph(graph) - loops <- as.logical(loops) + vids <- as_igraph_vs(graph, vids) + order <- as.numeric(order) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + mindist <- as.numeric(mindist) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_density, + R_igraph_neighborhood, graph, - loops + vids - 1, + order, + mode, + mindist ) - + if (igraph_opt("return.vs.es")) { + res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph)) + } res } -mean_degree_impl <- function( +neighborhood_graphs_impl <- function( graph, - loops = TRUE + vids, + order, + mode = c("all", "out", "in", "total"), + mindist = 0 ) { # Argument checks ensure_igraph(graph) - loops <- as.logical(loops) + vids <- as_igraph_vs(graph, vids) + order <- as.numeric(order) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + mindist <- as.numeric(mindist) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_mean_degree, + R_igraph_neighborhood_graphs, graph, - loops + vids - 1, + order, + mode, + mindist ) res @@ -3406,6 +4961,28 @@ is_perfect_impl <- function( res } +add_edge_impl <- function( + graph, + from, + to +) { + # Argument checks + ensure_igraph(graph) + from <- as.numeric(from) + to <- as.numeric(to) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_add_edge, + graph, + from, + to + ) + + res +} + eigenvector_centrality_impl <- function( graph, directed = FALSE, @@ -3443,6 +5020,74 @@ eigenvector_centrality_impl <- function( res } +hub_score_impl <- function( + graph, + scale = TRUE, + weights = NULL, + options = arpack_defaults() +) { + # Argument checks + ensure_igraph(graph) + scale <- as.logical(scale) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + options <- modify_list(arpack_defaults(), options) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_hub_score, + graph, + scale, + weights, + options + ) + if (igraph_opt("add.vertex.names") && is_named(graph)) { + names(res$vector) <- vertex_attr(graph, "name", V(graph)) + } + res +} + +authority_score_impl <- function( + graph, + scale = TRUE, + weights = NULL, + options = arpack_defaults() +) { + # Argument checks + ensure_igraph(graph) + scale <- as.logical(scale) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + options <- modify_list(arpack_defaults(), options) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_authority_score, + graph, + scale, + weights, + options + ) + if (igraph_opt("add.vertex.names") && is_named(graph)) { + names(res$vector) <- vertex_attr(graph, "name", V(graph)) + } + res +} + hub_and_authority_scores_impl <- function( graph, scale = TRUE, @@ -3567,6 +5212,32 @@ maximum_cardinality_search_impl <- function( res } +is_chordal_impl <- function( + graph, + alpha = NULL, + alpham1 = NULL +) { + # Argument checks + ensure_igraph(graph) + if (!is.null(alpha)) { + alpha <- as.numeric(alpha) - 1 + } + if (!is.null(alpham1)) { + alpham1 <- as_igraph_vs(graph, alpham1) + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_is_chordal, + graph, + alpha, + alpham1 - 1 + ) + + res +} + avg_nearest_neighbor_degree_impl <- function( graph, vids = V(graph), @@ -4213,6 +5884,36 @@ contract_vertices_impl <- function( 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_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, vids = V(graph), @@ -4255,6 +5956,33 @@ eccentricity_dijkstra_impl <- function( res } +graph_center_impl <- function( + graph, + mode = c("all", "out", "in", "total") +) { + # Argument checks + ensure_igraph(graph) + mode <- switch_igraph_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, ..., @@ -4294,6 +6022,31 @@ graph_center_dijkstra_impl <- function( res } +radius_impl <- function( + graph, + mode = c("all", "out", "in", "total") +) { + # Argument checks + ensure_igraph(graph) + mode <- switch_igraph_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, ..., @@ -4489,6 +6242,58 @@ random_walk_impl <- function( res } +random_edge_walk_impl <- function( + graph, + weights = NULL, + start, + mode = c("out", "in", "all", "total"), + steps, + stuck = c("return", "error") +) { + # Argument checks + ensure_igraph(graph) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + start <- as_igraph_vs(graph, start) + if (length(start) == 0) { + cli::cli_abort( + "{.arg start} must specify at least one vertex", + call = rlang::caller_env() + ) + } + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + steps <- as.numeric(steps) + stuck <- switch_igraph_arg(stuck, "error" = 0L, "return" = 1L) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_random_edge_walk, + graph, + weights, + start - 1, + mode, + steps, + stuck + ) + if (igraph_opt("return.vs.es")) { + res <- create_es(graph, res) + } + res +} + global_efficiency_impl <- function( graph, weights = NULL, @@ -4647,6 +6452,36 @@ trussness_impl <- function( res } +is_bigraphical_impl <- function( + degrees1, + degrees2, + allowed_edge_types = c("simple", "loops", "multi", "all") +) { + # Argument checks + degrees1 <- as.numeric(degrees1) + degrees2 <- as.numeric(degrees2) + allowed_edge_types <- switch_igraph_arg( + allowed_edge_types, + "simple" = 0L, + "loop" = 1L, + "loops" = 1L, + "multi" = 6L, + "multiple" = 6L, + "all" = 7L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_is_bigraphical, + degrees1, + degrees2, + allowed_edge_types + ) + + res +} + is_graphical_impl <- function( out_deg, in_deg = NULL, @@ -4734,6 +6569,50 @@ bipartite_projection_size_impl <- function( res } +bipartite_projection_impl <- function( + graph, + types, + probe1 = -1 +) { + # Argument checks + ensure_igraph(graph) + types <- handle_vertex_type_arg(types, graph) + probe1 <- as.numeric(probe1) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_bipartite_projection, + graph, + types, + probe1 + ) + + res +} + +create_bipartite_impl <- function( + types, + edges, + directed = FALSE +) { + # Argument checks + types <- handle_vertex_type_arg(types, res$graph) + edges <- as.numeric(edges) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_create_bipartite, + types, + edges, + directed + ) + + res +} + biadjacency_impl <- function( incidence, directed = FALSE, @@ -4872,6 +6751,48 @@ bipartite_game_gnm_impl <- function( res } +bipartite_game_impl <- function( + type, + n1, + n2, + p = 0.0, + m = 0, + directed = FALSE, + mode = c("all", "out", "in", "total") +) { + # Argument checks + type <- switch_igraph_arg(type, "gnp" = 0L, "gnm" = 1L) + n1 <- as.numeric(n1) + n2 <- as.numeric(n2) + p <- as.numeric(p) + m <- as.numeric(m) + directed <- as.logical(directed) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_bipartite_game, + type, + n1, + n2, + p, + m, + directed, + mode + ) + if (igraph_opt("add.vertex.names") && is_named(res$graph)) { + names(res$types) <- vertex_attr(res$graph, "name", V(res$graph)) + } + res +} + get_laplacian_impl <- function( graph, mode = c("out", "in", "all", "total"), @@ -5001,6 +6922,31 @@ is_connected_impl <- function( res } +decompose_impl <- function( + graph, + mode = c("weak", "strong"), + maxcompno = -1, + minelements = 1 +) { + # Argument checks + ensure_igraph(graph) + mode <- switch_igraph_arg(mode, "weak" = 1L, "strong" = 2L) + maxcompno <- as.numeric(maxcompno) + minelements <- as.numeric(minelements) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_decompose, + graph, + mode, + maxcompno, + minelements + ) + + res +} + articulation_points_impl <- function( graph ) { @@ -5249,6 +7195,67 @@ largest_cliques_impl <- function( res } +maximal_cliques_impl <- function( + graph, + min_size = 0, + max_size = 0 +) { + # Argument checks + ensure_igraph(graph) + min_size <- as.numeric(min_size) + max_size <- as.numeric(max_size) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_maximal_cliques, + graph, + min_size, + max_size + ) + if (igraph_opt("return.vs.es")) { + res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph)) + } + res +} + +maximal_cliques_subset_impl <- function( + graph, + subset, + outfile = NULL, + min_size = 0, + max_size = 0, + details = FALSE +) { + # Argument checks + ensure_igraph(graph) + subset <- as_igraph_vs(graph, subset) + if (!is.null(outfile)) { + check_string(outfile) + + } + min_size <- as.numeric(min_size) + max_size <- as.numeric(max_size) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_maximal_cliques_subset, + graph, + subset - 1, + outfile, + min_size, + max_size + ) + if (igraph_opt("return.vs.es")) { + res$res <- lapply(res$res, unsafe_create_vs, graph = graph, verts = V(graph)) + } + if (!details) { + res <- res$res + } + res +} + maximal_cliques_count_impl <- function( graph, min_size = 0, @@ -5271,6 +7278,32 @@ maximal_cliques_count_impl <- function( res } +maximal_cliques_file_impl <- function( + graph, + res, + min_size = 0, + max_size = 0 +) { + # Argument checks + ensure_igraph(graph) + check_string(res) + + min_size <- as.numeric(min_size) + max_size <- as.numeric(max_size) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_maximal_cliques_file, + graph, + res, + min_size, + max_size + ) + + res +} + maximal_cliques_hist_impl <- function( graph, min_size = 0, @@ -5419,6 +7452,30 @@ is_independent_vertex_set_impl <- function( res } +independent_vertex_sets_impl <- function( + graph, + min_size = 0, + max_size = 0 +) { + # Argument checks + ensure_igraph(graph) + min_size <- as.numeric(min_size) + max_size <- as.numeric(max_size) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_independent_vertex_sets, + graph, + min_size, + max_size + ) + if (igraph_opt("return.vs.es")) { + res <- lapply(res, unsafe_create_vs, graph = graph, verts = V(graph)) + } + res +} + largest_independent_vertex_sets_impl <- function( graph ) { @@ -5577,6 +7634,245 @@ layout_grid_3d_impl <- function( res } +layout_fruchterman_reingold_impl <- function( + graph, + coords = NULL, + use_seed = FALSE, + niter = 500, + start_temp = sqrt(vcount(graph)), + grid = c("auto", "grid", "nogrid"), + weights = NULL, + minx = NULL, + maxx = NULL, + miny = NULL, + maxy = NULL, + coolexp = NULL, + maxdelta = NULL, + area = NULL, + repulserad = NULL +) { + # Argument checks + ensure_igraph(graph) + if (!is.null(coords)) { + coords[] <- as.numeric(coords) + } + use_seed <- as.logical(use_seed) + niter <- as.numeric(niter) + start_temp <- as.numeric(start_temp) + grid <- switch_igraph_arg(grid, "grid" = 0L, "nogrid" = 1L, "auto" = 2L) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + if (!is.null(minx)) { + minx <- as.numeric(minx) + } + if (!is.null(maxx)) { + maxx <- as.numeric(maxx) + } + if (!is.null(miny)) { + miny <- as.numeric(miny) + } + if (!is.null(maxy)) { + maxy <- as.numeric(maxy) + } + if (!missing(coolexp)) { warning("Argument `coolexp' is deprecated and has no effect") } + if (!missing(maxdelta)) { warning("Argument `maxdelta' is deprecated and has no effect") } + if (!missing(area)) { warning("Argument `area' is deprecated and has no effect") } + if (!missing(repulserad)) { warning("Argument `repulserad' is deprecated and has no effect") } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_fruchterman_reingold, + graph, + coords, + use_seed, + niter, + start_temp, + grid, + weights, + minx, + maxx, + miny, + maxy + ) + + res +} + +layout_kamada_kawai_impl <- function( + graph, + coords, + use_seed = FALSE, + maxiter = 500, + epsilon = 0.0, + kkconst = vcount(graph), + weights = NULL, + minx = NULL, + maxx = NULL, + miny = NULL, + maxy = NULL +) { + # Argument checks + ensure_igraph(graph) + coords[] <- as.numeric(coords) + use_seed <- as.logical(use_seed) + maxiter <- as.numeric(maxiter) + epsilon <- as.numeric(epsilon) + kkconst <- as.numeric(kkconst) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + if (!is.null(minx)) { + minx <- as.numeric(minx) + } + if (!is.null(maxx)) { + maxx <- as.numeric(maxx) + } + if (!is.null(miny)) { + miny <- as.numeric(miny) + } + if (!is.null(maxy)) { + maxy <- as.numeric(maxy) + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_kamada_kawai, + graph, + coords, + use_seed, + maxiter, + epsilon, + kkconst, + weights, + minx, + maxx, + miny, + maxy + ) + + res +} + +layout_lgl_impl <- function( + graph, + maxiter = 150, + maxdelta = vcount(graph), + area = vcount(graph)^2, + coolexp = 1.5, + repulserad = vcount(graph)^3, + cellsize = vcount(graph), + root = -1 +) { + # Argument checks + ensure_igraph(graph) + maxiter <- as.numeric(maxiter) + maxdelta <- as.numeric(maxdelta) + area <- as.numeric(area) + coolexp <- as.numeric(coolexp) + repulserad <- as.numeric(repulserad) + cellsize <- as.numeric(cellsize) + root <- as.numeric(root) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_lgl, + graph, + maxiter, + maxdelta, + area, + coolexp, + repulserad, + cellsize, + root + ) + + res +} + +layout_reingold_tilford_impl <- function( + graph, + mode = c("out", "in", "all", "total"), + roots = NULL, + rootlevel = NULL +) { + # Argument checks + ensure_igraph(graph) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + if (!is.null(roots)) { + roots <- as_igraph_vs(graph, roots) + } + if (!is.null(rootlevel)) { + rootlevel <- as.numeric(rootlevel) + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_reingold_tilford, + graph, + mode, + roots - 1, + rootlevel + ) + + res +} + +layout_reingold_tilford_circular_impl <- function( + graph, + mode = c("out", "in", "all", "total"), + roots = NULL, + rootlevel = NULL +) { + # Argument checks + ensure_igraph(graph) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + if (!is.null(roots)) { + roots <- as_igraph_vs(graph, roots) + } + if (!is.null(rootlevel)) { + rootlevel <- as.numeric(rootlevel) + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_reingold_tilford_circular, + graph, + mode, + roots - 1, + rootlevel + ) + + res +} + roots_for_tree_layout_impl <- function( graph, mode = c("out", "in", "all", "total"), @@ -5600,39 +7896,298 @@ roots_for_tree_layout_impl <- function( mode, heuristic ) - if (igraph_opt("return.vs.es")) { - res <- create_vs(graph, res) - } + if (igraph_opt("return.vs.es")) { + res <- create_vs(graph, res) + } + res +} + +layout_random_3d_impl <- function( + graph +) { + # Argument checks + ensure_igraph(graph) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_random_3d, + graph + ) + + res +} + +layout_sphere_impl <- function( + graph +) { + # Argument checks + ensure_igraph(graph) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_sphere, + graph + ) + + res +} + +layout_fruchterman_reingold_3d_impl <- function( + graph, + coords = NULL, + use_seed = FALSE, + niter = 500, + start_temp = sqrt(vcount(graph)), + weights = NULL, + minx = NULL, + maxx = NULL, + miny = NULL, + maxy = NULL, + minz = NULL, + maxz = NULL, + coolexp = NULL, + maxdelta = NULL, + area = NULL, + repulserad = NULL +) { + # Argument checks + ensure_igraph(graph) + if (!is.null(coords)) { + coords[] <- as.numeric(coords) + } + use_seed <- as.logical(use_seed) + niter <- as.numeric(niter) + start_temp <- as.numeric(start_temp) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + if (!is.null(minx)) { + minx <- as.numeric(minx) + } + if (!is.null(maxx)) { + maxx <- as.numeric(maxx) + } + if (!is.null(miny)) { + miny <- as.numeric(miny) + } + if (!is.null(maxy)) { + maxy <- as.numeric(maxy) + } + if (!is.null(minz)) { + minz <- as.numeric(minz) + } + if (!is.null(maxz)) { + maxz <- as.numeric(maxz) + } + if (!missing(coolexp)) { warning("Argument `coolexp' is deprecated and has no effect") } + if (!missing(maxdelta)) { warning("Argument `maxdelta' is deprecated and has no effect") } + if (!missing(area)) { warning("Argument `area' is deprecated and has no effect") } + if (!missing(repulserad)) { warning("Argument `repulserad' is deprecated and has no effect") } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_fruchterman_reingold_3d, + graph, + coords, + use_seed, + niter, + start_temp, + weights, + minx, + maxx, + miny, + maxy, + minz, + maxz + ) + + res +} + +layout_kamada_kawai_3d_impl <- function( + graph, + coords, + use_seed = FALSE, + maxiter = 500, + epsilon = 0.0, + kkconst = vcount(graph), + weights = NULL, + minx = NULL, + maxx = NULL, + miny = NULL, + maxy = NULL, + minz = NULL, + maxz = NULL +) { + # Argument checks + ensure_igraph(graph) + coords[] <- as.numeric(coords) + use_seed <- as.logical(use_seed) + maxiter <- as.numeric(maxiter) + epsilon <- as.numeric(epsilon) + kkconst <- as.numeric(kkconst) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + if (!is.null(minx)) { + minx <- as.numeric(minx) + } + if (!is.null(maxx)) { + maxx <- as.numeric(maxx) + } + if (!is.null(miny)) { + miny <- as.numeric(miny) + } + if (!is.null(maxy)) { + maxy <- as.numeric(maxy) + } + if (!is.null(minz)) { + minz <- as.numeric(minz) + } + if (!is.null(maxz)) { + maxz <- as.numeric(maxz) + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_kamada_kawai_3d, + graph, + coords, + use_seed, + maxiter, + epsilon, + kkconst, + weights, + minx, + maxx, + miny, + maxy, + minz, + maxz + ) + + res +} + +layout_graphopt_impl <- function( + graph, + res, + niter = 500, + node_charge = 0.001, + node_mass = 30, + spring_length = 0, + spring_constant = 1, + max_sa_movement = 5, + use_seed = FALSE +) { + # Argument checks + ensure_igraph(graph) + res[] <- as.numeric(res) + niter <- as.numeric(niter) + node_charge <- as.numeric(node_charge) + node_mass <- as.numeric(node_mass) + spring_length <- as.numeric(spring_length) + spring_constant <- as.numeric(spring_constant) + max_sa_movement <- as.numeric(max_sa_movement) + use_seed <- as.logical(use_seed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_layout_graphopt, + graph, + res, + niter, + node_charge, + node_mass, + spring_length, + spring_constant, + max_sa_movement, + use_seed + ) + res } -layout_random_3d_impl <- function( - graph +layout_drl_impl <- function( + graph, + res, + use_seed = FALSE, + options = drl_defaults$default, + weights = NULL ) { # Argument checks ensure_igraph(graph) + res[] <- as.numeric(res) + use_seed <- as.logical(use_seed) + options <- modify_list(drl_defaults$default, options) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_layout_random_3d, - graph + R_igraph_layout_drl, + graph, + res, + use_seed, + options, + weights ) res } -layout_sphere_impl <- function( - graph +layout_drl_3d_impl <- function( + graph, + res, + use_seed = FALSE, + options = drl_defaults$default, + weights = NULL ) { # Argument checks ensure_igraph(graph) + res[] <- as.numeric(res) + use_seed <- as.logical(use_seed) + options <- modify_list(drl_defaults$default, options) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_layout_sphere, - graph + R_igraph_layout_drl_3d, + graph, + res, + use_seed, + options, + weights ) res @@ -6102,101 +8657,350 @@ similarity_jaccard_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_similarity_jaccard, + R_igraph_similarity_jaccard, + graph, + vids - 1, + mode, + loops + ) + + res +} + +similarity_jaccard_es_impl <- function( + graph, + es = E(graph), + mode = c("all", "out", "in", "total"), + loops = FALSE +) { + # Argument checks + ensure_igraph(graph) + es <- as_igraph_es(graph, es) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + loops <- as.logical(loops) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_similarity_jaccard_es, + graph, + es - 1, + mode, + loops + ) + + res +} + +similarity_jaccard_pairs_impl <- function( + graph, + pairs, + mode = c("all", "out", "in", "total"), + loops = FALSE +) { + # Argument checks + ensure_igraph(graph) + mode <- switch_igraph_arg( + mode, + "out" = 1L, + "in" = 2L, + "all" = 3L, + "total" = 3L + ) + loops <- as.logical(loops) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_similarity_jaccard_pairs, + graph, + pairs, + mode, + loops + ) + + res +} + +compare_communities_impl <- function( + comm1, + comm2, + method = c("vi", "nmi", "split.join", "rand", "adjusted.rand") +) { + # Argument checks + comm1 <- as.numeric(comm1) + comm2 <- as.numeric(comm2) + method <- switch_igraph_arg( + method, + "vi" = 0L, + "nmi" = 1L, + "split.join" = 2L, + "rand" = 3L, + "adjusted.rand" = 4L + ) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_compare_communities, + comm1, + comm2, + method + ) + + res +} + +community_spinglass_impl <- function( + graph, + weights = NULL, + spins = 25, + parupdate = FALSE, + starttemp = 1, + stoptemp = 0.01, + coolfact = 0.99, + update_rule = c("config", "simple"), + gamma = 1.0, + implementation = c("orig", "neg"), + lambda = 1.0 +) { + # Argument checks + ensure_igraph(graph) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + spins <- as.numeric(spins) + parupdate <- as.logical(parupdate) + starttemp <- as.numeric(starttemp) + stoptemp <- as.numeric(stoptemp) + coolfact <- as.numeric(coolfact) + update_rule <- switch_igraph_arg(update_rule, "simple" = 0L, "config" = 1L) + gamma <- as.numeric(gamma) + implementation <- switch_igraph_arg(implementation, "orig" = 0L, "neg" = 1L) + lambda <- as.numeric(lambda) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_community_spinglass, + graph, + weights, + spins, + parupdate, + starttemp, + stoptemp, + coolfact, + update_rule, + gamma, + implementation, + lambda + ) + + res +} + +community_spinglass_single_impl <- function( + graph, + weights = NULL, + vertex, + spins = 25, + update_rule = c("config", "simple"), + gamma = 1.0 +) { + # Argument checks + ensure_igraph(graph) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + vertex <- as.numeric(vertex) + spins <- as.numeric(spins) + update_rule <- switch_igraph_arg(update_rule, "simple" = 0L, "config" = 1L) + gamma <- as.numeric(gamma) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_community_spinglass_single, + graph, + weights, + vertex, + spins, + update_rule, + gamma + ) + + res +} + +community_walktrap_impl <- function( + graph, + weights = NULL, + steps = 4 +) { + # Argument checks + ensure_igraph(graph) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + steps <- as.numeric(steps) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_community_walktrap, + graph, + weights, + steps + ) + + res +} + +community_edge_betweenness_impl <- function( + graph, + directed = TRUE, + weights = NULL +) { + # Argument checks + ensure_igraph(graph) + directed <- as.logical(directed) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_community_edge_betweenness, + graph, + directed, + weights + ) + + res +} + +community_eb_get_merges_impl <- function( + graph, + directed, + edges, + weights = NULL +) { + # Argument checks + ensure_igraph(graph) + directed <- as.logical(directed) + edges <- as_igraph_es(graph, edges) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_community_eb_get_merges, graph, - vids - 1, - mode, - loops + directed, + edges - 1, + weights ) res } -similarity_jaccard_es_impl <- function( +community_fastgreedy_impl <- function( graph, - es = E(graph), - mode = c("all", "out", "in", "total"), - loops = FALSE + weights = NULL ) { # Argument checks ensure_igraph(graph) - es <- as_igraph_es(graph, es) - mode <- switch_igraph_arg( - mode, - "out" = 1L, - "in" = 2L, - "all" = 3L, - "total" = 3L - ) - loops <- as.logical(loops) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_similarity_jaccard_es, + R_igraph_community_fastgreedy, graph, - es - 1, - mode, - loops + weights ) res } -similarity_jaccard_pairs_impl <- function( - graph, - pairs, - mode = c("all", "out", "in", "total"), - loops = FALSE +community_to_membership_impl <- function( + merges, + nodes, + steps ) { # Argument checks - ensure_igraph(graph) - mode <- switch_igraph_arg( - mode, - "out" = 1L, - "in" = 2L, - "all" = 3L, - "total" = 3L - ) - loops <- as.logical(loops) + nodes <- as.numeric(nodes) + steps <- as.numeric(steps) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_similarity_jaccard_pairs, - graph, - pairs, - mode, - loops + R_igraph_community_to_membership, + merges, + nodes, + steps ) res } -compare_communities_impl <- function( - comm1, - comm2, - method = c("vi", "nmi", "split.join", "rand", "adjusted.rand") +le_community_to_membership_impl <- function( + merges, + steps, + membership ) { # Argument checks - comm1 <- as.numeric(comm1) - comm2 <- as.numeric(comm2) - method <- switch_igraph_arg( - method, - "vi" = 0L, - "nmi" = 1L, - "split.join" = 2L, - "rand" = 3L, - "adjusted.rand" = 4L - ) + steps <- as.numeric(steps) + membership <- as.numeric(membership) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_compare_communities, - comm1, - comm2, - method + R_igraph_le_community_to_membership, + merges, + steps, + membership ) res @@ -6269,6 +9073,22 @@ modularity_matrix_impl <- function( res } +reindex_membership_impl <- function( + membership +) { + # Argument checks + membership <- as.numeric(membership) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_reindex_membership, + membership + ) + + res +} + community_fluid_communities_impl <- function( graph, no_of_communities @@ -6519,7 +9339,7 @@ graphlets_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - Rx_igraph_graphlets, + R_igraph_graphlets, graph, weights, niter @@ -6829,6 +9649,38 @@ from_hrg_dendrogram_impl <- function( res } +get_adjacency_impl <- function( + graph, + type = c("both", "upper", "lower"), + weights = NULL, + loops = c("once", "none", "twice") +) { + # Argument checks + ensure_igraph(graph) + type <- switch_igraph_arg(type, "upper" = 0L, "lower" = 1L, "both" = 2L) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + loops <- switch_igraph_arg(loops, "none" = 0L, "twice" = 1L, "once" = 2L) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_get_adjacency, + graph, + type, + weights, + loops + ) + + res +} + get_adjacency_sparse_impl <- function( graph, type = c("both", "upper", "lower"), @@ -6985,6 +9837,83 @@ to_undirected_impl <- function( res } +read_graph_edgelist_impl <- function( + instream, + n = 0, + directed = TRUE +) { + # Argument checks + check_string(instream) + + n <- as.numeric(n) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_read_graph_edgelist, + instream, + n, + directed + ) + + res +} + +read_graph_ncol_impl <- function( + instream, + predefnames = NULL, + names = TRUE, + weights = TRUE, + directed = TRUE +) { + # Argument checks + check_string(instream) + + names <- as.logical(names) + weights <- switch_igraph_arg(weights, "no" = 0L, "yes" = 1L, "auto" = 2L) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_read_graph_ncol, + instream, + predefnames, + names, + weights, + directed + ) + + res +} + +read_graph_lgl_impl <- function( + instream, + names = TRUE, + weights = TRUE, + directed = TRUE +) { + # Argument checks + check_string(instream) + + names <- as.logical(names) + weights <- switch_igraph_arg(weights, "no" = 0L, "yes" = 1L, "auto" = 2L) + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_read_graph_lgl, + instream, + names, + weights, + directed + ) + + res +} + read_graph_pajek_impl <- function( instream ) { @@ -7022,6 +9951,26 @@ read_graph_graphml_impl <- function( res } +read_graph_dimacs_flow_impl <- function( + instream, + directed = TRUE +) { + # Argument checks + check_string(instream) + + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_read_graph_dimacs_flow, + instream, + directed + ) + + res +} + read_graph_graphdb_impl <- function( instream, directed = FALSE @@ -7064,36 +10013,87 @@ read_graph_dl_impl <- function( directed = TRUE ) { # Argument checks - check_string(instream) + check_string(instream) + + directed <- as.logical(directed) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_read_graph_dl, + instream, + directed + ) + + res +} + +write_graph_edgelist_impl <- function( + graph, + outstream +) { + # Argument checks + ensure_igraph(graph) + check_string(outstream) + + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_write_graph_edgelist, + graph, + outstream + ) + + res +} + +write_graph_ncol_impl <- function( + graph, + outstream, + names = "name", + weights = "weight" +) { + # Argument checks + ensure_igraph(graph) + check_string(outstream) - directed <- as.logical(directed) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_read_graph_dl, - instream, - directed + R_igraph_write_graph_ncol, + graph, + outstream, + names, + weights ) res } -write_graph_edgelist_impl <- function( +write_graph_lgl_impl <- function( graph, - outstream + outstream, + names = "name", + weights = "weight", + isolates = TRUE ) { # Argument checks ensure_igraph(graph) check_string(outstream) + isolates <- as.logical(isolates) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_write_graph_edgelist, + R_igraph_write_graph_lgl, graph, - outstream + outstream, + names, + weights, + isolates ) res @@ -7166,6 +10166,47 @@ write_graph_pajek_impl <- function( res } +write_graph_dimacs_flow_impl <- function( + graph, + outstream, + source = 0, + target = 0, + capacity +) { + # Argument checks + ensure_igraph(graph) + check_string(outstream) + + source <- as_igraph_vs(graph, source) + if (length(source) == 0) { + cli::cli_abort( + "{.arg source} must specify at least one vertex", + call = rlang::caller_env() + ) + } + target <- as_igraph_vs(graph, target) + if (length(target) == 0) { + cli::cli_abort( + "{.arg target} must specify at least one vertex", + call = rlang::caller_env() + ) + } + capacity <- as.numeric(capacity) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_write_graph_dimacs_flow, + graph, + outstream, + source - 1, + target - 1, + capacity + ) + + res +} + write_graph_gml_impl <- function( graph, outstream, @@ -7974,6 +11015,50 @@ maxflow_impl <- function( res } +maxflow_value_impl <- function( + graph, + source, + target, + capacity = NULL +) { + # Argument checks + ensure_igraph(graph) + source <- as_igraph_vs(graph, source) + if (length(source) == 0) { + cli::cli_abort( + "{.arg source} must specify at least one vertex", + call = rlang::caller_env() + ) + } + target <- as_igraph_vs(graph, target) + if (length(target) == 0) { + cli::cli_abort( + "{.arg target} must specify at least one vertex", + call = rlang::caller_env() + ) + } + if (is.null(capacity) && "capacity" %in% edge_attr_names(graph)) { + capacity <- E(graph)$capacity + } + if (!is.null(capacity) && !all(is.na(capacity))) { + capacity <- as.numeric(capacity) + } else { + capacity <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_maxflow_value, + graph, + source - 1, + target - 1, + capacity + ) + + res +} + mincut_impl <- function( graph, capacity = NULL @@ -8049,54 +11134,211 @@ residual_graph_impl <- function( } else { capacity <- NULL } - flow <- as.numeric(flow) + flow <- as.numeric(flow) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_residual_graph, + graph, + capacity, + flow + ) + + res +} + +reverse_residual_graph_impl <- function( + graph, + capacity, + flow +) { + # Argument checks + ensure_igraph(graph) + if (is.null(capacity) && "capacity" %in% edge_attr_names(graph)) { + capacity <- E(graph)$capacity + } + if (!is.null(capacity) && !all(is.na(capacity))) { + capacity <- as.numeric(capacity) + } else { + capacity <- NULL + } + flow <- as.numeric(flow) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_reverse_residual_graph, + graph, + capacity, + flow + ) + + res +} + +st_mincut_impl <- function( + graph, + source, + target, + capacity = NULL +) { + # Argument checks + ensure_igraph(graph) + source <- as_igraph_vs(graph, source) + if (length(source) == 0) { + cli::cli_abort( + "{.arg source} must specify at least one vertex", + call = rlang::caller_env() + ) + } + target <- as_igraph_vs(graph, target) + if (length(target) == 0) { + cli::cli_abort( + "{.arg target} must specify at least one vertex", + call = rlang::caller_env() + ) + } + if (is.null(capacity) && "capacity" %in% edge_attr_names(graph)) { + capacity <- E(graph)$capacity + } + if (!is.null(capacity) && !all(is.na(capacity))) { + capacity <- as.numeric(capacity) + } else { + capacity <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_st_mincut, + graph, + source - 1, + target - 1, + capacity + ) + if (igraph_opt("return.vs.es")) { + res$cut <- create_es(graph, res$cut) + } + if (igraph_opt("return.vs.es")) { + res$partition1 <- create_vs(graph, res$partition1) + } + if (igraph_opt("return.vs.es")) { + res$partition2 <- create_vs(graph, res$partition2) + } + res +} + +st_mincut_value_impl <- function( + graph, + source, + target, + capacity = NULL +) { + # Argument checks + ensure_igraph(graph) + source <- as_igraph_vs(graph, source) + if (length(source) == 0) { + cli::cli_abort( + "{.arg source} must specify at least one vertex", + call = rlang::caller_env() + ) + } + target <- as_igraph_vs(graph, target) + if (length(target) == 0) { + cli::cli_abort( + "{.arg target} must specify at least one vertex", + call = rlang::caller_env() + ) + } + if (is.null(capacity) && "capacity" %in% edge_attr_names(graph)) { + capacity <- E(graph)$capacity + } + if (!is.null(capacity) && !all(is.na(capacity))) { + capacity <- as.numeric(capacity) + } else { + capacity <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_st_mincut_value, + graph, + source - 1, + target - 1, + capacity + ) + + res +} + +st_vertex_connectivity_impl <- function( + graph, + source, + target, + neighbors = c("number_of_nodes", "error", "ignore", "negative") +) { + # Argument checks + ensure_igraph(graph) + source <- as_igraph_vs(graph, source) + if (length(source) == 0) { + cli::cli_abort( + "{.arg source} must specify at least one vertex", + call = rlang::caller_env() + ) + } + target <- as_igraph_vs(graph, target) + if (length(target) == 0) { + cli::cli_abort( + "{.arg target} must specify at least one vertex", + call = rlang::caller_env() + ) + } + neighbors <- switch_igraph_arg( + neighbors, + "error" = 0L, + "number_of_nodes" = 1L, + "ignore" = 2L, + "negative" = 3L + ) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_residual_graph, + R_igraph_st_vertex_connectivity, graph, - capacity, - flow + source - 1, + target - 1, + neighbors ) res } -reverse_residual_graph_impl <- function( +vertex_connectivity_impl <- function( graph, - capacity, - flow + checks = TRUE ) { # Argument checks ensure_igraph(graph) - if (is.null(capacity) && "capacity" %in% edge_attr_names(graph)) { - capacity <- E(graph)$capacity - } - if (!is.null(capacity) && !all(is.na(capacity))) { - capacity <- as.numeric(capacity) - } else { - capacity <- NULL - } - flow <- as.numeric(flow) + checks <- as.logical(checks) on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_reverse_residual_graph, + R_igraph_vertex_connectivity, graph, - capacity, - flow + checks ) res } -st_mincut_impl <- function( +st_edge_connectivity_impl <- function( graph, source, - target, - capacity = NULL + target ) { # Argument checks ensure_igraph(graph) @@ -8114,37 +11356,20 @@ st_mincut_impl <- function( call = rlang::caller_env() ) } - if (is.null(capacity) && "capacity" %in% edge_attr_names(graph)) { - capacity <- E(graph)$capacity - } - if (!is.null(capacity) && !all(is.na(capacity))) { - capacity <- as.numeric(capacity) - } else { - capacity <- NULL - } on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_st_mincut, + R_igraph_st_edge_connectivity, graph, source - 1, - target - 1, - capacity + target - 1 ) - if (igraph_opt("return.vs.es")) { - res$cut <- create_es(graph, res$cut) - } - if (igraph_opt("return.vs.es")) { - res$partition1 <- create_vs(graph, res$partition1) - } - if (igraph_opt("return.vs.es")) { - res$partition2 <- create_vs(graph, res$partition2) - } + res } -vertex_connectivity_impl <- function( +edge_connectivity_impl <- function( graph, checks = TRUE ) { @@ -8155,7 +11380,7 @@ vertex_connectivity_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_vertex_connectivity, + R_igraph_edge_connectivity, graph, checks ) @@ -8163,20 +11388,69 @@ vertex_connectivity_impl <- function( res } -edge_connectivity_impl <- function( +edge_disjoint_paths_impl <- function( graph, - checks = TRUE + source, + target ) { # Argument checks ensure_igraph(graph) - checks <- as.logical(checks) + source <- as_igraph_vs(graph, source) + if (length(source) == 0) { + cli::cli_abort( + "{.arg source} must specify at least one vertex", + call = rlang::caller_env() + ) + } + target <- as_igraph_vs(graph, target) + if (length(target) == 0) { + cli::cli_abort( + "{.arg target} must specify at least one vertex", + call = rlang::caller_env() + ) + } on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - R_igraph_edge_connectivity, + R_igraph_edge_disjoint_paths, graph, - checks + source - 1, + target - 1 + ) + + res +} + +vertex_disjoint_paths_impl <- function( + graph, + source, + target +) { + # Argument checks + ensure_igraph(graph) + source <- as_igraph_vs(graph, source) + if (length(source) == 0) { + cli::cli_abort( + "{.arg source} must specify at least one vertex", + call = rlang::caller_env() + ) + } + target <- as_igraph_vs(graph, target) + if (length(target) == 0) { + cli::cli_abort( + "{.arg target} must specify at least one vertex", + call = rlang::caller_env() + ) + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_vertex_disjoint_paths, + graph, + source - 1, + target - 1 ) res @@ -9381,7 +12655,7 @@ adjacency_spectral_embedding_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - Rx_igraph_adjacency_spectral_embedding, + R_igraph_adjacency_spectral_embedding, graph, no, weights, @@ -9424,7 +12698,7 @@ laplacian_spectral_embedding_impl <- function( on.exit(.Call(R_igraph_finalizer)) # Function call res <- .Call( - Rx_igraph_laplacian_spectral_embedding, + R_igraph_laplacian_spectral_embedding, graph, no, weights, @@ -9539,6 +12813,28 @@ running_mean_impl <- function( res } +random_sample_impl <- function( + l, + h, + length +) { + # Argument checks + l <- as.numeric(l) + h <- as.numeric(h) + length <- as.numeric(length) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_random_sample, + l, + h, + length + ) + + res +} + convex_hull_2d_impl <- function( data ) { @@ -9571,6 +12867,46 @@ dim_select_impl <- function( res } +almost_equals_impl <- function( + a, + b, + eps +) { + # Argument checks + + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_almost_equals, + a, + b, + eps + ) + + res +} + +cmp_epsilon_impl <- function( + a, + b, + eps +) { + # Argument checks + + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_cmp_epsilon, + a, + b, + eps + ) + + res +} + solve_lsap_impl <- function( c, n @@ -9927,6 +13263,34 @@ is_complete_impl <- function( res } +minimum_spanning_tree_impl <- function( + graph, + weights = NULL +) { + # Argument checks + ensure_igraph(graph) + if (is.null(weights) && "weight" %in% edge_attr_names(graph)) { + weights <- E(graph)$weight + } + if (!is.null(weights) && !all(is.na(weights))) { + weights <- as.numeric(weights) + } else { + weights <- NULL + } + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_minimum_spanning_tree, + graph, + weights + ) + if (igraph_opt("return.vs.es")) { + res <- create_es(graph, res) + } + res +} + minimum_spanning_tree_unweighted_impl <- function( graph ) { @@ -10284,6 +13648,104 @@ stochastic_imitation_impl <- function( res } +convergence_degree_impl <- function( + graph +) { + # Argument checks + ensure_igraph(graph) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_convergence_degree, + graph + ) + + res +} + +has_attribute_table_impl <- function( +) { + # Argument checks + + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_has_attribute_table + ) + + res +} + +progress_impl <- function( + message, + percent +) { + # Argument checks + percent <- as.numeric(percent) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_progress, + message, + percent + ) + + res +} + +status_impl <- function( + message +) { + # Argument checks + + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_status, + message + ) + + res +} + +strerror_impl <- function( + igraph_errno +) { + # Argument checks + + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_strerror, + igraph_errno + ) + + res +} + +expand_path_to_pairs_impl <- function( + path +) { + # Argument checks + path <- as_igraph_vs(path, path) + + on.exit(.Call(R_igraph_finalizer)) + # Function call + res <- .Call( + R_igraph_expand_path_to_pairs, + path - 1 + ) + if (igraph_opt("return.vs.es")) { + res <- create_vs(path, res) + } + res +} + invalidate_cache_impl <- function( graph ) { @@ -10364,7 +13826,9 @@ motifs_randesu_callback_closure_impl <- function( # Argument checks ensure_igraph(graph) size <- as.numeric(size) - if (!is.null(cut_prob)) cut_prob <- as.numeric(cut_prob) + if (!is.null(cut_prob)) { + cut_prob <- as.numeric(cut_prob) + } if (!is.function(callback)) { cli::cli_abort("{.arg callback} must be a function") } diff --git a/src/cpp11.cpp b/src/cpp11.cpp index 60908db7ed..686abff050 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -22,35 +22,48 @@ extern "C" SEXP _igraph_getsphere(SEXP spos, SEXP sradius, SEXP scolor, SEXP lig extern "C" { /* .Call calls */ +extern SEXP R_igraph_add_edge(SEXP, SEXP, SEXP); extern SEXP R_igraph_add_edges(SEXP, SEXP); extern SEXP R_igraph_add_vertices(SEXP, SEXP); extern SEXP R_igraph_adhesion(SEXP, SEXP); +extern SEXP R_igraph_adjacency(SEXP, SEXP, SEXP); +extern SEXP R_igraph_adjacency_spectral_embedding(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_adjlist(SEXP, SEXP, SEXP); extern SEXP R_igraph_all_minimal_st_separators(SEXP); extern SEXP R_igraph_all_st_cuts(SEXP, SEXP, SEXP); extern SEXP R_igraph_all_st_mincuts(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_almost_equals(SEXP, SEXP, SEXP); extern SEXP R_igraph_are_adjacent(SEXP, SEXP, SEXP); +extern SEXP R_igraph_are_connected(SEXP, SEXP, SEXP); extern SEXP R_igraph_articulation_points(SEXP); extern SEXP R_igraph_assortativity(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_assortativity_degree(SEXP, SEXP); extern SEXP R_igraph_assortativity_nominal(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_asymmetric_preference_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_atlas(SEXP); +extern SEXP R_igraph_authority_score(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_automorphism_group(SEXP, SEXP, SEXP); extern SEXP R_igraph_average_local_efficiency(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_average_path_length(SEXP, SEXP, SEXP); extern SEXP R_igraph_average_path_length_dijkstra(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_avg_nearest_neighbor_degree(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_barabasi_aging_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_barabasi_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_betweenness(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_betweenness_cutoff(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_betweenness_subset(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_bfs_simple(SEXP, SEXP, SEXP); extern SEXP R_igraph_biadjacency(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_bibcoupling(SEXP, SEXP); extern SEXP R_igraph_biconnected_components(SEXP); +extern SEXP R_igraph_bipartite_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_bipartite_game_gnm(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_bipartite_game_gnp(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_bipartite_projection(SEXP, SEXP, SEXP); extern SEXP R_igraph_bipartite_projection_size(SEXP, SEXP); extern SEXP R_igraph_bond_percolation(SEXP, SEXP); extern SEXP R_igraph_bridges(SEXP); +extern SEXP R_igraph_callaway_traits_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_canonical_permutation(SEXP, SEXP, SEXP); extern SEXP R_igraph_centralization(SEXP, SEXP, SEXP); extern SEXP R_igraph_centralization_betweenness(SEXP, SEXP, SEXP); @@ -63,26 +76,38 @@ extern SEXP R_igraph_centralization_eigenvector_centrality(SEXP, SEXP, SEXP, SEX extern SEXP R_igraph_centralization_eigenvector_centrality_tmax(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_chung_lu_game(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_circulant(SEXP, SEXP, SEXP); +extern SEXP R_igraph_cited_type_game(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_citing_cited_type_game(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_clique_number(SEXP); extern SEXP R_igraph_clique_size_hist(SEXP, SEXP, SEXP); extern SEXP R_igraph_cliques(SEXP, SEXP, SEXP); extern SEXP R_igraph_closeness(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_closeness_cutoff(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_cmp_epsilon(SEXP, SEXP, SEXP); extern SEXP R_igraph_cocitation(SEXP, SEXP); extern SEXP R_igraph_cohesion(SEXP, SEXP); extern SEXP R_igraph_cohesive_blocks(SEXP); +extern SEXP R_igraph_community_eb_get_merges(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_community_edge_betweenness(SEXP, SEXP, SEXP); +extern SEXP R_igraph_community_fastgreedy(SEXP, SEXP); extern SEXP R_igraph_community_fluid_communities(SEXP, SEXP); extern SEXP R_igraph_community_infomap(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_community_label_propagation(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_community_leiden(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_community_multilevel(SEXP, SEXP, SEXP); extern SEXP R_igraph_community_optimal_modularity(SEXP, SEXP); +extern SEXP R_igraph_community_spinglass(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_community_spinglass_single(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_community_to_membership(SEXP, SEXP, SEXP); +extern SEXP R_igraph_community_walktrap(SEXP, SEXP, SEXP); extern SEXP R_igraph_compare_communities(SEXP, SEXP, SEXP); extern SEXP R_igraph_complementer(SEXP, SEXP); extern SEXP R_igraph_compose(SEXP, SEXP); +extern SEXP R_igraph_connect_neighborhood(SEXP, SEXP, SEXP); extern SEXP R_igraph_connected_components(SEXP, SEXP); extern SEXP R_igraph_constraint(SEXP, SEXP, SEXP); extern SEXP R_igraph_contract_vertices(SEXP, SEXP, SEXP); +extern SEXP R_igraph_convergence_degree(SEXP); extern SEXP R_igraph_convex_hull_2d(SEXP); extern SEXP R_igraph_copy(SEXP); extern SEXP R_igraph_coreness(SEXP, SEXP); @@ -96,39 +121,58 @@ extern SEXP R_igraph_count_multiple(SEXP, SEXP); extern SEXP R_igraph_count_reachable(SEXP, SEXP); extern SEXP R_igraph_count_subisomorphisms_vf2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_count_triangles(SEXP); +extern SEXP R_igraph_create(SEXP, SEXP, SEXP); +extern SEXP R_igraph_create_bipartite(SEXP, SEXP, SEXP); extern SEXP R_igraph_cycle_graph(SEXP, SEXP, SEXP); extern SEXP R_igraph_de_bruijn(SEXP, SEXP); +extern SEXP R_igraph_decompose(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_degree(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_degree_correlation_vector(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_degree_sequence_game(SEXP, SEXP, SEXP); extern SEXP R_igraph_delete_edges(SEXP, SEXP); extern SEXP R_igraph_delete_vertices(SEXP, SEXP); extern SEXP R_igraph_delete_vertices_idx(SEXP, SEXP); extern SEXP R_igraph_density(SEXP, SEXP); extern SEXP R_igraph_deterministic_optimal_imitation(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_diameter(SEXP, SEXP, SEXP); +extern SEXP R_igraph_diameter_dijkstra(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_difference(SEXP, SEXP); extern SEXP R_igraph_dim_select(SEXP); extern SEXP R_igraph_disjoint_union(SEXP, SEXP); +extern SEXP R_igraph_distances(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_distances_bellman_ford(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_distances_cutoff(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_distances_dijkstra(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_distances_dijkstra_cutoff(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_distances_floyd_warshall(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_distances_johnson(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_diversity(SEXP, SEXP, SEXP); extern SEXP R_igraph_dominator_tree(SEXP, SEXP, SEXP); extern SEXP R_igraph_dot_product_game(SEXP, SEXP); extern SEXP R_igraph_dyad_census(SEXP); extern SEXP R_igraph_ecc(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_eccentricity(SEXP, SEXP, SEXP); extern SEXP R_igraph_eccentricity_dijkstra(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_ecount(SEXP); +extern SEXP R_igraph_edge(SEXP, SEXP); extern SEXP R_igraph_edge_betweenness(SEXP, SEXP, SEXP); extern SEXP R_igraph_edge_betweenness_cutoff(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_edge_betweenness_subset(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_edge_connectivity(SEXP, SEXP); +extern SEXP R_igraph_edge_disjoint_paths(SEXP, SEXP, SEXP); extern SEXP R_igraph_edgelist_percolation(SEXP); extern SEXP R_igraph_edges(SEXP, SEXP); extern SEXP R_igraph_eigen_adjacency(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_eigenvector_centrality(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_empty(SEXP, SEXP); +extern SEXP R_igraph_empty_attrs(SEXP, SEXP); extern SEXP R_igraph_erdos_renyi_game_gnm(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_erdos_renyi_game_gnp(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_establishment_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_eulerian_cycle(SEXP); extern SEXP R_igraph_eulerian_path(SEXP); extern SEXP R_igraph_even_tarjan_reduction(SEXP); +extern SEXP R_igraph_expand_path_to_pairs(SEXP); extern SEXP R_igraph_extended_chordal_ring(SEXP, SEXP, SEXP); extern SEXP R_igraph_famous(SEXP); extern SEXP R_igraph_feedback_arc_set(SEXP, SEXP, SEXP); @@ -138,11 +182,13 @@ extern SEXP R_igraph_find_cycle(SEXP, SEXP); extern SEXP R_igraph_forest_fire_game(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_from_hrg_dendrogram(SEXP); extern SEXP R_igraph_from_prufer(SEXP); +extern SEXP R_igraph_full(SEXP, SEXP, SEXP); extern SEXP R_igraph_full_bipartite(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_full_citation(SEXP, SEXP); extern SEXP R_igraph_full_multipartite(SEXP, SEXP, SEXP); extern SEXP R_igraph_fundamental_cycles(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_generalized_petersen(SEXP, SEXP); +extern SEXP R_igraph_get_adjacency(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_adjacency_sparse(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_all_eids_between(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_all_shortest_paths(SEXP, SEXP, SEXP, SEXP); @@ -150,14 +196,19 @@ extern SEXP R_igraph_get_all_shortest_paths_dijkstra(SEXP, SEXP, SEXP, SEXP, SEX extern SEXP R_igraph_get_all_simple_paths(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_biadjacency(SEXP, SEXP); extern SEXP R_igraph_get_edgelist(SEXP, SEXP); +extern SEXP R_igraph_get_eids(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_isomorphisms_vf2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_isomorphisms_vf2_callback(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_k_shortest_paths(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_laplacian(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_laplacian_sparse(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_shortest_path(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_get_shortest_path_astar(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_shortest_path_bellman_ford(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_shortest_path_dijkstra(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_get_shortest_paths(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_get_shortest_paths_bellman_ford(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_get_shortest_paths_dijkstra(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_get_stochastic(SEXP, SEXP, SEXP); extern SEXP R_igraph_get_stochastic_sparse(SEXP, SEXP, SEXP); extern SEXP R_igraph_get_subisomorphisms_vf2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); @@ -166,13 +217,18 @@ extern SEXP R_igraph_get_widest_paths(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_girth(SEXP); extern SEXP R_igraph_global_efficiency(SEXP, SEXP, SEXP); extern SEXP R_igraph_gomory_hu_tree(SEXP, SEXP); +extern SEXP R_igraph_graph_center(SEXP, SEXP); extern SEXP R_igraph_graph_center_dijkstra(SEXP, SEXP, SEXP); extern SEXP R_igraph_graph_count(SEXP, SEXP); extern SEXP R_igraph_graph_power(SEXP, SEXP, SEXP); +extern SEXP R_igraph_graphlets(SEXP, SEXP, SEXP); extern SEXP R_igraph_graphlets_candidate_basis(SEXP, SEXP); extern SEXP R_igraph_graphlets_project(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_grg_game(SEXP, SEXP, SEXP); extern SEXP R_igraph_growing_random_game(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_harmonic_centrality(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_harmonic_centrality_cutoff(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_has_attribute_table(void); extern SEXP R_igraph_has_loop(SEXP); extern SEXP R_igraph_has_multiple(SEXP); extern SEXP R_igraph_has_mutual(SEXP, SEXP); @@ -188,17 +244,21 @@ extern SEXP R_igraph_hrg_size(SEXP); extern SEXP R_igraph_hsbm_game(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_hsbm_list_game(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_hub_and_authority_scores(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_hub_score(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_hypercube(SEXP, SEXP); extern SEXP R_igraph_incident(SEXP, SEXP, SEXP); extern SEXP R_igraph_independence_number(SEXP); +extern SEXP R_igraph_independent_vertex_sets(SEXP, SEXP, SEXP); extern SEXP R_igraph_induced_subgraph(SEXP, SEXP, SEXP); extern SEXP R_igraph_induced_subgraph_map(SEXP, SEXP, SEXP); extern SEXP R_igraph_intersection(SEXP, SEXP); extern SEXP R_igraph_invalidate_cache(SEXP); extern SEXP R_igraph_is_acyclic(SEXP); extern SEXP R_igraph_is_biconnected(SEXP); +extern SEXP R_igraph_is_bigraphical(SEXP, SEXP, SEXP); extern SEXP R_igraph_is_bipartite(SEXP); extern SEXP R_igraph_is_bipartite_coloring(SEXP, SEXP); +extern SEXP R_igraph_is_chordal(SEXP, SEXP, SEXP); extern SEXP R_igraph_is_clique(SEXP, SEXP, SEXP); extern SEXP R_igraph_is_complete(SEXP); extern SEXP R_igraph_is_connected(SEXP, SEXP); @@ -216,6 +276,7 @@ extern SEXP R_igraph_is_minimal_separator(SEXP, SEXP); extern SEXP R_igraph_is_multiple(SEXP, SEXP); extern SEXP R_igraph_is_mutual(SEXP, SEXP, SEXP); extern SEXP R_igraph_is_perfect(SEXP); +extern SEXP R_igraph_is_same_graph(SEXP, SEXP); extern SEXP R_igraph_is_separator(SEXP, SEXP); extern SEXP R_igraph_is_simple(SEXP); extern SEXP R_igraph_is_tree(SEXP, SEXP); @@ -231,20 +292,33 @@ extern SEXP R_igraph_joint_degree_distribution(SEXP, SEXP, SEXP, SEXP, SEXP, SEX extern SEXP R_igraph_joint_degree_matrix(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_joint_type_distribution(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_k_regular_game(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_kary_tree(SEXP, SEXP, SEXP); extern SEXP R_igraph_kautz(SEXP, SEXP); +extern SEXP R_igraph_laplacian_spectral_embedding(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_largest_cliques(SEXP); extern SEXP R_igraph_largest_independent_vertex_sets(SEXP); extern SEXP R_igraph_largest_weighted_cliques(SEXP, SEXP); +extern SEXP R_igraph_lastcit_game(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_align(SEXP, SEXP); extern SEXP R_igraph_layout_bipartite(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_circle(SEXP, SEXP); extern SEXP R_igraph_layout_davidson_harel(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_drl(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_drl_3d(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_fruchterman_reingold(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_fruchterman_reingold_3d(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_gem(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_graphopt(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_grid(SEXP, SEXP); extern SEXP R_igraph_layout_grid_3d(SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_kamada_kawai(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_kamada_kawai_3d(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_lgl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_mds(SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_random(SEXP); extern SEXP R_igraph_layout_random_3d(SEXP); +extern SEXP R_igraph_layout_reingold_tilford(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_layout_reingold_tilford_circular(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_sphere(SEXP); extern SEXP R_igraph_layout_star(SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_sugiyama(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); @@ -252,6 +326,7 @@ extern SEXP R_igraph_layout_umap(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_umap_3d(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_layout_umap_compute_weights(SEXP, SEXP, SEXP); extern SEXP R_igraph_lcf_vector(SEXP, SEXP, SEXP); +extern SEXP R_igraph_le_community_to_membership(SEXP, SEXP, SEXP); extern SEXP R_igraph_linegraph(SEXP); extern SEXP R_igraph_list_triangles(SEXP); extern SEXP R_igraph_local_efficiency(SEXP, SEXP, SEXP, SEXP, SEXP); @@ -265,8 +340,12 @@ extern SEXP R_igraph_local_scan_neighborhood_ecount(SEXP, SEXP, SEXP); extern SEXP R_igraph_local_scan_subset_ecount(SEXP, SEXP, SEXP); extern SEXP R_igraph_maxdegree(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_maxflow(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_maxflow_value(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_maximal_cliques(SEXP, SEXP, SEXP); extern SEXP R_igraph_maximal_cliques_count(SEXP, SEXP, SEXP); +extern SEXP R_igraph_maximal_cliques_file(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_maximal_cliques_hist(SEXP, SEXP, SEXP); +extern SEXP R_igraph_maximal_cliques_subset(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_maximal_independent_vertex_sets(SEXP); extern SEXP R_igraph_maximum_bipartite_matching(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_maximum_cardinality_search(SEXP); @@ -275,6 +354,7 @@ extern SEXP R_igraph_mincut(SEXP, SEXP); extern SEXP R_igraph_mincut_value(SEXP, SEXP); extern SEXP R_igraph_minimum_cycle_basis(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_minimum_size_separators(SEXP); +extern SEXP R_igraph_minimum_spanning_tree(SEXP, SEXP); extern SEXP R_igraph_minimum_spanning_tree_prim(SEXP, SEXP); extern SEXP R_igraph_minimum_spanning_tree_unweighted(SEXP); extern SEXP R_igraph_modularity(SEXP, SEXP, SEXP, SEXP, SEXP); @@ -286,7 +366,11 @@ extern SEXP R_igraph_motifs_randesu_estimate(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_motifs_randesu_no(SEXP, SEXP, SEXP); extern SEXP R_igraph_mycielski_graph(SEXP); extern SEXP R_igraph_mycielskian(SEXP, SEXP); +extern SEXP R_igraph_neighborhood(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_neighborhood_graphs(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_neighborhood_size(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_neighbors(SEXP, SEXP, SEXP); +extern SEXP R_igraph_pagerank(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_path_graph(SEXP, SEXP, SEXP); extern SEXP R_igraph_path_length_hist(SEXP, SEXP); extern SEXP R_igraph_permute_vertices(SEXP, SEXP); @@ -295,20 +379,31 @@ extern SEXP R_igraph_personalized_pagerank_vs(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP extern SEXP R_igraph_power_law_fit(SEXP, SEXP, SEXP); extern SEXP R_igraph_preference_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_product(SEXP, SEXP, SEXP); +extern SEXP R_igraph_progress(SEXP, SEXP); extern SEXP R_igraph_pseudo_diameter(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_pseudo_diameter_dijkstra(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_radius(SEXP, SEXP); extern SEXP R_igraph_radius_dijkstra(SEXP, SEXP, SEXP); +extern SEXP R_igraph_random_edge_walk(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_random_sample(SEXP, SEXP, SEXP); extern SEXP R_igraph_random_spanning_tree(SEXP, SEXP); extern SEXP R_igraph_random_walk(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_read_graph_dimacs_flow(SEXP, SEXP); extern SEXP R_igraph_read_graph_dl(SEXP, SEXP); +extern SEXP R_igraph_read_graph_edgelist(SEXP, SEXP, SEXP); extern SEXP R_igraph_read_graph_gml(SEXP); extern SEXP R_igraph_read_graph_graphdb(SEXP, SEXP); extern SEXP R_igraph_read_graph_graphml(SEXP, SEXP); +extern SEXP R_igraph_read_graph_lgl(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_read_graph_ncol(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_read_graph_pajek(SEXP); extern SEXP R_igraph_realize_bipartite_degree_sequence(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_realize_degree_sequence(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_recent_degree_aging_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_recent_degree_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_reciprocity(SEXP, SEXP, SEXP); extern SEXP R_igraph_regular_tree(SEXP, SEXP, SEXP); +extern SEXP R_igraph_reindex_membership(SEXP); extern SEXP R_igraph_residual_graph(SEXP, SEXP, SEXP); extern SEXP R_igraph_reverse_edges(SEXP, SEXP); extern SEXP R_igraph_reverse_residual_graph(SEXP, SEXP, SEXP); @@ -316,6 +411,7 @@ extern SEXP R_igraph_rewire(SEXP, SEXP, SEXP); extern SEXP R_igraph_rewire_directed_edges(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_rewire_edges(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_rich_club_sequence(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_ring(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_rooted_product(SEXP, SEXP, SEXP); extern SEXP R_igraph_roots_for_tree_layout(SEXP, SEXP, SEXP); extern SEXP R_igraph_roulette_wheel_imitation(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); @@ -341,11 +437,18 @@ extern SEXP R_igraph_solve_lsap(SEXP, SEXP); extern SEXP R_igraph_spanner(SEXP, SEXP, SEXP); extern SEXP R_igraph_split_join_distance(SEXP, SEXP); extern SEXP R_igraph_square_lattice(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_st_edge_connectivity(SEXP, SEXP, SEXP); extern SEXP R_igraph_st_mincut(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_st_mincut_value(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_st_vertex_connectivity(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_star(SEXP, SEXP, SEXP); extern SEXP R_igraph_static_fitness_game(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_static_power_law_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_status(SEXP); extern SEXP R_igraph_stochastic_imitation(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_strength(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_strerror(SEXP); +extern SEXP R_igraph_subcomponent(SEXP, SEXP, SEXP); extern SEXP R_igraph_subgraph_from_edges(SEXP, SEXP, SEXP); extern SEXP R_igraph_subisomorphic(SEXP, SEXP); extern SEXP R_igraph_subisomorphic_vf2(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); @@ -372,18 +475,24 @@ extern SEXP R_igraph_vcount(SEXP); extern SEXP R_igraph_version(void); extern SEXP R_igraph_vertex_coloring_greedy(SEXP, SEXP); extern SEXP R_igraph_vertex_connectivity(SEXP, SEXP); +extern SEXP R_igraph_vertex_disjoint_paths(SEXP, SEXP, SEXP); extern SEXP R_igraph_vertex_path_from_edge_path(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_voronoi(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_watts_strogatz_game(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_weighted_adjacency(SEXP, SEXP, SEXP); extern SEXP R_igraph_weighted_clique_number(SEXP, SEXP); extern SEXP R_igraph_weighted_cliques(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_wheel(SEXP, SEXP, SEXP); extern SEXP R_igraph_widest_path_widths_dijkstra(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_widest_path_widths_floyd_warshall(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_write_graph_dimacs_flow(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_write_graph_dot(SEXP, SEXP); extern SEXP R_igraph_write_graph_edgelist(SEXP, SEXP); extern SEXP R_igraph_write_graph_gml(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_write_graph_graphml(SEXP, SEXP, SEXP); extern SEXP R_igraph_write_graph_leda(SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_write_graph_lgl(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP R_igraph_write_graph_ncol(SEXP, SEXP, SEXP, SEXP); extern SEXP R_igraph_write_graph_pajek(SEXP, SEXP); extern SEXP Rx_igraph_add_edges_manual(SEXP, SEXP); extern SEXP Rx_igraph_add_env(SEXP); @@ -391,7 +500,6 @@ extern SEXP Rx_igraph_add_myid_to_env(SEXP); extern SEXP Rx_igraph_add_version_to_env(SEXP); extern SEXP Rx_igraph_address(SEXP); extern SEXP Rx_igraph_adjacency(SEXP, SEXP, SEXP); -extern SEXP Rx_igraph_adjacency_spectral_embedding(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP Rx_igraph_adjacent_vertices(SEXP, SEXP, SEXP); extern SEXP Rx_igraph_arpack(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP Rx_igraph_arpack_unpack_complex(SEXP, SEXP, SEXP); @@ -440,7 +548,6 @@ extern SEXP Rx_igraph_get_graph_id(SEXP); extern SEXP Rx_igraph_get_shortest_paths(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP Rx_igraph_girth(SEXP, SEXP); extern SEXP Rx_igraph_graph_version(SEXP); -extern SEXP Rx_igraph_graphlets(SEXP, SEXP, SEXP); extern SEXP Rx_igraph_grg_game(SEXP, SEXP, SEXP, SEXP); extern SEXP Rx_igraph_i_levc_arp(SEXP, SEXP, SEXP); extern SEXP Rx_igraph_identical_graphs(SEXP, SEXP, SEXP); @@ -449,7 +556,6 @@ extern SEXP Rx_igraph_independent_vertex_sets(SEXP, SEXP, SEXP); extern SEXP Rx_igraph_intersection(SEXP, SEXP); extern SEXP Rx_igraph_is_chordal(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP Rx_igraph_kary_tree(SEXP, SEXP, SEXP); -extern SEXP Rx_igraph_laplacian_spectral_embedding(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP Rx_igraph_lastcit_game(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP Rx_igraph_layout_drl(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP Rx_igraph_layout_drl_3d(SEXP, SEXP, SEXP, SEXP, SEXP); @@ -510,35 +616,48 @@ extern SEXP Rx_igraph_write_graph_ncol(SEXP, SEXP, SEXP, SEXP); extern SEXP UUID_gen(SEXP); static const R_CallMethodDef CallEntries[] = { + {"R_igraph_add_edge", (DL_FUNC) &R_igraph_add_edge, 3}, {"R_igraph_add_edges", (DL_FUNC) &R_igraph_add_edges, 2}, {"R_igraph_add_vertices", (DL_FUNC) &R_igraph_add_vertices, 2}, {"R_igraph_adhesion", (DL_FUNC) &R_igraph_adhesion, 2}, + {"R_igraph_adjacency", (DL_FUNC) &R_igraph_adjacency, 3}, + {"R_igraph_adjacency_spectral_embedding", (DL_FUNC) &R_igraph_adjacency_spectral_embedding, 7}, {"R_igraph_adjlist", (DL_FUNC) &R_igraph_adjlist, 3}, {"R_igraph_all_minimal_st_separators", (DL_FUNC) &R_igraph_all_minimal_st_separators, 1}, {"R_igraph_all_st_cuts", (DL_FUNC) &R_igraph_all_st_cuts, 3}, {"R_igraph_all_st_mincuts", (DL_FUNC) &R_igraph_all_st_mincuts, 4}, + {"R_igraph_almost_equals", (DL_FUNC) &R_igraph_almost_equals, 3}, {"R_igraph_are_adjacent", (DL_FUNC) &R_igraph_are_adjacent, 3}, + {"R_igraph_are_connected", (DL_FUNC) &R_igraph_are_connected, 3}, {"R_igraph_articulation_points", (DL_FUNC) &R_igraph_articulation_points, 1}, {"R_igraph_assortativity", (DL_FUNC) &R_igraph_assortativity, 5}, {"R_igraph_assortativity_degree", (DL_FUNC) &R_igraph_assortativity_degree, 2}, {"R_igraph_assortativity_nominal", (DL_FUNC) &R_igraph_assortativity_nominal, 4}, {"R_igraph_asymmetric_preference_game", (DL_FUNC) &R_igraph_asymmetric_preference_game, 6}, {"R_igraph_atlas", (DL_FUNC) &R_igraph_atlas, 1}, + {"R_igraph_authority_score", (DL_FUNC) &R_igraph_authority_score, 4}, {"R_igraph_automorphism_group", (DL_FUNC) &R_igraph_automorphism_group, 3}, {"R_igraph_average_local_efficiency", (DL_FUNC) &R_igraph_average_local_efficiency, 4}, + {"R_igraph_average_path_length", (DL_FUNC) &R_igraph_average_path_length, 3}, {"R_igraph_average_path_length_dijkstra", (DL_FUNC) &R_igraph_average_path_length_dijkstra, 4}, {"R_igraph_avg_nearest_neighbor_degree", (DL_FUNC) &R_igraph_avg_nearest_neighbor_degree, 5}, + {"R_igraph_barabasi_aging_game", (DL_FUNC) &R_igraph_barabasi_aging_game, 12}, + {"R_igraph_barabasi_game", (DL_FUNC) &R_igraph_barabasi_game, 9}, + {"R_igraph_betweenness", (DL_FUNC) &R_igraph_betweenness, 4}, {"R_igraph_betweenness_cutoff", (DL_FUNC) &R_igraph_betweenness_cutoff, 5}, {"R_igraph_betweenness_subset", (DL_FUNC) &R_igraph_betweenness_subset, 6}, {"R_igraph_bfs_simple", (DL_FUNC) &R_igraph_bfs_simple, 3}, {"R_igraph_biadjacency", (DL_FUNC) &R_igraph_biadjacency, 4}, {"R_igraph_bibcoupling", (DL_FUNC) &R_igraph_bibcoupling, 2}, {"R_igraph_biconnected_components", (DL_FUNC) &R_igraph_biconnected_components, 1}, + {"R_igraph_bipartite_game", (DL_FUNC) &R_igraph_bipartite_game, 7}, {"R_igraph_bipartite_game_gnm", (DL_FUNC) &R_igraph_bipartite_game_gnm, 5}, {"R_igraph_bipartite_game_gnp", (DL_FUNC) &R_igraph_bipartite_game_gnp, 5}, + {"R_igraph_bipartite_projection", (DL_FUNC) &R_igraph_bipartite_projection, 3}, {"R_igraph_bipartite_projection_size", (DL_FUNC) &R_igraph_bipartite_projection_size, 2}, {"R_igraph_bond_percolation", (DL_FUNC) &R_igraph_bond_percolation, 2}, {"R_igraph_bridges", (DL_FUNC) &R_igraph_bridges, 1}, + {"R_igraph_callaway_traits_game", (DL_FUNC) &R_igraph_callaway_traits_game, 6}, {"R_igraph_canonical_permutation", (DL_FUNC) &R_igraph_canonical_permutation, 3}, {"R_igraph_centralization", (DL_FUNC) &R_igraph_centralization, 3}, {"R_igraph_centralization_betweenness", (DL_FUNC) &R_igraph_centralization_betweenness, 3}, @@ -551,26 +670,38 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_centralization_eigenvector_centrality_tmax", (DL_FUNC) &R_igraph_centralization_eigenvector_centrality_tmax, 4}, {"R_igraph_chung_lu_game", (DL_FUNC) &R_igraph_chung_lu_game, 4}, {"R_igraph_circulant", (DL_FUNC) &R_igraph_circulant, 3}, + {"R_igraph_cited_type_game", (DL_FUNC) &R_igraph_cited_type_game, 5}, + {"R_igraph_citing_cited_type_game", (DL_FUNC) &R_igraph_citing_cited_type_game, 5}, {"R_igraph_clique_number", (DL_FUNC) &R_igraph_clique_number, 1}, {"R_igraph_clique_size_hist", (DL_FUNC) &R_igraph_clique_size_hist, 3}, {"R_igraph_cliques", (DL_FUNC) &R_igraph_cliques, 3}, {"R_igraph_closeness", (DL_FUNC) &R_igraph_closeness, 5}, {"R_igraph_closeness_cutoff", (DL_FUNC) &R_igraph_closeness_cutoff, 6}, + {"R_igraph_cmp_epsilon", (DL_FUNC) &R_igraph_cmp_epsilon, 3}, {"R_igraph_cocitation", (DL_FUNC) &R_igraph_cocitation, 2}, {"R_igraph_cohesion", (DL_FUNC) &R_igraph_cohesion, 2}, {"R_igraph_cohesive_blocks", (DL_FUNC) &R_igraph_cohesive_blocks, 1}, + {"R_igraph_community_eb_get_merges", (DL_FUNC) &R_igraph_community_eb_get_merges, 4}, + {"R_igraph_community_edge_betweenness", (DL_FUNC) &R_igraph_community_edge_betweenness, 3}, + {"R_igraph_community_fastgreedy", (DL_FUNC) &R_igraph_community_fastgreedy, 2}, {"R_igraph_community_fluid_communities", (DL_FUNC) &R_igraph_community_fluid_communities, 2}, {"R_igraph_community_infomap", (DL_FUNC) &R_igraph_community_infomap, 4}, {"R_igraph_community_label_propagation", (DL_FUNC) &R_igraph_community_label_propagation, 5}, {"R_igraph_community_leiden", (DL_FUNC) &R_igraph_community_leiden, 8}, {"R_igraph_community_multilevel", (DL_FUNC) &R_igraph_community_multilevel, 3}, {"R_igraph_community_optimal_modularity", (DL_FUNC) &R_igraph_community_optimal_modularity, 2}, + {"R_igraph_community_spinglass", (DL_FUNC) &R_igraph_community_spinglass, 11}, + {"R_igraph_community_spinglass_single", (DL_FUNC) &R_igraph_community_spinglass_single, 6}, + {"R_igraph_community_to_membership", (DL_FUNC) &R_igraph_community_to_membership, 3}, + {"R_igraph_community_walktrap", (DL_FUNC) &R_igraph_community_walktrap, 3}, {"R_igraph_compare_communities", (DL_FUNC) &R_igraph_compare_communities, 3}, {"R_igraph_complementer", (DL_FUNC) &R_igraph_complementer, 2}, {"R_igraph_compose", (DL_FUNC) &R_igraph_compose, 2}, + {"R_igraph_connect_neighborhood", (DL_FUNC) &R_igraph_connect_neighborhood, 3}, {"R_igraph_connected_components", (DL_FUNC) &R_igraph_connected_components, 2}, {"R_igraph_constraint", (DL_FUNC) &R_igraph_constraint, 3}, {"R_igraph_contract_vertices", (DL_FUNC) &R_igraph_contract_vertices, 3}, + {"R_igraph_convergence_degree", (DL_FUNC) &R_igraph_convergence_degree, 1}, {"R_igraph_convex_hull_2d", (DL_FUNC) &R_igraph_convex_hull_2d, 1}, {"R_igraph_copy", (DL_FUNC) &R_igraph_copy, 1}, {"R_igraph_coreness", (DL_FUNC) &R_igraph_coreness, 2}, @@ -584,39 +715,58 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_count_reachable", (DL_FUNC) &R_igraph_count_reachable, 2}, {"R_igraph_count_subisomorphisms_vf2", (DL_FUNC) &R_igraph_count_subisomorphisms_vf2, 6}, {"R_igraph_count_triangles", (DL_FUNC) &R_igraph_count_triangles, 1}, + {"R_igraph_create", (DL_FUNC) &R_igraph_create, 3}, + {"R_igraph_create_bipartite", (DL_FUNC) &R_igraph_create_bipartite, 3}, {"R_igraph_cycle_graph", (DL_FUNC) &R_igraph_cycle_graph, 3}, {"R_igraph_de_bruijn", (DL_FUNC) &R_igraph_de_bruijn, 2}, + {"R_igraph_decompose", (DL_FUNC) &R_igraph_decompose, 4}, {"R_igraph_degree", (DL_FUNC) &R_igraph_degree, 4}, {"R_igraph_degree_correlation_vector", (DL_FUNC) &R_igraph_degree_correlation_vector, 5}, + {"R_igraph_degree_sequence_game", (DL_FUNC) &R_igraph_degree_sequence_game, 3}, {"R_igraph_delete_edges", (DL_FUNC) &R_igraph_delete_edges, 2}, {"R_igraph_delete_vertices", (DL_FUNC) &R_igraph_delete_vertices, 2}, {"R_igraph_delete_vertices_idx", (DL_FUNC) &R_igraph_delete_vertices_idx, 2}, {"R_igraph_density", (DL_FUNC) &R_igraph_density, 2}, {"R_igraph_deterministic_optimal_imitation", (DL_FUNC) &R_igraph_deterministic_optimal_imitation, 6}, + {"R_igraph_diameter", (DL_FUNC) &R_igraph_diameter, 3}, + {"R_igraph_diameter_dijkstra", (DL_FUNC) &R_igraph_diameter_dijkstra, 4}, {"R_igraph_difference", (DL_FUNC) &R_igraph_difference, 2}, {"R_igraph_dim_select", (DL_FUNC) &R_igraph_dim_select, 1}, {"R_igraph_disjoint_union", (DL_FUNC) &R_igraph_disjoint_union, 2}, + {"R_igraph_distances", (DL_FUNC) &R_igraph_distances, 4}, + {"R_igraph_distances_bellman_ford", (DL_FUNC) &R_igraph_distances_bellman_ford, 5}, + {"R_igraph_distances_cutoff", (DL_FUNC) &R_igraph_distances_cutoff, 5}, + {"R_igraph_distances_dijkstra", (DL_FUNC) &R_igraph_distances_dijkstra, 5}, + {"R_igraph_distances_dijkstra_cutoff", (DL_FUNC) &R_igraph_distances_dijkstra_cutoff, 6}, + {"R_igraph_distances_floyd_warshall", (DL_FUNC) &R_igraph_distances_floyd_warshall, 6}, + {"R_igraph_distances_johnson", (DL_FUNC) &R_igraph_distances_johnson, 4}, {"R_igraph_diversity", (DL_FUNC) &R_igraph_diversity, 3}, {"R_igraph_dominator_tree", (DL_FUNC) &R_igraph_dominator_tree, 3}, {"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", (DL_FUNC) &R_igraph_edge, 2}, {"R_igraph_edge_betweenness", (DL_FUNC) &R_igraph_edge_betweenness, 3}, {"R_igraph_edge_betweenness_cutoff", (DL_FUNC) &R_igraph_edge_betweenness_cutoff, 4}, {"R_igraph_edge_betweenness_subset", (DL_FUNC) &R_igraph_edge_betweenness_subset, 6}, {"R_igraph_edge_connectivity", (DL_FUNC) &R_igraph_edge_connectivity, 2}, + {"R_igraph_edge_disjoint_paths", (DL_FUNC) &R_igraph_edge_disjoint_paths, 3}, {"R_igraph_edgelist_percolation", (DL_FUNC) &R_igraph_edgelist_percolation, 1}, {"R_igraph_edges", (DL_FUNC) &R_igraph_edges, 2}, {"R_igraph_eigen_adjacency", (DL_FUNC) &R_igraph_eigen_adjacency, 4}, {"R_igraph_eigenvector_centrality", (DL_FUNC) &R_igraph_eigenvector_centrality, 5}, {"R_igraph_empty", (DL_FUNC) &R_igraph_empty, 2}, + {"R_igraph_empty_attrs", (DL_FUNC) &R_igraph_empty_attrs, 2}, {"R_igraph_erdos_renyi_game_gnm", (DL_FUNC) &R_igraph_erdos_renyi_game_gnm, 4}, {"R_igraph_erdos_renyi_game_gnp", (DL_FUNC) &R_igraph_erdos_renyi_game_gnp, 4}, + {"R_igraph_establishment_game", (DL_FUNC) &R_igraph_establishment_game, 6}, {"R_igraph_eulerian_cycle", (DL_FUNC) &R_igraph_eulerian_cycle, 1}, {"R_igraph_eulerian_path", (DL_FUNC) &R_igraph_eulerian_path, 1}, {"R_igraph_even_tarjan_reduction", (DL_FUNC) &R_igraph_even_tarjan_reduction, 1}, + {"R_igraph_expand_path_to_pairs", (DL_FUNC) &R_igraph_expand_path_to_pairs, 1}, {"R_igraph_extended_chordal_ring", (DL_FUNC) &R_igraph_extended_chordal_ring, 3}, {"R_igraph_famous", (DL_FUNC) &R_igraph_famous, 1}, {"R_igraph_feedback_arc_set", (DL_FUNC) &R_igraph_feedback_arc_set, 3}, @@ -626,11 +776,13 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_forest_fire_game", (DL_FUNC) &R_igraph_forest_fire_game, 5}, {"R_igraph_from_hrg_dendrogram", (DL_FUNC) &R_igraph_from_hrg_dendrogram, 1}, {"R_igraph_from_prufer", (DL_FUNC) &R_igraph_from_prufer, 1}, + {"R_igraph_full", (DL_FUNC) &R_igraph_full, 3}, {"R_igraph_full_bipartite", (DL_FUNC) &R_igraph_full_bipartite, 4}, {"R_igraph_full_citation", (DL_FUNC) &R_igraph_full_citation, 2}, {"R_igraph_full_multipartite", (DL_FUNC) &R_igraph_full_multipartite, 3}, {"R_igraph_fundamental_cycles", (DL_FUNC) &R_igraph_fundamental_cycles, 4}, {"R_igraph_generalized_petersen", (DL_FUNC) &R_igraph_generalized_petersen, 2}, + {"R_igraph_get_adjacency", (DL_FUNC) &R_igraph_get_adjacency, 4}, {"R_igraph_get_adjacency_sparse", (DL_FUNC) &R_igraph_get_adjacency_sparse, 4}, {"R_igraph_get_all_eids_between", (DL_FUNC) &R_igraph_get_all_eids_between, 4}, {"R_igraph_get_all_shortest_paths", (DL_FUNC) &R_igraph_get_all_shortest_paths, 4}, @@ -638,14 +790,19 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_get_all_simple_paths", (DL_FUNC) &R_igraph_get_all_simple_paths, 5}, {"R_igraph_get_biadjacency", (DL_FUNC) &R_igraph_get_biadjacency, 2}, {"R_igraph_get_edgelist", (DL_FUNC) &R_igraph_get_edgelist, 2}, + {"R_igraph_get_eids", (DL_FUNC) &R_igraph_get_eids, 4}, {"R_igraph_get_isomorphisms_vf2", (DL_FUNC) &R_igraph_get_isomorphisms_vf2, 6}, {"R_igraph_get_isomorphisms_vf2_callback", (DL_FUNC) &R_igraph_get_isomorphisms_vf2_callback, 6}, {"R_igraph_get_k_shortest_paths", (DL_FUNC) &R_igraph_get_k_shortest_paths, 6}, {"R_igraph_get_laplacian", (DL_FUNC) &R_igraph_get_laplacian, 4}, {"R_igraph_get_laplacian_sparse", (DL_FUNC) &R_igraph_get_laplacian_sparse, 4}, {"R_igraph_get_shortest_path", (DL_FUNC) &R_igraph_get_shortest_path, 4}, + {"R_igraph_get_shortest_path_astar", (DL_FUNC) &R_igraph_get_shortest_path_astar, 6}, {"R_igraph_get_shortest_path_bellman_ford", (DL_FUNC) &R_igraph_get_shortest_path_bellman_ford, 5}, {"R_igraph_get_shortest_path_dijkstra", (DL_FUNC) &R_igraph_get_shortest_path_dijkstra, 5}, + {"R_igraph_get_shortest_paths", (DL_FUNC) &R_igraph_get_shortest_paths, 4}, + {"R_igraph_get_shortest_paths_bellman_ford", (DL_FUNC) &R_igraph_get_shortest_paths_bellman_ford, 5}, + {"R_igraph_get_shortest_paths_dijkstra", (DL_FUNC) &R_igraph_get_shortest_paths_dijkstra, 5}, {"R_igraph_get_stochastic", (DL_FUNC) &R_igraph_get_stochastic, 3}, {"R_igraph_get_stochastic_sparse", (DL_FUNC) &R_igraph_get_stochastic_sparse, 3}, {"R_igraph_get_subisomorphisms_vf2", (DL_FUNC) &R_igraph_get_subisomorphisms_vf2, 6}, @@ -654,13 +811,18 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_girth", (DL_FUNC) &R_igraph_girth, 1}, {"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}, + {"R_igraph_graphlets", (DL_FUNC) &R_igraph_graphlets, 3}, {"R_igraph_graphlets_candidate_basis", (DL_FUNC) &R_igraph_graphlets_candidate_basis, 2}, {"R_igraph_graphlets_project", (DL_FUNC) &R_igraph_graphlets_project, 6}, + {"R_igraph_grg_game", (DL_FUNC) &R_igraph_grg_game, 3}, {"R_igraph_growing_random_game", (DL_FUNC) &R_igraph_growing_random_game, 4}, + {"R_igraph_harmonic_centrality", (DL_FUNC) &R_igraph_harmonic_centrality, 5}, {"R_igraph_harmonic_centrality_cutoff", (DL_FUNC) &R_igraph_harmonic_centrality_cutoff, 6}, + {"R_igraph_has_attribute_table", (DL_FUNC) &R_igraph_has_attribute_table, 0}, {"R_igraph_has_loop", (DL_FUNC) &R_igraph_has_loop, 1}, {"R_igraph_has_multiple", (DL_FUNC) &R_igraph_has_multiple, 1}, {"R_igraph_has_mutual", (DL_FUNC) &R_igraph_has_mutual, 2}, @@ -676,17 +838,21 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_hsbm_game", (DL_FUNC) &R_igraph_hsbm_game, 5}, {"R_igraph_hsbm_list_game", (DL_FUNC) &R_igraph_hsbm_list_game, 5}, {"R_igraph_hub_and_authority_scores", (DL_FUNC) &R_igraph_hub_and_authority_scores, 4}, + {"R_igraph_hub_score", (DL_FUNC) &R_igraph_hub_score, 4}, {"R_igraph_hypercube", (DL_FUNC) &R_igraph_hypercube, 2}, {"R_igraph_incident", (DL_FUNC) &R_igraph_incident, 3}, {"R_igraph_independence_number", (DL_FUNC) &R_igraph_independence_number, 1}, + {"R_igraph_independent_vertex_sets", (DL_FUNC) &R_igraph_independent_vertex_sets, 3}, {"R_igraph_induced_subgraph", (DL_FUNC) &R_igraph_induced_subgraph, 3}, {"R_igraph_induced_subgraph_map", (DL_FUNC) &R_igraph_induced_subgraph_map, 3}, {"R_igraph_intersection", (DL_FUNC) &R_igraph_intersection, 2}, {"R_igraph_invalidate_cache", (DL_FUNC) &R_igraph_invalidate_cache, 1}, {"R_igraph_is_acyclic", (DL_FUNC) &R_igraph_is_acyclic, 1}, {"R_igraph_is_biconnected", (DL_FUNC) &R_igraph_is_biconnected, 1}, + {"R_igraph_is_bigraphical", (DL_FUNC) &R_igraph_is_bigraphical, 3}, {"R_igraph_is_bipartite", (DL_FUNC) &R_igraph_is_bipartite, 1}, {"R_igraph_is_bipartite_coloring", (DL_FUNC) &R_igraph_is_bipartite_coloring, 2}, + {"R_igraph_is_chordal", (DL_FUNC) &R_igraph_is_chordal, 3}, {"R_igraph_is_clique", (DL_FUNC) &R_igraph_is_clique, 3}, {"R_igraph_is_complete", (DL_FUNC) &R_igraph_is_complete, 1}, {"R_igraph_is_connected", (DL_FUNC) &R_igraph_is_connected, 2}, @@ -704,6 +870,7 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_is_multiple", (DL_FUNC) &R_igraph_is_multiple, 2}, {"R_igraph_is_mutual", (DL_FUNC) &R_igraph_is_mutual, 3}, {"R_igraph_is_perfect", (DL_FUNC) &R_igraph_is_perfect, 1}, + {"R_igraph_is_same_graph", (DL_FUNC) &R_igraph_is_same_graph, 2}, {"R_igraph_is_separator", (DL_FUNC) &R_igraph_is_separator, 2}, {"R_igraph_is_simple", (DL_FUNC) &R_igraph_is_simple, 1}, {"R_igraph_is_tree", (DL_FUNC) &R_igraph_is_tree, 2}, @@ -719,20 +886,33 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_joint_degree_matrix", (DL_FUNC) &R_igraph_joint_degree_matrix, 4}, {"R_igraph_joint_type_distribution", (DL_FUNC) &R_igraph_joint_type_distribution, 6}, {"R_igraph_k_regular_game", (DL_FUNC) &R_igraph_k_regular_game, 4}, + {"R_igraph_kary_tree", (DL_FUNC) &R_igraph_kary_tree, 3}, {"R_igraph_kautz", (DL_FUNC) &R_igraph_kautz, 2}, + {"R_igraph_laplacian_spectral_embedding", (DL_FUNC) &R_igraph_laplacian_spectral_embedding, 7}, {"R_igraph_largest_cliques", (DL_FUNC) &R_igraph_largest_cliques, 1}, {"R_igraph_largest_independent_vertex_sets", (DL_FUNC) &R_igraph_largest_independent_vertex_sets, 1}, {"R_igraph_largest_weighted_cliques", (DL_FUNC) &R_igraph_largest_weighted_cliques, 2}, + {"R_igraph_lastcit_game", (DL_FUNC) &R_igraph_lastcit_game, 5}, {"R_igraph_layout_align", (DL_FUNC) &R_igraph_layout_align, 2}, {"R_igraph_layout_bipartite", (DL_FUNC) &R_igraph_layout_bipartite, 5}, {"R_igraph_layout_circle", (DL_FUNC) &R_igraph_layout_circle, 2}, {"R_igraph_layout_davidson_harel", (DL_FUNC) &R_igraph_layout_davidson_harel, 11}, + {"R_igraph_layout_drl", (DL_FUNC) &R_igraph_layout_drl, 5}, + {"R_igraph_layout_drl_3d", (DL_FUNC) &R_igraph_layout_drl_3d, 5}, + {"R_igraph_layout_fruchterman_reingold", (DL_FUNC) &R_igraph_layout_fruchterman_reingold, 11}, + {"R_igraph_layout_fruchterman_reingold_3d", (DL_FUNC) &R_igraph_layout_fruchterman_reingold_3d, 12}, {"R_igraph_layout_gem", (DL_FUNC) &R_igraph_layout_gem, 7}, + {"R_igraph_layout_graphopt", (DL_FUNC) &R_igraph_layout_graphopt, 9}, {"R_igraph_layout_grid", (DL_FUNC) &R_igraph_layout_grid, 2}, {"R_igraph_layout_grid_3d", (DL_FUNC) &R_igraph_layout_grid_3d, 3}, + {"R_igraph_layout_kamada_kawai", (DL_FUNC) &R_igraph_layout_kamada_kawai, 11}, + {"R_igraph_layout_kamada_kawai_3d", (DL_FUNC) &R_igraph_layout_kamada_kawai_3d, 13}, + {"R_igraph_layout_lgl", (DL_FUNC) &R_igraph_layout_lgl, 8}, {"R_igraph_layout_mds", (DL_FUNC) &R_igraph_layout_mds, 3}, {"R_igraph_layout_random", (DL_FUNC) &R_igraph_layout_random, 1}, {"R_igraph_layout_random_3d", (DL_FUNC) &R_igraph_layout_random_3d, 1}, + {"R_igraph_layout_reingold_tilford", (DL_FUNC) &R_igraph_layout_reingold_tilford, 4}, + {"R_igraph_layout_reingold_tilford_circular", (DL_FUNC) &R_igraph_layout_reingold_tilford_circular, 4}, {"R_igraph_layout_sphere", (DL_FUNC) &R_igraph_layout_sphere, 1}, {"R_igraph_layout_star", (DL_FUNC) &R_igraph_layout_star, 3}, {"R_igraph_layout_sugiyama", (DL_FUNC) &R_igraph_layout_sugiyama, 6}, @@ -740,6 +920,7 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_layout_umap_3d", (DL_FUNC) &R_igraph_layout_umap_3d, 7}, {"R_igraph_layout_umap_compute_weights", (DL_FUNC) &R_igraph_layout_umap_compute_weights, 3}, {"R_igraph_lcf_vector", (DL_FUNC) &R_igraph_lcf_vector, 3}, + {"R_igraph_le_community_to_membership", (DL_FUNC) &R_igraph_le_community_to_membership, 3}, {"R_igraph_linegraph", (DL_FUNC) &R_igraph_linegraph, 1}, {"R_igraph_list_triangles", (DL_FUNC) &R_igraph_list_triangles, 1}, {"R_igraph_local_efficiency", (DL_FUNC) &R_igraph_local_efficiency, 5}, @@ -753,8 +934,12 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_local_scan_subset_ecount", (DL_FUNC) &R_igraph_local_scan_subset_ecount, 3}, {"R_igraph_maxdegree", (DL_FUNC) &R_igraph_maxdegree, 4}, {"R_igraph_maxflow", (DL_FUNC) &R_igraph_maxflow, 4}, + {"R_igraph_maxflow_value", (DL_FUNC) &R_igraph_maxflow_value, 4}, + {"R_igraph_maximal_cliques", (DL_FUNC) &R_igraph_maximal_cliques, 3}, {"R_igraph_maximal_cliques_count", (DL_FUNC) &R_igraph_maximal_cliques_count, 3}, + {"R_igraph_maximal_cliques_file", (DL_FUNC) &R_igraph_maximal_cliques_file, 4}, {"R_igraph_maximal_cliques_hist", (DL_FUNC) &R_igraph_maximal_cliques_hist, 3}, + {"R_igraph_maximal_cliques_subset", (DL_FUNC) &R_igraph_maximal_cliques_subset, 5}, {"R_igraph_maximal_independent_vertex_sets", (DL_FUNC) &R_igraph_maximal_independent_vertex_sets, 1}, {"R_igraph_maximum_bipartite_matching", (DL_FUNC) &R_igraph_maximum_bipartite_matching, 4}, {"R_igraph_maximum_cardinality_search", (DL_FUNC) &R_igraph_maximum_cardinality_search, 1}, @@ -763,6 +948,7 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_mincut_value", (DL_FUNC) &R_igraph_mincut_value, 2}, {"R_igraph_minimum_cycle_basis", (DL_FUNC) &R_igraph_minimum_cycle_basis, 5}, {"R_igraph_minimum_size_separators", (DL_FUNC) &R_igraph_minimum_size_separators, 1}, + {"R_igraph_minimum_spanning_tree", (DL_FUNC) &R_igraph_minimum_spanning_tree, 2}, {"R_igraph_minimum_spanning_tree_prim", (DL_FUNC) &R_igraph_minimum_spanning_tree_prim, 2}, {"R_igraph_minimum_spanning_tree_unweighted", (DL_FUNC) &R_igraph_minimum_spanning_tree_unweighted, 1}, {"R_igraph_modularity", (DL_FUNC) &R_igraph_modularity, 5}, @@ -774,7 +960,11 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_motifs_randesu_no", (DL_FUNC) &R_igraph_motifs_randesu_no, 3}, {"R_igraph_mycielski_graph", (DL_FUNC) &R_igraph_mycielski_graph, 1}, {"R_igraph_mycielskian", (DL_FUNC) &R_igraph_mycielskian, 2}, + {"R_igraph_neighborhood", (DL_FUNC) &R_igraph_neighborhood, 5}, + {"R_igraph_neighborhood_graphs", (DL_FUNC) &R_igraph_neighborhood_graphs, 5}, + {"R_igraph_neighborhood_size", (DL_FUNC) &R_igraph_neighborhood_size, 5}, {"R_igraph_neighbors", (DL_FUNC) &R_igraph_neighbors, 3}, + {"R_igraph_pagerank", (DL_FUNC) &R_igraph_pagerank, 7}, {"R_igraph_path_graph", (DL_FUNC) &R_igraph_path_graph, 3}, {"R_igraph_path_length_hist", (DL_FUNC) &R_igraph_path_length_hist, 2}, {"R_igraph_permute_vertices", (DL_FUNC) &R_igraph_permute_vertices, 2}, @@ -783,20 +973,31 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_power_law_fit", (DL_FUNC) &R_igraph_power_law_fit, 3}, {"R_igraph_preference_game", (DL_FUNC) &R_igraph_preference_game, 7}, {"R_igraph_product", (DL_FUNC) &R_igraph_product, 3}, + {"R_igraph_progress", (DL_FUNC) &R_igraph_progress, 2}, {"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}, {"R_igraph_random_spanning_tree", (DL_FUNC) &R_igraph_random_spanning_tree, 2}, {"R_igraph_random_walk", (DL_FUNC) &R_igraph_random_walk, 6}, + {"R_igraph_read_graph_dimacs_flow", (DL_FUNC) &R_igraph_read_graph_dimacs_flow, 2}, {"R_igraph_read_graph_dl", (DL_FUNC) &R_igraph_read_graph_dl, 2}, + {"R_igraph_read_graph_edgelist", (DL_FUNC) &R_igraph_read_graph_edgelist, 3}, {"R_igraph_read_graph_gml", (DL_FUNC) &R_igraph_read_graph_gml, 1}, {"R_igraph_read_graph_graphdb", (DL_FUNC) &R_igraph_read_graph_graphdb, 2}, {"R_igraph_read_graph_graphml", (DL_FUNC) &R_igraph_read_graph_graphml, 2}, + {"R_igraph_read_graph_lgl", (DL_FUNC) &R_igraph_read_graph_lgl, 4}, + {"R_igraph_read_graph_ncol", (DL_FUNC) &R_igraph_read_graph_ncol, 5}, {"R_igraph_read_graph_pajek", (DL_FUNC) &R_igraph_read_graph_pajek, 1}, {"R_igraph_realize_bipartite_degree_sequence", (DL_FUNC) &R_igraph_realize_bipartite_degree_sequence, 4}, {"R_igraph_realize_degree_sequence", (DL_FUNC) &R_igraph_realize_degree_sequence, 4}, + {"R_igraph_recent_degree_aging_game", (DL_FUNC) &R_igraph_recent_degree_aging_game, 10}, + {"R_igraph_recent_degree_game", (DL_FUNC) &R_igraph_recent_degree_game, 8}, {"R_igraph_reciprocity", (DL_FUNC) &R_igraph_reciprocity, 3}, {"R_igraph_regular_tree", (DL_FUNC) &R_igraph_regular_tree, 3}, + {"R_igraph_reindex_membership", (DL_FUNC) &R_igraph_reindex_membership, 1}, {"R_igraph_residual_graph", (DL_FUNC) &R_igraph_residual_graph, 3}, {"R_igraph_reverse_edges", (DL_FUNC) &R_igraph_reverse_edges, 2}, {"R_igraph_reverse_residual_graph", (DL_FUNC) &R_igraph_reverse_residual_graph, 3}, @@ -804,6 +1005,7 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_rewire_directed_edges", (DL_FUNC) &R_igraph_rewire_directed_edges, 4}, {"R_igraph_rewire_edges", (DL_FUNC) &R_igraph_rewire_edges, 4}, {"R_igraph_rich_club_sequence", (DL_FUNC) &R_igraph_rich_club_sequence, 6}, + {"R_igraph_ring", (DL_FUNC) &R_igraph_ring, 4}, {"R_igraph_rooted_product", (DL_FUNC) &R_igraph_rooted_product, 3}, {"R_igraph_roots_for_tree_layout", (DL_FUNC) &R_igraph_roots_for_tree_layout, 3}, {"R_igraph_roulette_wheel_imitation", (DL_FUNC) &R_igraph_roulette_wheel_imitation, 6}, @@ -829,11 +1031,18 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_spanner", (DL_FUNC) &R_igraph_spanner, 3}, {"R_igraph_split_join_distance", (DL_FUNC) &R_igraph_split_join_distance, 2}, {"R_igraph_square_lattice", (DL_FUNC) &R_igraph_square_lattice, 5}, + {"R_igraph_st_edge_connectivity", (DL_FUNC) &R_igraph_st_edge_connectivity, 3}, {"R_igraph_st_mincut", (DL_FUNC) &R_igraph_st_mincut, 4}, + {"R_igraph_st_mincut_value", (DL_FUNC) &R_igraph_st_mincut_value, 4}, + {"R_igraph_st_vertex_connectivity", (DL_FUNC) &R_igraph_st_vertex_connectivity, 4}, + {"R_igraph_star", (DL_FUNC) &R_igraph_star, 3}, {"R_igraph_static_fitness_game", (DL_FUNC) &R_igraph_static_fitness_game, 5}, {"R_igraph_static_power_law_game", (DL_FUNC) &R_igraph_static_power_law_game, 7}, + {"R_igraph_status", (DL_FUNC) &R_igraph_status, 1}, {"R_igraph_stochastic_imitation", (DL_FUNC) &R_igraph_stochastic_imitation, 6}, {"R_igraph_strength", (DL_FUNC) &R_igraph_strength, 5}, + {"R_igraph_strerror", (DL_FUNC) &R_igraph_strerror, 1}, + {"R_igraph_subcomponent", (DL_FUNC) &R_igraph_subcomponent, 3}, {"R_igraph_subgraph_from_edges", (DL_FUNC) &R_igraph_subgraph_from_edges, 3}, {"R_igraph_subisomorphic", (DL_FUNC) &R_igraph_subisomorphic, 2}, {"R_igraph_subisomorphic_vf2", (DL_FUNC) &R_igraph_subisomorphic_vf2, 6}, @@ -860,18 +1069,24 @@ static const R_CallMethodDef CallEntries[] = { {"R_igraph_version", (DL_FUNC) &R_igraph_version, 0}, {"R_igraph_vertex_coloring_greedy", (DL_FUNC) &R_igraph_vertex_coloring_greedy, 2}, {"R_igraph_vertex_connectivity", (DL_FUNC) &R_igraph_vertex_connectivity, 2}, + {"R_igraph_vertex_disjoint_paths", (DL_FUNC) &R_igraph_vertex_disjoint_paths, 3}, {"R_igraph_vertex_path_from_edge_path", (DL_FUNC) &R_igraph_vertex_path_from_edge_path, 4}, {"R_igraph_voronoi", (DL_FUNC) &R_igraph_voronoi, 5}, + {"R_igraph_watts_strogatz_game", (DL_FUNC) &R_igraph_watts_strogatz_game, 6}, + {"R_igraph_weighted_adjacency", (DL_FUNC) &R_igraph_weighted_adjacency, 3}, {"R_igraph_weighted_clique_number", (DL_FUNC) &R_igraph_weighted_clique_number, 2}, {"R_igraph_weighted_cliques", (DL_FUNC) &R_igraph_weighted_cliques, 5}, {"R_igraph_wheel", (DL_FUNC) &R_igraph_wheel, 3}, {"R_igraph_widest_path_widths_dijkstra", (DL_FUNC) &R_igraph_widest_path_widths_dijkstra, 5}, {"R_igraph_widest_path_widths_floyd_warshall", (DL_FUNC) &R_igraph_widest_path_widths_floyd_warshall, 5}, + {"R_igraph_write_graph_dimacs_flow", (DL_FUNC) &R_igraph_write_graph_dimacs_flow, 5}, {"R_igraph_write_graph_dot", (DL_FUNC) &R_igraph_write_graph_dot, 2}, {"R_igraph_write_graph_edgelist", (DL_FUNC) &R_igraph_write_graph_edgelist, 2}, {"R_igraph_write_graph_gml", (DL_FUNC) &R_igraph_write_graph_gml, 5}, {"R_igraph_write_graph_graphml", (DL_FUNC) &R_igraph_write_graph_graphml, 3}, {"R_igraph_write_graph_leda", (DL_FUNC) &R_igraph_write_graph_leda, 4}, + {"R_igraph_write_graph_lgl", (DL_FUNC) &R_igraph_write_graph_lgl, 5}, + {"R_igraph_write_graph_ncol", (DL_FUNC) &R_igraph_write_graph_ncol, 4}, {"R_igraph_write_graph_pajek", (DL_FUNC) &R_igraph_write_graph_pajek, 2}, {"Rx_igraph_add_edges_manual", (DL_FUNC) &Rx_igraph_add_edges_manual, 2}, {"Rx_igraph_add_env", (DL_FUNC) &Rx_igraph_add_env, 1}, @@ -879,7 +1094,6 @@ static const R_CallMethodDef CallEntries[] = { {"Rx_igraph_add_version_to_env", (DL_FUNC) &Rx_igraph_add_version_to_env, 1}, {"Rx_igraph_address", (DL_FUNC) &Rx_igraph_address, 1}, {"Rx_igraph_adjacency", (DL_FUNC) &Rx_igraph_adjacency, 3}, - {"Rx_igraph_adjacency_spectral_embedding", (DL_FUNC) &Rx_igraph_adjacency_spectral_embedding, 7}, {"Rx_igraph_adjacent_vertices", (DL_FUNC) &Rx_igraph_adjacent_vertices, 3}, {"Rx_igraph_arpack", (DL_FUNC) &Rx_igraph_arpack, 5}, {"Rx_igraph_arpack_unpack_complex", (DL_FUNC) &Rx_igraph_arpack_unpack_complex, 3}, @@ -928,7 +1142,6 @@ static const R_CallMethodDef CallEntries[] = { {"Rx_igraph_get_shortest_paths", (DL_FUNC) &Rx_igraph_get_shortest_paths, 10}, {"Rx_igraph_girth", (DL_FUNC) &Rx_igraph_girth, 2}, {"Rx_igraph_graph_version", (DL_FUNC) &Rx_igraph_graph_version, 1}, - {"Rx_igraph_graphlets", (DL_FUNC) &Rx_igraph_graphlets, 3}, {"Rx_igraph_grg_game", (DL_FUNC) &Rx_igraph_grg_game, 4}, {"Rx_igraph_i_levc_arp", (DL_FUNC) &Rx_igraph_i_levc_arp, 3}, {"Rx_igraph_identical_graphs", (DL_FUNC) &Rx_igraph_identical_graphs, 3}, @@ -937,7 +1150,6 @@ static const R_CallMethodDef CallEntries[] = { {"Rx_igraph_intersection", (DL_FUNC) &Rx_igraph_intersection, 2}, {"Rx_igraph_is_chordal", (DL_FUNC) &Rx_igraph_is_chordal, 5}, {"Rx_igraph_kary_tree", (DL_FUNC) &Rx_igraph_kary_tree, 3}, - {"Rx_igraph_laplacian_spectral_embedding", (DL_FUNC) &Rx_igraph_laplacian_spectral_embedding, 7}, {"Rx_igraph_lastcit_game", (DL_FUNC) &Rx_igraph_lastcit_game, 5}, {"Rx_igraph_layout_drl", (DL_FUNC) &Rx_igraph_layout_drl, 5}, {"Rx_igraph_layout_drl_3d", (DL_FUNC) &Rx_igraph_layout_drl_3d, 5}, diff --git a/src/rinterface.c b/src/rinterface.c index 9b45e09975..3cd99d3b35 100644 --- a/src/rinterface.c +++ b/src/rinterface.c @@ -88,6 +88,37 @@ SEXP R_igraph_add_edges(SEXP graph, SEXP edges) { return(r_result); } +/*-------------------------------------------/ +/ igraph_empty_attrs / +/-------------------------------------------*/ +SEXP R_igraph_empty_attrs(SEXP n, SEXP directed) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_n; + igraph_bool_t c_directed; + + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_empty_attrs(&c_graph, c_n, c_directed, 0)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_add_vertices / /-------------------------------------------*/ @@ -386,6 +417,46 @@ SEXP R_igraph_degree(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { return(r_result); } +/*-------------------------------------------/ +/ igraph_edge / +/-------------------------------------------*/ +SEXP R_igraph_edge(SEXP graph, SEXP eid) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_eid; + igraph_integer_t c_from; + igraph_integer_t c_to; + SEXP from; + SEXP to; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK_INT(eid); + c_eid = (igraph_integer_t) REAL(eid)[0]; + c_from=0; + c_to=0; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_edge(&c_graph, c_eid, &c_from, &c_to)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(from=NEW_NUMERIC(1)); + REAL(from)[0]=(double) c_from; + PROTECT(to=NEW_NUMERIC(1)); + REAL(to)[0]=(double) c_to; + SET_VECTOR_ELT(r_result, 0, from); + SET_VECTOR_ELT(r_result, 1, to); + SET_STRING_ELT(r_names, 0, Rf_mkChar("from")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("to")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_edges / /-------------------------------------------*/ @@ -418,6 +489,44 @@ SEXP R_igraph_edges(SEXP graph, SEXP eids) { return(r_result); } +/*-------------------------------------------/ +/ igraph_get_eids / +/-------------------------------------------*/ +SEXP R_igraph_get_eids(SEXP graph, SEXP pairs, SEXP directed, SEXP error) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_eids; + igraph_vector_int_t c_pairs; + igraph_bool_t c_directed; + igraph_bool_t c_error; + SEXP eids; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_eids, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_eids); + Rz_SEXP_to_vector_int_copy(pairs, &c_pairs); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_pairs); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(error); + c_error = LOGICAL(error)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_eids(&c_graph, &c_eids, &c_pairs, c_directed, c_error)); + + /* Convert output */ + PROTECT(eids=Ry_igraph_vector_int_to_SEXPp1(&c_eids)); + igraph_vector_int_destroy(&c_eids); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_pairs); + IGRAPH_FINALLY_CLEAN(1); + r_result = eids; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_get_all_eids_between / /-------------------------------------------*/ @@ -483,6 +592,67 @@ SEXP R_igraph_incident(SEXP graph, SEXP vid, SEXP mode) { return(r_result); } +/*-------------------------------------------/ +/ igraph_is_same_graph / +/-------------------------------------------*/ +SEXP R_igraph_is_same_graph(SEXP graph1, SEXP graph2) { + /* Declarations */ + igraph_t c_graph1; + igraph_t c_graph2; + igraph_bool_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph1, &c_graph1); + Rz_SEXP_to_igraph(graph2, &c_graph2); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_is_same_graph(&c_graph1, &c_graph2, &c_res)); + + /* Convert output */ + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_create / +/-------------------------------------------*/ +SEXP R_igraph_create(SEXP edges, SEXP n, SEXP directed) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_edges; + igraph_integer_t c_n; + igraph_bool_t c_directed; + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(edges, &c_edges)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_create(&c_graph, &c_edges, c_n, c_directed)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_adjacency / /-------------------------------------------*/ @@ -558,6 +728,38 @@ SEXP R_igraph_weighted_adjacency(SEXP adjmatrix, SEXP mode, SEXP loops) { return(r_result); } +/*-------------------------------------------/ +/ igraph_star / +/-------------------------------------------*/ +SEXP R_igraph_star(SEXP n, SEXP mode, SEXP center) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_n; + igraph_star_mode_t c_mode; + igraph_integer_t c_center; + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + c_mode = (igraph_star_mode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_INT(center); + c_center = (igraph_integer_t) REAL(center)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_star(&c_graph, c_n, c_mode, c_center)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_wheel / /-------------------------------------------*/ @@ -697,6 +899,42 @@ SEXP R_igraph_triangular_lattice(SEXP dimvector, SEXP directed, SEXP mutual) { return(r_result); } +/*-------------------------------------------/ +/ igraph_ring / +/-------------------------------------------*/ +SEXP R_igraph_ring(SEXP n, SEXP directed, SEXP mutual, SEXP circular) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_n; + igraph_bool_t c_directed; + igraph_bool_t c_mutual; + igraph_bool_t c_circular; + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(mutual); + c_mutual = LOGICAL(mutual)[0]; + IGRAPH_R_CHECK_BOOL(circular); + c_circular = LOGICAL(circular)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_ring(&c_graph, c_n, c_directed, c_mutual, c_circular)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_path_graph / /-------------------------------------------*/ @@ -763,6 +1001,38 @@ SEXP R_igraph_cycle_graph(SEXP n, SEXP directed, SEXP mutual) { return(r_result); } +/*-------------------------------------------/ +/ igraph_kary_tree / +/-------------------------------------------*/ +SEXP R_igraph_kary_tree(SEXP n, SEXP children, SEXP type) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_n; + igraph_integer_t c_children; + igraph_tree_mode_t c_type; + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_INT(children); + c_children = (igraph_integer_t) REAL(children)[0]; + c_type = (igraph_tree_mode_t) Rf_asInteger(type); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_kary_tree(&c_graph, c_n, c_children, c_type)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_symmetric_tree / /-------------------------------------------*/ @@ -827,13 +1097,14 @@ SEXP R_igraph_regular_tree(SEXP h, SEXP k, SEXP type) { } /*-------------------------------------------/ -/ igraph_full_citation / +/ igraph_full / /-------------------------------------------*/ -SEXP R_igraph_full_citation(SEXP n, SEXP directed) { +SEXP R_igraph_full(SEXP n, SEXP directed, SEXP loops) { /* Declarations */ igraph_t c_graph; igraph_integer_t c_n; igraph_bool_t c_directed; + igraph_bool_t c_loops; SEXP graph; SEXP r_result; @@ -842,8 +1113,10 @@ SEXP R_igraph_full_citation(SEXP n, SEXP directed) { c_n = (igraph_integer_t) REAL(n)[0]; IGRAPH_R_CHECK_BOOL(directed); c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_full_citation(&c_graph, c_n, c_directed)); + IGRAPH_R_CHECK(igraph_full(&c_graph, c_n, c_directed, c_loops)); /* Convert output */ IGRAPH_FINALLY(igraph_destroy, &c_graph); @@ -857,20 +1130,23 @@ SEXP R_igraph_full_citation(SEXP n, SEXP directed) { } /*-------------------------------------------/ -/ igraph_atlas / +/ igraph_full_citation / /-------------------------------------------*/ -SEXP R_igraph_atlas(SEXP number) { +SEXP R_igraph_full_citation(SEXP n, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_number; + igraph_integer_t c_n; + igraph_bool_t c_directed; SEXP graph; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(number); - c_number = (igraph_integer_t) REAL(number)[0]; + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_atlas(&c_graph, c_number)); + IGRAPH_R_CHECK(igraph_full_citation(&c_graph, c_n, c_directed)); /* Convert output */ IGRAPH_FINALLY(igraph_destroy, &c_graph); @@ -884,14 +1160,41 @@ SEXP R_igraph_atlas(SEXP number) { } /*-------------------------------------------/ -/ igraph_extended_chordal_ring / +/ igraph_atlas / /-------------------------------------------*/ -SEXP R_igraph_extended_chordal_ring(SEXP nodes, SEXP W, SEXP directed) { +SEXP R_igraph_atlas(SEXP number) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_nodes; - igraph_matrix_int_t c_W; - igraph_bool_t c_directed; + igraph_integer_t c_number; + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(number); + c_number = (igraph_integer_t) REAL(number)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_atlas(&c_graph, c_number)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_extended_chordal_ring / +/-------------------------------------------*/ +SEXP R_igraph_extended_chordal_ring(SEXP nodes, SEXP W, SEXP directed) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_nodes; + igraph_matrix_int_t c_W; + igraph_bool_t c_directed; SEXP graph; SEXP r_result; @@ -918,6 +1221,35 @@ SEXP R_igraph_extended_chordal_ring(SEXP nodes, SEXP W, SEXP directed) { return(r_result); } +/*-------------------------------------------/ +/ igraph_connect_neighborhood / +/-------------------------------------------*/ +SEXP R_igraph_connect_neighborhood(SEXP graph, SEXP order, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_order; + igraph_neimode_t c_mode; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph_copy(graph, &c_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + IGRAPH_R_CHECK_INT(order); + c_order = (igraph_integer_t) REAL(order)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_connect_neighborhood(&c_graph, c_order, c_mode)); + + /* Convert output */ + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_graph_power / /-------------------------------------------*/ @@ -1443,6 +1775,64 @@ SEXP R_igraph_turan(SEXP n, SEXP r) { return(r_result); } +/*-------------------------------------------/ +/ igraph_barabasi_game / +/-------------------------------------------*/ +SEXP R_igraph_barabasi_game(SEXP n, SEXP power, SEXP m, SEXP outseq, SEXP outpref, SEXP A, SEXP directed, SEXP algo, SEXP start_from) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_n; + igraph_real_t c_power; + igraph_integer_t c_m; + igraph_vector_int_t c_outseq; + igraph_bool_t c_outpref; + igraph_real_t c_A; + igraph_bool_t c_directed; + igraph_barabasi_algorithm_t c_algo; + igraph_t c_start_from; + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_REAL(power); + c_power = REAL(power)[0]; + IGRAPH_R_CHECK_INT(m); + c_m = (igraph_integer_t) REAL(m)[0]; + if (!Rf_isNull(outseq)) { + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(outseq, &c_outseq)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_outseq); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_outseq, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_outseq); + } + IGRAPH_R_CHECK_BOOL(outpref); + c_outpref = LOGICAL(outpref)[0]; + IGRAPH_R_CHECK_REAL(A); + c_A = REAL(A)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + c_algo = (igraph_barabasi_algorithm_t) Rf_asInteger(algo); + if (!Rf_isNull(start_from)) { + Rz_SEXP_to_igraph(start_from, &c_start_from); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_barabasi_game(&c_graph, c_n, c_power, c_m, (Rf_isNull(outseq) ? 0 : &c_outseq), c_outpref, c_A, c_directed, c_algo, (Rf_isNull(start_from) ? 0 : &c_start_from))); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_outseq); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_erdos_renyi_game_gnp / /-------------------------------------------*/ @@ -1515,6 +1905,47 @@ SEXP R_igraph_erdos_renyi_game_gnm(SEXP n, SEXP m, SEXP directed, SEXP loops) { return(r_result); } +/*-------------------------------------------/ +/ igraph_degree_sequence_game / +/-------------------------------------------*/ +SEXP R_igraph_degree_sequence_game(SEXP out_deg, SEXP in_deg, SEXP method) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_out_deg; + igraph_vector_int_t c_in_deg; + igraph_degseq_t c_method; + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(out_deg, &c_out_deg)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_out_deg); + if (!Rf_isNull(in_deg)) { + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(in_deg, &c_in_deg)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_in_deg); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_in_deg, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_in_deg); + } + c_method = (igraph_degseq_t) Rf_asInteger(method); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_degree_sequence_game(&c_graph, &c_out_deg, (Rf_isNull(in_deg) ? 0 : &c_in_deg), c_method)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_out_deg); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_in_deg); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_growing_random_game / /-------------------------------------------*/ @@ -1552,152 +1983,182 @@ SEXP R_igraph_growing_random_game(SEXP n, SEXP m, SEXP directed, SEXP citation) } /*-------------------------------------------/ -/ igraph_preference_game / +/ igraph_barabasi_aging_game / /-------------------------------------------*/ -SEXP R_igraph_preference_game(SEXP nodes, SEXP types, SEXP type_dist, SEXP fixed_sizes, SEXP pref_matrix, SEXP directed, SEXP loops) { +SEXP R_igraph_barabasi_aging_game(SEXP nodes, SEXP m, SEXP outseq, SEXP outpref, SEXP pa_exp, SEXP aging_exp, SEXP aging_bin, SEXP zero_deg_appeal, SEXP zero_age_appeal, SEXP deg_coef, SEXP age_coef, SEXP directed) { /* Declarations */ igraph_t c_graph; igraph_integer_t c_nodes; - igraph_integer_t c_types; - igraph_vector_t c_type_dist; - igraph_bool_t c_fixed_sizes; - igraph_matrix_t c_pref_matrix; - igraph_vector_int_t c_node_type_vec; + igraph_integer_t c_m; + igraph_vector_int_t c_outseq; + igraph_bool_t c_outpref; + igraph_real_t c_pa_exp; + igraph_real_t c_aging_exp; + igraph_integer_t c_aging_bin; + igraph_real_t c_zero_deg_appeal; + igraph_real_t c_zero_age_appeal; + igraph_real_t c_deg_coef; + igraph_real_t c_age_coef; igraph_bool_t c_directed; - igraph_bool_t c_loops; SEXP graph; - SEXP node_type_vec; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ IGRAPH_R_CHECK_INT(nodes); c_nodes = (igraph_integer_t) REAL(nodes)[0]; - IGRAPH_R_CHECK_INT(types); - c_types = (igraph_integer_t) REAL(types)[0]; - Rz_SEXP_to_vector(type_dist, &c_type_dist); - IGRAPH_R_CHECK_BOOL(fixed_sizes); - c_fixed_sizes = LOGICAL(fixed_sizes)[0]; - Rz_SEXP_to_matrix(pref_matrix, &c_pref_matrix); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_node_type_vec, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_node_type_vec); + IGRAPH_R_CHECK_INT(m); + c_m = (igraph_integer_t) REAL(m)[0]; + if (!Rf_isNull(outseq)) { + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(outseq, &c_outseq)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_outseq); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_outseq, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_outseq); + } + IGRAPH_R_CHECK_BOOL(outpref); + c_outpref = LOGICAL(outpref)[0]; + IGRAPH_R_CHECK_REAL(pa_exp); + c_pa_exp = REAL(pa_exp)[0]; + IGRAPH_R_CHECK_REAL(aging_exp); + c_aging_exp = REAL(aging_exp)[0]; + IGRAPH_R_CHECK_INT(aging_bin); + c_aging_bin = (igraph_integer_t) REAL(aging_bin)[0]; + IGRAPH_R_CHECK_REAL(zero_deg_appeal); + c_zero_deg_appeal = REAL(zero_deg_appeal)[0]; + IGRAPH_R_CHECK_REAL(zero_age_appeal); + c_zero_age_appeal = REAL(zero_age_appeal)[0]; + IGRAPH_R_CHECK_REAL(deg_coef); + c_deg_coef = REAL(deg_coef)[0]; + IGRAPH_R_CHECK_REAL(age_coef); + c_age_coef = REAL(age_coef)[0]; IGRAPH_R_CHECK_BOOL(directed); c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_preference_game(&c_graph, c_nodes, c_types, &c_type_dist, c_fixed_sizes, &c_pref_matrix, &c_node_type_vec, c_directed, c_loops)); + IGRAPH_R_CHECK(igraph_barabasi_aging_game(&c_graph, c_nodes, c_m, (Rf_isNull(outseq) ? 0 : &c_outseq), c_outpref, c_pa_exp, c_aging_exp, c_aging_bin, c_zero_deg_appeal, c_zero_age_appeal, c_deg_coef, c_age_coef, c_directed)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - PROTECT(node_type_vec=Ry_igraph_vector_int_to_SEXP(&c_node_type_vec)); - igraph_vector_int_destroy(&c_node_type_vec); + igraph_vector_int_destroy(&c_outseq); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, graph); - SET_VECTOR_ELT(r_result, 1, node_type_vec); - SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("node_type_vec")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_asymmetric_preference_game / +/ igraph_recent_degree_game / /-------------------------------------------*/ -SEXP R_igraph_asymmetric_preference_game(SEXP nodes, SEXP out_types, SEXP in_types, SEXP type_dist_matrix, SEXP pref_matrix, SEXP loops) { +SEXP R_igraph_recent_degree_game(SEXP n, SEXP power, SEXP window, SEXP m, SEXP outseq, SEXP outpref, SEXP zero_appeal, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_nodes; - igraph_integer_t c_out_types; - igraph_integer_t c_in_types; - igraph_matrix_t c_type_dist_matrix; - igraph_matrix_t c_pref_matrix; - igraph_vector_int_t c_node_type_out_vec; - igraph_vector_int_t c_node_type_in_vec; - igraph_bool_t c_loops; + igraph_integer_t c_n; + igraph_real_t c_power; + igraph_integer_t c_window; + igraph_integer_t c_m; + igraph_vector_int_t c_outseq; + igraph_bool_t c_outpref; + igraph_real_t c_zero_appeal; + igraph_bool_t c_directed; SEXP graph; - SEXP node_type_out_vec; - SEXP node_type_in_vec; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(nodes); - c_nodes = (igraph_integer_t) REAL(nodes)[0]; - IGRAPH_R_CHECK_INT(out_types); - c_out_types = (igraph_integer_t) REAL(out_types)[0]; - IGRAPH_R_CHECK_INT(in_types); - c_in_types = (igraph_integer_t) REAL(in_types)[0]; - Rz_SEXP_to_matrix(type_dist_matrix, &c_type_dist_matrix); - Rz_SEXP_to_matrix(pref_matrix, &c_pref_matrix); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_node_type_out_vec, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_node_type_out_vec); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_node_type_in_vec, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_node_type_in_vec); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_REAL(power); + c_power = REAL(power)[0]; + IGRAPH_R_CHECK_INT(window); + c_window = (igraph_integer_t) REAL(window)[0]; + IGRAPH_R_CHECK_INT(m); + c_m = (igraph_integer_t) REAL(m)[0]; + if (!Rf_isNull(outseq)) { + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(outseq, &c_outseq)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_outseq); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_outseq, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_outseq); + } + IGRAPH_R_CHECK_BOOL(outpref); + c_outpref = LOGICAL(outpref)[0]; + IGRAPH_R_CHECK_REAL(zero_appeal); + c_zero_appeal = REAL(zero_appeal)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_asymmetric_preference_game(&c_graph, c_nodes, c_out_types, c_in_types, &c_type_dist_matrix, &c_pref_matrix, &c_node_type_out_vec, &c_node_type_in_vec, c_loops)); + IGRAPH_R_CHECK(igraph_recent_degree_game(&c_graph, c_n, c_power, c_window, c_m, (Rf_isNull(outseq) ? 0 : &c_outseq), c_outpref, c_zero_appeal, c_directed)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - PROTECT(node_type_out_vec=Ry_igraph_vector_int_to_SEXP(&c_node_type_out_vec)); - igraph_vector_int_destroy(&c_node_type_out_vec); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(node_type_in_vec=Ry_igraph_vector_int_to_SEXP(&c_node_type_in_vec)); - igraph_vector_int_destroy(&c_node_type_in_vec); + igraph_vector_int_destroy(&c_outseq); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, graph); - SET_VECTOR_ELT(r_result, 1, node_type_out_vec); - SET_VECTOR_ELT(r_result, 2, node_type_in_vec); - SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("node_type_out_vec")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("node_type_in_vec")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_rewire_edges / +/ igraph_recent_degree_aging_game / /-------------------------------------------*/ -SEXP R_igraph_rewire_edges(SEXP graph, SEXP prob, SEXP loops, SEXP multiple) { +SEXP R_igraph_recent_degree_aging_game(SEXP nodes, SEXP m, SEXP outseq, SEXP outpref, SEXP pa_exp, SEXP aging_exp, SEXP aging_bin, SEXP window, SEXP zero_appeal, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_prob; - igraph_bool_t c_loops; - igraph_bool_t c_multiple; + igraph_integer_t c_nodes; + igraph_integer_t c_m; + igraph_vector_int_t c_outseq; + igraph_bool_t c_outpref; + igraph_real_t c_pa_exp; + igraph_real_t c_aging_exp; + igraph_integer_t c_aging_bin; + igraph_integer_t c_window; + igraph_real_t c_zero_appeal; + igraph_bool_t c_directed; + SEXP graph; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph_copy(graph, &c_graph); - IGRAPH_FINALLY(igraph_destroy, &c_graph); - IGRAPH_R_CHECK_REAL(prob); - c_prob = REAL(prob)[0]; - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; - IGRAPH_R_CHECK_BOOL(multiple); - c_multiple = LOGICAL(multiple)[0]; + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_INT(m); + c_m = (igraph_integer_t) REAL(m)[0]; + if (!Rf_isNull(outseq)) { + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(outseq, &c_outseq)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_outseq); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_outseq, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_outseq); + } + IGRAPH_R_CHECK_BOOL(outpref); + c_outpref = LOGICAL(outpref)[0]; + IGRAPH_R_CHECK_REAL(pa_exp); + c_pa_exp = REAL(pa_exp)[0]; + IGRAPH_R_CHECK_REAL(aging_exp); + c_aging_exp = REAL(aging_exp)[0]; + IGRAPH_R_CHECK_INT(aging_bin); + c_aging_bin = (igraph_integer_t) REAL(aging_bin)[0]; + IGRAPH_R_CHECK_INT(window); + c_window = (igraph_integer_t) REAL(window)[0]; + IGRAPH_R_CHECK_REAL(zero_appeal); + c_zero_appeal = REAL(zero_appeal)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_rewire_edges(&c_graph, c_prob, c_loops, c_multiple)); + IGRAPH_R_CHECK(igraph_recent_degree_aging_game(&c_graph, c_nodes, c_m, (Rf_isNull(outseq) ? 0 : &c_outseq), c_outpref, c_pa_exp, c_aging_exp, c_aging_bin, c_window, c_zero_appeal, c_directed)); /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_outseq); + IGRAPH_FINALLY_CLEAN(1); r_result = graph; UNPROTECT(1); @@ -1705,222 +2166,313 @@ SEXP R_igraph_rewire_edges(SEXP graph, SEXP prob, SEXP loops, SEXP multiple) { } /*-------------------------------------------/ -/ igraph_rewire_directed_edges / +/ igraph_callaway_traits_game / /-------------------------------------------*/ -SEXP R_igraph_rewire_directed_edges(SEXP graph, SEXP prob, SEXP loops, SEXP mode) { +SEXP R_igraph_callaway_traits_game(SEXP nodes, SEXP types, SEXP edges_per_step, SEXP type_dist, SEXP pref_matrix, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_prob; - igraph_bool_t c_loops; - igraph_neimode_t c_mode; - - SEXP r_result; - /* Convert input */ - Rz_SEXP_to_igraph_copy(graph, &c_graph); - IGRAPH_FINALLY(igraph_destroy, &c_graph); - IGRAPH_R_CHECK_REAL(prob); - c_prob = REAL(prob)[0]; - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + igraph_integer_t c_nodes; + igraph_integer_t c_types; + igraph_integer_t c_edges_per_step; + igraph_vector_t c_type_dist; + igraph_matrix_t c_pref_matrix; + igraph_bool_t c_directed; + igraph_vector_int_t c_node_type_vec; + SEXP graph; + SEXP node_type_vec; + + SEXP r_result, r_names; + /* Convert input */ + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_INT(types); + c_types = (igraph_integer_t) REAL(types)[0]; + IGRAPH_R_CHECK_INT(edges_per_step); + c_edges_per_step = (igraph_integer_t) REAL(edges_per_step)[0]; + Rz_SEXP_to_vector(type_dist, &c_type_dist); + Rz_SEXP_to_matrix(pref_matrix, &c_pref_matrix); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_node_type_vec, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_node_type_vec); /* Call igraph */ - IGRAPH_R_CHECK(igraph_rewire_directed_edges(&c_graph, c_prob, c_loops, c_mode)); + IGRAPH_R_CHECK(igraph_callaway_traits_game(&c_graph, c_nodes, c_types, c_edges_per_step, &c_type_dist, &c_pref_matrix, c_directed, &c_node_type_vec)); /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + PROTECT(node_type_vec=Ry_igraph_vector_int_to_SEXP(&c_node_type_vec)); + igraph_vector_int_destroy(&c_node_type_vec); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, node_type_vec); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("node_type_vec")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_forest_fire_game / +/ igraph_establishment_game / /-------------------------------------------*/ -SEXP R_igraph_forest_fire_game(SEXP nodes, SEXP fw_prob, SEXP bw_factor, SEXP ambs, SEXP directed) { +SEXP R_igraph_establishment_game(SEXP nodes, SEXP types, SEXP k, SEXP type_dist, SEXP pref_matrix, SEXP directed) { /* Declarations */ igraph_t c_graph; igraph_integer_t c_nodes; - igraph_real_t c_fw_prob; - igraph_real_t c_bw_factor; - igraph_integer_t c_ambs; + igraph_integer_t c_types; + igraph_integer_t c_k; + igraph_vector_t c_type_dist; + igraph_matrix_t c_pref_matrix; igraph_bool_t c_directed; + igraph_vector_int_t c_node_type_vec; SEXP graph; + SEXP node_type_vec; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ IGRAPH_R_CHECK_INT(nodes); c_nodes = (igraph_integer_t) REAL(nodes)[0]; - IGRAPH_R_CHECK_REAL(fw_prob); - c_fw_prob = REAL(fw_prob)[0]; - IGRAPH_R_CHECK_REAL(bw_factor); - c_bw_factor = REAL(bw_factor)[0]; - IGRAPH_R_CHECK_INT(ambs); - c_ambs = (igraph_integer_t) REAL(ambs)[0]; + IGRAPH_R_CHECK_INT(types); + c_types = (igraph_integer_t) REAL(types)[0]; + IGRAPH_R_CHECK_INT(k); + c_k = (igraph_integer_t) REAL(k)[0]; + Rz_SEXP_to_vector(type_dist, &c_type_dist); + Rz_SEXP_to_matrix(pref_matrix, &c_pref_matrix); IGRAPH_R_CHECK_BOOL(directed); c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_node_type_vec, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_node_type_vec); /* Call igraph */ - IGRAPH_R_CHECK(igraph_forest_fire_game(&c_graph, c_nodes, c_fw_prob, c_bw_factor, c_ambs, c_directed)); + IGRAPH_R_CHECK(igraph_establishment_game(&c_graph, c_nodes, c_types, c_k, &c_type_dist, &c_pref_matrix, c_directed, &c_node_type_vec)); /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + PROTECT(node_type_vec=Ry_igraph_vector_int_to_SEXP(&c_node_type_vec)); + igraph_vector_int_destroy(&c_node_type_vec); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, node_type_vec); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("node_type_vec")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_simple_interconnected_islands_game / +/ igraph_grg_game / /-------------------------------------------*/ -SEXP R_igraph_simple_interconnected_islands_game(SEXP islands_n, SEXP islands_size, SEXP islands_pin, SEXP n_inter) { +SEXP R_igraph_grg_game(SEXP nodes, SEXP radius, SEXP torus) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_islands_n; - igraph_integer_t c_islands_size; - igraph_real_t c_islands_pin; - igraph_integer_t c_n_inter; + igraph_integer_t c_nodes; + igraph_real_t c_radius; + igraph_bool_t c_torus; + igraph_vector_t c_x; + igraph_vector_t c_y; SEXP graph; + SEXP x; + SEXP y; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - IGRAPH_R_CHECK_INT(islands_n); - c_islands_n = (igraph_integer_t) REAL(islands_n)[0]; - IGRAPH_R_CHECK_INT(islands_size); - c_islands_size = (igraph_integer_t) REAL(islands_size)[0]; - IGRAPH_R_CHECK_REAL(islands_pin); - c_islands_pin = REAL(islands_pin)[0]; - IGRAPH_R_CHECK_INT(n_inter); - c_n_inter = (igraph_integer_t) REAL(n_inter)[0]; + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_REAL(radius); + c_radius = REAL(radius)[0]; + IGRAPH_R_CHECK_BOOL(torus); + c_torus = LOGICAL(torus)[0]; + IGRAPH_R_CHECK(igraph_vector_init(&c_x, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_x); + IGRAPH_R_CHECK(igraph_vector_init(&c_y, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_y); /* Call igraph */ - IGRAPH_R_CHECK(igraph_simple_interconnected_islands_game(&c_graph, c_islands_n, c_islands_size, c_islands_pin, c_n_inter)); + IGRAPH_R_CHECK(igraph_grg_game(&c_graph, c_nodes, c_radius, c_torus, &c_x, &c_y)); /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + PROTECT(x=Ry_igraph_vector_to_SEXP(&c_x)); + igraph_vector_destroy(&c_x); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(y=Ry_igraph_vector_to_SEXP(&c_y)); + igraph_vector_destroy(&c_y); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, x); + SET_VECTOR_ELT(r_result, 2, y); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("x")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("y")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_chung_lu_game / +/ igraph_preference_game / /-------------------------------------------*/ -SEXP R_igraph_chung_lu_game(SEXP out_weights, SEXP in_weights, SEXP loops, SEXP variant) { +SEXP R_igraph_preference_game(SEXP nodes, SEXP types, SEXP type_dist, SEXP fixed_sizes, SEXP pref_matrix, SEXP directed, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_out_weights; - igraph_vector_t c_in_weights; + igraph_integer_t c_nodes; + igraph_integer_t c_types; + igraph_vector_t c_type_dist; + igraph_bool_t c_fixed_sizes; + igraph_matrix_t c_pref_matrix; + igraph_vector_int_t c_node_type_vec; + igraph_bool_t c_directed; igraph_bool_t c_loops; - igraph_chung_lu_t c_variant; SEXP graph; + SEXP node_type_vec; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - Rz_SEXP_to_vector(out_weights, &c_out_weights); - if (!Rf_isNull(in_weights)) { - Rz_SEXP_to_vector(in_weights, &c_in_weights); - } + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_INT(types); + c_types = (igraph_integer_t) REAL(types)[0]; + Rz_SEXP_to_vector(type_dist, &c_type_dist); + IGRAPH_R_CHECK_BOOL(fixed_sizes); + c_fixed_sizes = LOGICAL(fixed_sizes)[0]; + Rz_SEXP_to_matrix(pref_matrix, &c_pref_matrix); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_node_type_vec, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_node_type_vec); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; IGRAPH_R_CHECK_BOOL(loops); c_loops = LOGICAL(loops)[0]; - c_variant = (igraph_chung_lu_t) Rf_asInteger(variant); /* Call igraph */ - IGRAPH_R_CHECK(igraph_chung_lu_game(&c_graph, &c_out_weights, (Rf_isNull(in_weights) ? 0 : &c_in_weights), c_loops, c_variant)); + IGRAPH_R_CHECK(igraph_preference_game(&c_graph, c_nodes, c_types, &c_type_dist, c_fixed_sizes, &c_pref_matrix, &c_node_type_vec, c_directed, c_loops)); /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + PROTECT(node_type_vec=Ry_igraph_vector_int_to_SEXP(&c_node_type_vec)); + igraph_vector_int_destroy(&c_node_type_vec); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, node_type_vec); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("node_type_vec")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_static_fitness_game / +/ igraph_asymmetric_preference_game / /-------------------------------------------*/ -SEXP R_igraph_static_fitness_game(SEXP no_of_edges, SEXP fitness_out, SEXP fitness_in, SEXP loops, SEXP multiple) { +SEXP R_igraph_asymmetric_preference_game(SEXP nodes, SEXP out_types, SEXP in_types, SEXP type_dist_matrix, SEXP pref_matrix, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_no_of_edges; - igraph_vector_t c_fitness_out; - igraph_vector_t c_fitness_in; + igraph_integer_t c_nodes; + igraph_integer_t c_out_types; + igraph_integer_t c_in_types; + igraph_matrix_t c_type_dist_matrix; + igraph_matrix_t c_pref_matrix; + igraph_vector_int_t c_node_type_out_vec; + igraph_vector_int_t c_node_type_in_vec; igraph_bool_t c_loops; - igraph_bool_t c_multiple; SEXP graph; + SEXP node_type_out_vec; + SEXP node_type_in_vec; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - IGRAPH_R_CHECK_INT(no_of_edges); - c_no_of_edges = (igraph_integer_t) REAL(no_of_edges)[0]; - Rz_SEXP_to_vector(fitness_out, &c_fitness_out); - if (!Rf_isNull(fitness_in)) { - Rz_SEXP_to_vector(fitness_in, &c_fitness_in); - } + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_INT(out_types); + c_out_types = (igraph_integer_t) REAL(out_types)[0]; + IGRAPH_R_CHECK_INT(in_types); + c_in_types = (igraph_integer_t) REAL(in_types)[0]; + Rz_SEXP_to_matrix(type_dist_matrix, &c_type_dist_matrix); + Rz_SEXP_to_matrix(pref_matrix, &c_pref_matrix); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_node_type_out_vec, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_node_type_out_vec); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_node_type_in_vec, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_node_type_in_vec); IGRAPH_R_CHECK_BOOL(loops); c_loops = LOGICAL(loops)[0]; - IGRAPH_R_CHECK_BOOL(multiple); - c_multiple = LOGICAL(multiple)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_static_fitness_game(&c_graph, c_no_of_edges, &c_fitness_out, (Rf_isNull(fitness_in) ? 0 : &c_fitness_in), c_loops, c_multiple)); + IGRAPH_R_CHECK(igraph_asymmetric_preference_game(&c_graph, c_nodes, c_out_types, c_in_types, &c_type_dist_matrix, &c_pref_matrix, &c_node_type_out_vec, &c_node_type_in_vec, c_loops)); /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + PROTECT(node_type_out_vec=Ry_igraph_vector_int_to_SEXP(&c_node_type_out_vec)); + igraph_vector_int_destroy(&c_node_type_out_vec); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(node_type_in_vec=Ry_igraph_vector_int_to_SEXP(&c_node_type_in_vec)); + igraph_vector_int_destroy(&c_node_type_in_vec); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, node_type_out_vec); + SET_VECTOR_ELT(r_result, 2, node_type_in_vec); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("node_type_out_vec")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("node_type_in_vec")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_static_power_law_game / +/ igraph_rewire_edges / /-------------------------------------------*/ -SEXP R_igraph_static_power_law_game(SEXP no_of_nodes, SEXP no_of_edges, SEXP exponent_out, SEXP exponent_in, SEXP loops, SEXP multiple, SEXP finite_size_correction) { +SEXP R_igraph_rewire_edges(SEXP graph, SEXP prob, SEXP loops, SEXP multiple) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_no_of_nodes; - igraph_integer_t c_no_of_edges; - igraph_real_t c_exponent_out; - igraph_real_t c_exponent_in; + igraph_real_t c_prob; igraph_bool_t c_loops; igraph_bool_t c_multiple; - igraph_bool_t c_finite_size_correction; - SEXP graph; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(no_of_nodes); - c_no_of_nodes = (igraph_integer_t) REAL(no_of_nodes)[0]; - IGRAPH_R_CHECK_INT(no_of_edges); - c_no_of_edges = (igraph_integer_t) REAL(no_of_edges)[0]; - IGRAPH_R_CHECK_REAL(exponent_out); - c_exponent_out = REAL(exponent_out)[0]; - IGRAPH_R_CHECK_REAL(exponent_in); - c_exponent_in = REAL(exponent_in)[0]; + Rz_SEXP_to_igraph_copy(graph, &c_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + IGRAPH_R_CHECK_REAL(prob); + c_prob = REAL(prob)[0]; IGRAPH_R_CHECK_BOOL(loops); c_loops = LOGICAL(loops)[0]; IGRAPH_R_CHECK_BOOL(multiple); c_multiple = LOGICAL(multiple)[0]; - IGRAPH_R_CHECK_BOOL(finite_size_correction); - c_finite_size_correction = LOGICAL(finite_size_correction)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_static_power_law_game(&c_graph, c_no_of_nodes, c_no_of_edges, c_exponent_out, c_exponent_in, c_loops, c_multiple, c_finite_size_correction)); + IGRAPH_R_CHECK(igraph_rewire_edges(&c_graph, c_prob, c_loops, c_multiple)); /* Convert output */ - IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); @@ -1931,32 +2483,28 @@ SEXP R_igraph_static_power_law_game(SEXP no_of_nodes, SEXP no_of_edges, SEXP exp } /*-------------------------------------------/ -/ igraph_k_regular_game / +/ igraph_rewire_directed_edges / /-------------------------------------------*/ -SEXP R_igraph_k_regular_game(SEXP no_of_nodes, SEXP k, SEXP directed, SEXP multiple) { +SEXP R_igraph_rewire_directed_edges(SEXP graph, SEXP prob, SEXP loops, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_no_of_nodes; - igraph_integer_t c_k; - igraph_bool_t c_directed; - igraph_bool_t c_multiple; - SEXP graph; + igraph_real_t c_prob; + igraph_bool_t c_loops; + igraph_neimode_t c_mode; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(no_of_nodes); - c_no_of_nodes = (igraph_integer_t) REAL(no_of_nodes)[0]; - IGRAPH_R_CHECK_INT(k); - c_k = (igraph_integer_t) REAL(k)[0]; - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(multiple); - c_multiple = LOGICAL(multiple)[0]; + Rz_SEXP_to_igraph_copy(graph, &c_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + IGRAPH_R_CHECK_REAL(prob); + c_prob = REAL(prob)[0]; + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_k_regular_game(&c_graph, c_no_of_nodes, c_k, c_directed, c_multiple)); + IGRAPH_R_CHECK(igraph_rewire_directed_edges(&c_graph, c_prob, c_loops, c_mode)); /* Convert output */ - IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); @@ -1967,39 +2515,41 @@ SEXP R_igraph_k_regular_game(SEXP no_of_nodes, SEXP k, SEXP directed, SEXP multi } /*-------------------------------------------/ -/ igraph_sbm_game / +/ igraph_watts_strogatz_game / /-------------------------------------------*/ -SEXP R_igraph_sbm_game(SEXP n, SEXP pref_matrix, SEXP block_sizes, SEXP directed, SEXP loops) { +SEXP R_igraph_watts_strogatz_game(SEXP dim, SEXP size, SEXP nei, SEXP p, SEXP loops, SEXP multiple) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_n; - igraph_matrix_t c_pref_matrix; - igraph_vector_int_t c_block_sizes; - igraph_bool_t c_directed; + igraph_integer_t c_dim; + igraph_integer_t c_size; + igraph_integer_t c_nei; + igraph_real_t c_p; igraph_bool_t c_loops; + igraph_bool_t c_multiple; SEXP graph; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(n); - c_n = (igraph_integer_t) REAL(n)[0]; - Rz_SEXP_to_matrix(pref_matrix, &c_pref_matrix); - IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(block_sizes, &c_block_sizes)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_block_sizes); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_INT(dim); + c_dim = (igraph_integer_t) REAL(dim)[0]; + IGRAPH_R_CHECK_INT(size); + c_size = (igraph_integer_t) REAL(size)[0]; + IGRAPH_R_CHECK_INT(nei); + c_nei = (igraph_integer_t) REAL(nei)[0]; + IGRAPH_R_CHECK_REAL(p); + c_p = REAL(p)[0]; IGRAPH_R_CHECK_BOOL(loops); c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK_BOOL(multiple); + c_multiple = LOGICAL(multiple)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_sbm_game(&c_graph, c_n, &c_pref_matrix, &c_block_sizes, c_directed, c_loops)); + IGRAPH_R_CHECK(igraph_watts_strogatz_game(&c_graph, c_dim, c_size, c_nei, c_p, c_loops, c_multiple)); /* Convert output */ IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_block_sizes); - IGRAPH_FINALLY_CLEAN(1); r_result = graph; UNPROTECT(1); @@ -2007,30 +2557,31 @@ SEXP R_igraph_sbm_game(SEXP n, SEXP pref_matrix, SEXP block_sizes, SEXP directed } /*-------------------------------------------/ -/ igraph_hsbm_game / +/ igraph_lastcit_game / /-------------------------------------------*/ -SEXP R_igraph_hsbm_game(SEXP n, SEXP m, SEXP rho, SEXP C, SEXP p) { +SEXP R_igraph_lastcit_game(SEXP nodes, SEXP edges_per_node, SEXP agebins, SEXP preference, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_n; - igraph_integer_t c_m; - igraph_vector_t c_rho; - igraph_matrix_t c_C; - igraph_real_t c_p; + igraph_integer_t c_nodes; + igraph_integer_t c_edges_per_node; + igraph_integer_t c_agebins; + igraph_vector_t c_preference; + igraph_bool_t c_directed; SEXP graph; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(n); - c_n = (igraph_integer_t) REAL(n)[0]; - IGRAPH_R_CHECK_INT(m); - c_m = (igraph_integer_t) REAL(m)[0]; - Rz_SEXP_to_vector(rho, &c_rho); - Rz_SEXP_to_matrix(C, &c_C); - IGRAPH_R_CHECK_REAL(p); - c_p = REAL(p)[0]; + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_INT(edges_per_node); + c_edges_per_node = (igraph_integer_t) REAL(edges_per_node)[0]; + IGRAPH_R_CHECK_INT(agebins); + c_agebins = (igraph_integer_t) REAL(agebins)[0]; + Rz_SEXP_to_vector(preference, &c_preference); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_hsbm_game(&c_graph, c_n, c_m, &c_rho, &c_C, c_p)); + IGRAPH_R_CHECK(igraph_lastcit_game(&c_graph, c_nodes, c_edges_per_node, c_agebins, &c_preference, c_directed)); /* Convert output */ IGRAPH_FINALLY(igraph_destroy, &c_graph); @@ -2044,37 +2595,38 @@ SEXP R_igraph_hsbm_game(SEXP n, SEXP m, SEXP rho, SEXP C, SEXP p) { } /*-------------------------------------------/ -/ igraph_hsbm_list_game / +/ igraph_cited_type_game / /-------------------------------------------*/ -SEXP R_igraph_hsbm_list_game(SEXP n, SEXP mlist, SEXP rholist, SEXP Clist, SEXP p) { +SEXP R_igraph_cited_type_game(SEXP nodes, SEXP types, SEXP pref, SEXP edges_per_step, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_n; - igraph_vector_int_t c_mlist; - igraph_vector_list_t c_rholist; - igraph_matrix_list_t c_Clist; - igraph_real_t c_p; + igraph_integer_t c_nodes; + igraph_vector_int_t c_types; + igraph_vector_t c_pref; + igraph_integer_t c_edges_per_step; + igraph_bool_t c_directed; SEXP graph; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(n); - c_n = (igraph_integer_t) REAL(n)[0]; - IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(mlist, &c_mlist)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_mlist); - Ry_igraph_SEXP_to_vector_list(rholist, &c_rholist); - Ry_igraph_SEXP_to_matrixlist(Clist, &c_Clist); - IGRAPH_R_CHECK_REAL(p); - c_p = REAL(p)[0]; + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + Rz_SEXP_to_vector_int_copy(types, &c_types); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_types); + Rz_SEXP_to_vector(pref, &c_pref); + IGRAPH_R_CHECK_INT(edges_per_step); + c_edges_per_step = (igraph_integer_t) REAL(edges_per_step)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_hsbm_list_game(&c_graph, c_n, &c_mlist, &c_rholist, &c_Clist, c_p)); + IGRAPH_R_CHECK(igraph_cited_type_game(&c_graph, c_nodes, &c_types, &c_pref, c_edges_per_step, c_directed)); /* Convert output */ IGRAPH_FINALLY(igraph_destroy, &c_graph); PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_mlist); + igraph_vector_int_destroy(&c_types); IGRAPH_FINALLY_CLEAN(1); r_result = graph; @@ -2083,123 +2635,108 @@ SEXP R_igraph_hsbm_list_game(SEXP n, SEXP mlist, SEXP rholist, SEXP Clist, SEXP } /*-------------------------------------------/ -/ igraph_correlated_game / +/ igraph_citing_cited_type_game / /-------------------------------------------*/ -SEXP R_igraph_correlated_game(SEXP old_graph, SEXP corr, SEXP p, SEXP permutation) { +SEXP R_igraph_citing_cited_type_game(SEXP nodes, SEXP types, SEXP pref, SEXP edges_per_step, SEXP directed) { /* Declarations */ - igraph_t c_old_graph; - igraph_t c_new_graph; - igraph_real_t c_corr; - igraph_real_t c_p; - igraph_vector_int_t c_permutation; - SEXP new_graph; + igraph_t c_graph; + igraph_integer_t c_nodes; + igraph_vector_int_t c_types; + igraph_matrix_t c_pref; + igraph_integer_t c_edges_per_step; + igraph_bool_t c_directed; + SEXP graph; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(old_graph, &c_old_graph); - IGRAPH_R_CHECK_REAL(corr); - c_corr = REAL(corr)[0]; - IGRAPH_R_CHECK_REAL(p); - c_p = REAL(p)[0]; - if (!Rf_isNull(permutation)) { - Rz_SEXP_to_vector_int_copy(permutation, &c_permutation); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_permutation); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_permutation, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_permutation); - } + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + Rz_SEXP_to_vector_int_copy(types, &c_types); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_types); + Rz_SEXP_to_matrix(pref, &c_pref); + IGRAPH_R_CHECK_INT(edges_per_step); + c_edges_per_step = (igraph_integer_t) REAL(edges_per_step)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_correlated_game(&c_old_graph, &c_new_graph, c_corr, c_p, (Rf_isNull(permutation) ? 0 : &c_permutation))); + IGRAPH_R_CHECK(igraph_citing_cited_type_game(&c_graph, c_nodes, &c_types, &c_pref, c_edges_per_step, c_directed)); /* Convert output */ - IGRAPH_FINALLY(igraph_destroy, &c_new_graph); - PROTECT(new_graph=Ry_igraph_to_SEXP(&c_new_graph)); - IGRAPH_I_DESTROY(&c_new_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_permutation); + igraph_vector_int_destroy(&c_types); IGRAPH_FINALLY_CLEAN(1); - r_result = new_graph; + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_correlated_pair_game / +/ igraph_forest_fire_game / /-------------------------------------------*/ -SEXP R_igraph_correlated_pair_game(SEXP n, SEXP corr, SEXP p, SEXP directed, SEXP permutation) { +SEXP R_igraph_forest_fire_game(SEXP nodes, SEXP fw_prob, SEXP bw_factor, SEXP ambs, SEXP directed) { /* Declarations */ - igraph_t c_graph1; - igraph_t c_graph2; - igraph_integer_t c_n; - igraph_real_t c_corr; - igraph_real_t c_p; + igraph_t c_graph; + igraph_integer_t c_nodes; + igraph_real_t c_fw_prob; + igraph_real_t c_bw_factor; + igraph_integer_t c_ambs; igraph_bool_t c_directed; - igraph_vector_int_t c_permutation; - SEXP graph1; - SEXP graph2; + SEXP graph; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(n); - c_n = (igraph_integer_t) REAL(n)[0]; - IGRAPH_R_CHECK_REAL(corr); - c_corr = REAL(corr)[0]; - IGRAPH_R_CHECK_REAL(p); - c_p = REAL(p)[0]; + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_REAL(fw_prob); + c_fw_prob = REAL(fw_prob)[0]; + IGRAPH_R_CHECK_REAL(bw_factor); + c_bw_factor = REAL(bw_factor)[0]; + IGRAPH_R_CHECK_INT(ambs); + c_ambs = (igraph_integer_t) REAL(ambs)[0]; IGRAPH_R_CHECK_BOOL(directed); c_directed = LOGICAL(directed)[0]; - if (!Rf_isNull(permutation)) { - Rz_SEXP_to_vector_int_copy(permutation, &c_permutation); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_permutation); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_permutation, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_permutation); - } /* Call igraph */ - IGRAPH_R_CHECK(igraph_correlated_pair_game(&c_graph1, &c_graph2, c_n, c_corr, c_p, c_directed, (Rf_isNull(permutation) ? 0 : &c_permutation))); + IGRAPH_R_CHECK(igraph_forest_fire_game(&c_graph, c_nodes, c_fw_prob, c_bw_factor, c_ambs, c_directed)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - IGRAPH_FINALLY(igraph_destroy, &c_graph1); - PROTECT(graph1=Ry_igraph_to_SEXP(&c_graph1)); - IGRAPH_I_DESTROY(&c_graph1); - IGRAPH_FINALLY_CLEAN(1); - IGRAPH_FINALLY(igraph_destroy, &c_graph2); - PROTECT(graph2=Ry_igraph_to_SEXP(&c_graph2)); - IGRAPH_I_DESTROY(&c_graph2); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_permutation); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, graph1); - SET_VECTOR_ELT(r_result, 1, graph2); - SET_STRING_ELT(r_names, 0, Rf_mkChar("graph1")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("graph2")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_dot_product_game / +/ igraph_simple_interconnected_islands_game / /-------------------------------------------*/ -SEXP R_igraph_dot_product_game(SEXP vecs, SEXP directed) { +SEXP R_igraph_simple_interconnected_islands_game(SEXP islands_n, SEXP islands_size, SEXP islands_pin, SEXP n_inter) { /* Declarations */ igraph_t c_graph; - igraph_matrix_t c_vecs; - igraph_bool_t c_directed; + igraph_integer_t c_islands_n; + igraph_integer_t c_islands_size; + igraph_real_t c_islands_pin; + igraph_integer_t c_n_inter; SEXP graph; SEXP r_result; /* Convert input */ - Rz_SEXP_to_matrix(vecs, &c_vecs); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_INT(islands_n); + c_islands_n = (igraph_integer_t) REAL(islands_n)[0]; + IGRAPH_R_CHECK_INT(islands_size); + c_islands_size = (igraph_integer_t) REAL(islands_size)[0]; + IGRAPH_R_CHECK_REAL(islands_pin); + c_islands_pin = REAL(islands_pin)[0]; + IGRAPH_R_CHECK_INT(n_inter); + c_n_inter = (igraph_integer_t) REAL(n_inter)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_dot_product_game(&c_graph, &c_vecs, c_directed)); + IGRAPH_R_CHECK(igraph_simple_interconnected_islands_game(&c_graph, c_islands_n, c_islands_size, c_islands_pin, c_n_inter)); /* Convert output */ IGRAPH_FINALLY(igraph_destroy, &c_graph); @@ -2213,255 +2750,2477 @@ SEXP R_igraph_dot_product_game(SEXP vecs, SEXP directed) { } /*-------------------------------------------/ -/ igraph_sample_sphere_surface / +/ igraph_chung_lu_game / /-------------------------------------------*/ -SEXP R_igraph_sample_sphere_surface(SEXP dim, SEXP n, SEXP radius, SEXP positive) { +SEXP R_igraph_chung_lu_game(SEXP out_weights, SEXP in_weights, SEXP loops, SEXP variant) { /* Declarations */ - igraph_integer_t c_dim; - igraph_integer_t c_n; - igraph_real_t c_radius; - igraph_bool_t c_positive; - igraph_matrix_t c_res; - SEXP res; + igraph_t c_graph; + igraph_vector_t c_out_weights; + igraph_vector_t c_in_weights; + igraph_bool_t c_loops; + igraph_chung_lu_t c_variant; + SEXP graph; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(dim); - c_dim = (igraph_integer_t) REAL(dim)[0]; - IGRAPH_R_CHECK_INT(n); - c_n = (igraph_integer_t) REAL(n)[0]; - IGRAPH_R_CHECK_REAL(radius); - c_radius = REAL(radius)[0]; - IGRAPH_R_CHECK_BOOL(positive); - c_positive = LOGICAL(positive)[0]; - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + Rz_SEXP_to_vector(out_weights, &c_out_weights); + if (!Rf_isNull(in_weights)) { + Rz_SEXP_to_vector(in_weights, &c_in_weights); + } + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; + c_variant = (igraph_chung_lu_t) Rf_asInteger(variant); /* Call igraph */ - IGRAPH_R_CHECK(igraph_sample_sphere_surface(c_dim, c_n, c_radius, c_positive, &c_res)); + IGRAPH_R_CHECK(igraph_chung_lu_game(&c_graph, &c_out_weights, (Rf_isNull(in_weights) ? 0 : &c_in_weights), c_loops, c_variant)); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_sample_sphere_volume / +/ igraph_static_fitness_game / /-------------------------------------------*/ -SEXP R_igraph_sample_sphere_volume(SEXP dim, SEXP n, SEXP radius, SEXP positive) { +SEXP R_igraph_static_fitness_game(SEXP no_of_edges, SEXP fitness_out, SEXP fitness_in, SEXP loops, SEXP multiple) { /* Declarations */ - igraph_integer_t c_dim; - igraph_integer_t c_n; - igraph_real_t c_radius; - igraph_bool_t c_positive; - igraph_matrix_t c_res; - SEXP res; + igraph_t c_graph; + igraph_integer_t c_no_of_edges; + igraph_vector_t c_fitness_out; + igraph_vector_t c_fitness_in; + igraph_bool_t c_loops; + igraph_bool_t c_multiple; + SEXP graph; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(dim); - c_dim = (igraph_integer_t) REAL(dim)[0]; - IGRAPH_R_CHECK_INT(n); - c_n = (igraph_integer_t) REAL(n)[0]; - IGRAPH_R_CHECK_REAL(radius); - c_radius = REAL(radius)[0]; - IGRAPH_R_CHECK_BOOL(positive); - c_positive = LOGICAL(positive)[0]; - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK_INT(no_of_edges); + c_no_of_edges = (igraph_integer_t) REAL(no_of_edges)[0]; + Rz_SEXP_to_vector(fitness_out, &c_fitness_out); + if (!Rf_isNull(fitness_in)) { + Rz_SEXP_to_vector(fitness_in, &c_fitness_in); + } + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK_BOOL(multiple); + c_multiple = LOGICAL(multiple)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_sample_sphere_volume(c_dim, c_n, c_radius, c_positive, &c_res)); + IGRAPH_R_CHECK(igraph_static_fitness_game(&c_graph, c_no_of_edges, &c_fitness_out, (Rf_isNull(fitness_in) ? 0 : &c_fitness_in), c_loops, c_multiple)); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_sample_dirichlet / +/ igraph_static_power_law_game / /-------------------------------------------*/ -SEXP R_igraph_sample_dirichlet(SEXP n, SEXP alpha) { +SEXP R_igraph_static_power_law_game(SEXP no_of_nodes, SEXP no_of_edges, SEXP exponent_out, SEXP exponent_in, SEXP loops, SEXP multiple, SEXP finite_size_correction) { /* Declarations */ - igraph_integer_t c_n; - igraph_vector_t c_alpha; - igraph_matrix_t c_res; - SEXP res; + igraph_t c_graph; + igraph_integer_t c_no_of_nodes; + igraph_integer_t c_no_of_edges; + igraph_real_t c_exponent_out; + igraph_real_t c_exponent_in; + igraph_bool_t c_loops; + igraph_bool_t c_multiple; + igraph_bool_t c_finite_size_correction; + SEXP graph; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK_INT(n); - c_n = (igraph_integer_t) REAL(n)[0]; - Rz_SEXP_to_vector(alpha, &c_alpha); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK_INT(no_of_nodes); + c_no_of_nodes = (igraph_integer_t) REAL(no_of_nodes)[0]; + IGRAPH_R_CHECK_INT(no_of_edges); + c_no_of_edges = (igraph_integer_t) REAL(no_of_edges)[0]; + IGRAPH_R_CHECK_REAL(exponent_out); + c_exponent_out = REAL(exponent_out)[0]; + IGRAPH_R_CHECK_REAL(exponent_in); + c_exponent_in = REAL(exponent_in)[0]; + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK_BOOL(multiple); + c_multiple = LOGICAL(multiple)[0]; + IGRAPH_R_CHECK_BOOL(finite_size_correction); + c_finite_size_correction = LOGICAL(finite_size_correction)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_sample_dirichlet(c_n, &c_alpha, &c_res)); + IGRAPH_R_CHECK(igraph_static_power_law_game(&c_graph, c_no_of_nodes, c_no_of_edges, c_exponent_out, c_exponent_in, c_loops, c_multiple, c_finite_size_correction)); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_are_adjacent / +/ igraph_k_regular_game / /-------------------------------------------*/ -SEXP R_igraph_are_adjacent(SEXP graph, SEXP v1, SEXP v2) { +SEXP R_igraph_k_regular_game(SEXP no_of_nodes, SEXP k, SEXP directed, SEXP multiple) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_v1; - igraph_integer_t c_v2; - igraph_bool_t c_res; - SEXP res; + igraph_integer_t c_no_of_nodes; + igraph_integer_t c_k; + igraph_bool_t c_directed; + igraph_bool_t c_multiple; + SEXP graph; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - c_v1 = (igraph_integer_t) REAL(v1)[0]; - c_v2 = (igraph_integer_t) REAL(v2)[0]; + IGRAPH_R_CHECK_INT(no_of_nodes); + c_no_of_nodes = (igraph_integer_t) REAL(no_of_nodes)[0]; + IGRAPH_R_CHECK_INT(k); + c_k = (igraph_integer_t) REAL(k)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(multiple); + c_multiple = LOGICAL(multiple)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_are_adjacent(&c_graph, c_v1, c_v2, &c_res)); + IGRAPH_R_CHECK(igraph_k_regular_game(&c_graph, c_no_of_nodes, c_k, c_directed, c_multiple)); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; - r_result = res; + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_closeness / +/ igraph_sbm_game / /-------------------------------------------*/ -SEXP R_igraph_closeness(SEXP graph, SEXP vids, SEXP mode, SEXP weights, SEXP normalized) { +SEXP R_igraph_sbm_game(SEXP n, SEXP pref_matrix, SEXP block_sizes, SEXP directed, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vector_int_t c_reachable_count; - igraph_bool_t c_all_reachable; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - igraph_vector_t c_weights; - igraph_bool_t c_normalized; - SEXP res; - SEXP reachable_count; - SEXP all_reachable; + igraph_integer_t c_n; + igraph_matrix_t c_pref_matrix; + igraph_vector_int_t c_block_sizes; + igraph_bool_t c_directed; + igraph_bool_t c_loops; + SEXP graph; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_reachable_count, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_reachable_count); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + Rz_SEXP_to_matrix(pref_matrix, &c_pref_matrix); + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(block_sizes, &c_block_sizes)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_block_sizes); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_closeness(&c_graph, &c_res, &c_reachable_count, &c_all_reachable, c_vids, c_mode, (Rf_isNull(weights) ? 0 : &c_weights), c_normalized)); + IGRAPH_R_CHECK(igraph_sbm_game(&c_graph, c_n, &c_pref_matrix, &c_block_sizes, c_directed, c_loops)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - PROTECT(reachable_count=Ry_igraph_vector_int_to_SEXP(&c_reachable_count)); - igraph_vector_int_destroy(&c_reachable_count); + igraph_vector_int_destroy(&c_block_sizes); IGRAPH_FINALLY_CLEAN(1); - PROTECT(all_reachable=NEW_LOGICAL(1)); - LOGICAL(all_reachable)[0]=c_all_reachable; - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, reachable_count); - SET_VECTOR_ELT(r_result, 2, all_reachable); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("reachable_count")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("all_reachable")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_closeness_cutoff / +/ igraph_hsbm_game / /-------------------------------------------*/ -SEXP R_igraph_closeness_cutoff(SEXP graph, SEXP vids, SEXP mode, SEXP weights, SEXP normalized, SEXP cutoff) { +SEXP R_igraph_hsbm_game(SEXP n, SEXP m, SEXP rho, SEXP C, SEXP p) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vector_int_t c_reachable_count; - igraph_bool_t c_all_reachable; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - igraph_vector_t c_weights; - igraph_bool_t c_normalized; - igraph_real_t c_cutoff; - SEXP res; - SEXP reachable_count; - SEXP all_reachable; + igraph_integer_t c_n; + igraph_integer_t c_m; + igraph_vector_t c_rho; + igraph_matrix_t c_C; + igraph_real_t c_p; + SEXP graph; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_reachable_count, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_reachable_count); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; - IGRAPH_R_CHECK_REAL(cutoff); - c_cutoff = REAL(cutoff)[0]; - /* Call igraph */ - IGRAPH_R_CHECK(igraph_closeness_cutoff(&c_graph, &c_res, &c_reachable_count, &c_all_reachable, c_vids, c_mode, (Rf_isNull(weights) ? 0 : &c_weights), c_normalized, c_cutoff)); - - /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_INT(m); + c_m = (igraph_integer_t) REAL(m)[0]; + Rz_SEXP_to_vector(rho, &c_rho); + Rz_SEXP_to_matrix(C, &c_C); + IGRAPH_R_CHECK_REAL(p); + c_p = REAL(p)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_hsbm_game(&c_graph, c_n, c_m, &c_rho, &c_C, c_p)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_hsbm_list_game / +/-------------------------------------------*/ +SEXP R_igraph_hsbm_list_game(SEXP n, SEXP mlist, SEXP rholist, SEXP Clist, SEXP p) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_n; + igraph_vector_int_t c_mlist; + igraph_vector_list_t c_rholist; + igraph_matrix_list_t c_Clist; + igraph_real_t c_p; + SEXP graph; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(mlist, &c_mlist)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_mlist); + Ry_igraph_SEXP_to_vector_list(rholist, &c_rholist); + Ry_igraph_SEXP_to_matrixlist(Clist, &c_Clist); + IGRAPH_R_CHECK_REAL(p); + c_p = REAL(p)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_hsbm_list_game(&c_graph, c_n, &c_mlist, &c_rholist, &c_Clist, c_p)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_mlist); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_correlated_game / +/-------------------------------------------*/ +SEXP R_igraph_correlated_game(SEXP old_graph, SEXP corr, SEXP p, SEXP permutation) { + /* Declarations */ + igraph_t c_old_graph; + igraph_t c_new_graph; + igraph_real_t c_corr; + igraph_real_t c_p; + igraph_vector_int_t c_permutation; + SEXP new_graph; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(old_graph, &c_old_graph); + IGRAPH_R_CHECK_REAL(corr); + c_corr = REAL(corr)[0]; + IGRAPH_R_CHECK_REAL(p); + c_p = REAL(p)[0]; + if (!Rf_isNull(permutation)) { + Rz_SEXP_to_vector_int_copy(permutation, &c_permutation); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_permutation); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_permutation, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_permutation); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_correlated_game(&c_old_graph, &c_new_graph, c_corr, c_p, (Rf_isNull(permutation) ? 0 : &c_permutation))); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_new_graph); + PROTECT(new_graph=Ry_igraph_to_SEXP(&c_new_graph)); + IGRAPH_I_DESTROY(&c_new_graph); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_permutation); + IGRAPH_FINALLY_CLEAN(1); + r_result = new_graph; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_correlated_pair_game / +/-------------------------------------------*/ +SEXP R_igraph_correlated_pair_game(SEXP n, SEXP corr, SEXP p, SEXP directed, SEXP permutation) { + /* Declarations */ + igraph_t c_graph1; + igraph_t c_graph2; + igraph_integer_t c_n; + igraph_real_t c_corr; + igraph_real_t c_p; + igraph_bool_t c_directed; + igraph_vector_int_t c_permutation; + SEXP graph1; + SEXP graph2; + + SEXP r_result, r_names; + /* Convert input */ + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_REAL(corr); + c_corr = REAL(corr)[0]; + IGRAPH_R_CHECK_REAL(p); + c_p = REAL(p)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + if (!Rf_isNull(permutation)) { + Rz_SEXP_to_vector_int_copy(permutation, &c_permutation); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_permutation); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_permutation, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_permutation); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_correlated_pair_game(&c_graph1, &c_graph2, c_n, c_corr, c_p, c_directed, (Rf_isNull(permutation) ? 0 : &c_permutation))); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + IGRAPH_FINALLY(igraph_destroy, &c_graph1); + PROTECT(graph1=Ry_igraph_to_SEXP(&c_graph1)); + IGRAPH_I_DESTROY(&c_graph1); + IGRAPH_FINALLY_CLEAN(1); + IGRAPH_FINALLY(igraph_destroy, &c_graph2); + PROTECT(graph2=Ry_igraph_to_SEXP(&c_graph2)); + IGRAPH_I_DESTROY(&c_graph2); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_permutation); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph1); + SET_VECTOR_ELT(r_result, 1, graph2); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph1")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("graph2")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_dot_product_game / +/-------------------------------------------*/ +SEXP R_igraph_dot_product_game(SEXP vecs, SEXP directed) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_vecs; + igraph_bool_t c_directed; + SEXP graph; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_matrix(vecs, &c_vecs); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_dot_product_game(&c_graph, &c_vecs, c_directed)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_sample_sphere_surface / +/-------------------------------------------*/ +SEXP R_igraph_sample_sphere_surface(SEXP dim, SEXP n, SEXP radius, SEXP positive) { + /* Declarations */ + igraph_integer_t c_dim; + igraph_integer_t c_n; + igraph_real_t c_radius; + igraph_bool_t c_positive; + igraph_matrix_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(dim); + c_dim = (igraph_integer_t) REAL(dim)[0]; + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_REAL(radius); + c_radius = REAL(radius)[0]; + IGRAPH_R_CHECK_BOOL(positive); + c_positive = LOGICAL(positive)[0]; + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_sample_sphere_surface(c_dim, c_n, c_radius, c_positive, &c_res)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_sample_sphere_volume / +/-------------------------------------------*/ +SEXP R_igraph_sample_sphere_volume(SEXP dim, SEXP n, SEXP radius, SEXP positive) { + /* Declarations */ + igraph_integer_t c_dim; + igraph_integer_t c_n; + igraph_real_t c_radius; + igraph_bool_t c_positive; + igraph_matrix_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(dim); + c_dim = (igraph_integer_t) REAL(dim)[0]; + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_REAL(radius); + c_radius = REAL(radius)[0]; + IGRAPH_R_CHECK_BOOL(positive); + c_positive = LOGICAL(positive)[0]; + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_sample_sphere_volume(c_dim, c_n, c_radius, c_positive, &c_res)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_sample_dirichlet / +/-------------------------------------------*/ +SEXP R_igraph_sample_dirichlet(SEXP n, SEXP alpha) { + /* Declarations */ + igraph_integer_t c_n; + igraph_vector_t c_alpha; + igraph_matrix_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + Rz_SEXP_to_vector(alpha, &c_alpha); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_sample_dirichlet(c_n, &c_alpha, &c_res)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_are_adjacent / +/-------------------------------------------*/ +SEXP R_igraph_are_adjacent(SEXP graph, SEXP v1, SEXP v2) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_v1; + igraph_integer_t c_v2; + igraph_bool_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_v1 = (igraph_integer_t) REAL(v1)[0]; + c_v2 = (igraph_integer_t) REAL(v2)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_are_adjacent(&c_graph, c_v1, c_v2, &c_res)); + + /* Convert output */ + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_are_connected / +/-------------------------------------------*/ +SEXP R_igraph_are_connected(SEXP graph, SEXP v1, SEXP v2) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_v1; + igraph_integer_t c_v2; + igraph_bool_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_v1 = (igraph_integer_t) REAL(v1)[0]; + c_v2 = (igraph_integer_t) REAL(v2)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_are_connected(&c_graph, c_v1, c_v2, &c_res)); + + /* Convert output */ + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_diameter / +/-------------------------------------------*/ +SEXP R_igraph_diameter(SEXP graph, SEXP directed, SEXP unconnected) { + /* Declarations */ + igraph_t c_graph; + igraph_real_t c_res; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_vector_int_t c_vertex_path; + igraph_vector_int_t c_edge_path; + igraph_bool_t c_directed; + igraph_bool_t c_unconnected; + SEXP res; + SEXP from; + SEXP to; + SEXP vertex_path; + SEXP edge_path; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_from=0; + c_to=0; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_path, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_path); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edge_path, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_path); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(unconnected); + c_unconnected = LOGICAL(unconnected)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_diameter(&c_graph, &c_res, &c_from, &c_to, &c_vertex_path, &c_edge_path, c_directed, c_unconnected)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(5)); + PROTECT(r_names=NEW_CHARACTER(5)); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + PROTECT(from=NEW_NUMERIC(1)); + REAL(from)[0]=(double) c_from; + PROTECT(to=NEW_NUMERIC(1)); + REAL(to)[0]=(double) c_to; + PROTECT(vertex_path=Ry_igraph_vector_int_to_SEXP(&c_vertex_path)); + igraph_vector_int_destroy(&c_vertex_path); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edge_path=Ry_igraph_vector_int_to_SEXP(&c_edge_path)); + igraph_vector_int_destroy(&c_edge_path); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, from); + SET_VECTOR_ELT(r_result, 2, to); + SET_VECTOR_ELT(r_result, 3, vertex_path); + SET_VECTOR_ELT(r_result, 4, edge_path); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("from")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("to")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("vertex_path")); + SET_STRING_ELT(r_names, 4, Rf_mkChar("edge_path")); + SET_NAMES(r_result, r_names); + UNPROTECT(6); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_diameter_dijkstra / +/-------------------------------------------*/ +SEXP R_igraph_diameter_dijkstra(SEXP graph, SEXP weights, SEXP directed, SEXP unconnected) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_weights; + igraph_real_t c_res; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_vector_int_t c_vertex_path; + igraph_vector_int_t c_edge_path; + igraph_bool_t c_directed; + igraph_bool_t c_unconnected; + SEXP res; + SEXP from; + SEXP to; + SEXP vertex_path; + SEXP edge_path; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_from=0; + c_to=0; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_path, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_path); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edge_path, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_path); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(unconnected); + c_unconnected = LOGICAL(unconnected)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_diameter_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, &c_from, &c_to, &c_vertex_path, &c_edge_path, c_directed, c_unconnected)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(5)); + PROTECT(r_names=NEW_CHARACTER(5)); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + PROTECT(from=NEW_NUMERIC(1)); + REAL(from)[0]=(double) c_from; + PROTECT(to=NEW_NUMERIC(1)); + REAL(to)[0]=(double) c_to; + PROTECT(vertex_path=Ry_igraph_vector_int_to_SEXP(&c_vertex_path)); + igraph_vector_int_destroy(&c_vertex_path); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edge_path=Ry_igraph_vector_int_to_SEXP(&c_edge_path)); + igraph_vector_int_destroy(&c_edge_path); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, from); + SET_VECTOR_ELT(r_result, 2, to); + SET_VECTOR_ELT(r_result, 3, vertex_path); + SET_VECTOR_ELT(r_result, 4, edge_path); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("from")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("to")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("vertex_path")); + SET_STRING_ELT(r_names, 4, Rf_mkChar("edge_path")); + SET_NAMES(r_result, r_names); + UNPROTECT(6); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_closeness / +/-------------------------------------------*/ +SEXP R_igraph_closeness(SEXP graph, SEXP vids, SEXP mode, SEXP weights, SEXP normalized) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_vector_int_t c_reachable_count; + igraph_bool_t c_all_reachable; + igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_vector_t c_weights; + igraph_bool_t c_normalized; + SEXP res; + SEXP reachable_count; + SEXP all_reachable; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_reachable_count, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_reachable_count); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_closeness(&c_graph, &c_res, &c_reachable_count, &c_all_reachable, c_vids, c_mode, (Rf_isNull(weights) ? 0 : &c_weights), c_normalized)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(reachable_count=Ry_igraph_vector_int_to_SEXP(&c_reachable_count)); + igraph_vector_int_destroy(&c_reachable_count); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(all_reachable=NEW_LOGICAL(1)); + LOGICAL(all_reachable)[0]=c_all_reachable; + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, reachable_count); + SET_VECTOR_ELT(r_result, 2, all_reachable); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("reachable_count")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("all_reachable")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_closeness_cutoff / +/-------------------------------------------*/ +SEXP R_igraph_closeness_cutoff(SEXP graph, SEXP vids, SEXP mode, SEXP weights, SEXP normalized, SEXP cutoff) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_vector_int_t c_reachable_count; + igraph_bool_t c_all_reachable; + igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_vector_t c_weights; + igraph_bool_t c_normalized; + igraph_real_t c_cutoff; + SEXP res; + SEXP reachable_count; + SEXP all_reachable; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_reachable_count, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_reachable_count); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; + IGRAPH_R_CHECK_REAL(cutoff); + c_cutoff = REAL(cutoff)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_closeness_cutoff(&c_graph, &c_res, &c_reachable_count, &c_all_reachable, c_vids, c_mode, (Rf_isNull(weights) ? 0 : &c_weights), c_normalized, c_cutoff)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(reachable_count=Ry_igraph_vector_int_to_SEXP(&c_reachable_count)); + igraph_vector_int_destroy(&c_reachable_count); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(all_reachable=NEW_LOGICAL(1)); + LOGICAL(all_reachable)[0]=c_all_reachable; + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, reachable_count); + SET_VECTOR_ELT(r_result, 2, all_reachable); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("reachable_count")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("all_reachable")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_distances / +/-------------------------------------------*/ +SEXP R_igraph_distances(SEXP graph, SEXP from, SEXP to, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_neimode_t c_mode; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_distances(&c_graph, &c_res, c_from, c_to, c_mode)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_distances_cutoff / +/-------------------------------------------*/ +SEXP R_igraph_distances_cutoff(SEXP graph, SEXP from, SEXP to, SEXP mode, SEXP cutoff) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_neimode_t c_mode; + igraph_real_t c_cutoff; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_REAL(cutoff); + c_cutoff = REAL(cutoff)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_distances_cutoff(&c_graph, &c_res, c_from, c_to, c_mode, c_cutoff)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_shortest_path / +/-------------------------------------------*/ +SEXP R_igraph_get_shortest_path(SEXP graph, SEXP from, SEXP to, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_vertices; + igraph_vector_int_t c_edges; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_neimode_t c_mode; + SEXP vertices; + SEXP edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + c_to = (igraph_integer_t) REAL(to)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_shortest_path(&c_graph, &c_vertices, &c_edges, c_from, c_to, c_mode)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); + igraph_vector_int_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); + igraph_vector_int_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_shortest_path_bellman_ford / +/-------------------------------------------*/ +SEXP R_igraph_get_shortest_path_bellman_ford(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_vertices; + igraph_vector_int_t c_edges; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + SEXP vertices; + SEXP edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + c_to = (igraph_integer_t) REAL(to)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_shortest_path_bellman_ford(&c_graph, &c_vertices, &c_edges, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); + igraph_vector_int_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); + igraph_vector_int_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_shortest_path_dijkstra / +/-------------------------------------------*/ +SEXP R_igraph_get_shortest_path_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_vertices; + igraph_vector_int_t c_edges; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + SEXP vertices; + SEXP edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + c_to = (igraph_integer_t) REAL(to)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_shortest_path_dijkstra(&c_graph, &c_vertices, &c_edges, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); + igraph_vector_int_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); + igraph_vector_int_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_shortest_path_astar / +/-------------------------------------------*/ +SEXP R_igraph_get_shortest_path_astar(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_vertices; + igraph_vector_int_t c_edges; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + + + SEXP vertices; + SEXP edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + c_to = (igraph_integer_t) REAL(to)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_shortest_path_astar(&c_graph, &c_vertices, &c_edges, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode, 0, 0)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); + igraph_vector_int_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); + igraph_vector_int_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_shortest_paths / +/-------------------------------------------*/ +SEXP R_igraph_get_shortest_paths(SEXP graph, SEXP from, SEXP to, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_list_t c_vertices; + igraph_vector_int_list_t c_edges; + igraph_integer_t c_from; + igraph_vs_t c_to; + igraph_neimode_t c_mode; + igraph_vector_int_t c_parents; + igraph_vector_int_t c_inbound_edges; + SEXP vertices; + SEXP edges; + SEXP parents; + SEXP inbound_edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_parents, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_parents); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_inbound_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_inbound_edges); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_shortest_paths(&c_graph, &c_vertices, &c_edges, c_from, c_to, c_mode, &c_parents, &c_inbound_edges)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); + igraph_vector_int_list_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); + igraph_vector_int_list_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + PROTECT(parents=Ry_igraph_vector_int_to_SEXP(&c_parents)); + igraph_vector_int_destroy(&c_parents); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(inbound_edges=Ry_igraph_vector_int_to_SEXP(&c_inbound_edges)); + igraph_vector_int_destroy(&c_inbound_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_VECTOR_ELT(r_result, 2, parents); + SET_VECTOR_ELT(r_result, 3, inbound_edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("parents")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("inbound_edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_all_shortest_paths / +/-------------------------------------------*/ +SEXP R_igraph_get_all_shortest_paths(SEXP graph, SEXP from, SEXP to, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_list_t c_vertices; + igraph_vector_int_list_t c_edges; + igraph_vector_int_t c_nrgeo; + igraph_integer_t c_from; + igraph_vs_t c_to; + igraph_neimode_t c_mode; + SEXP vertices; + SEXP edges; + SEXP nrgeo; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_nrgeo, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_nrgeo); + c_from = (igraph_integer_t) REAL(from)[0]; + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_all_shortest_paths(&c_graph, &c_vertices, &c_edges, &c_nrgeo, c_from, c_to, c_mode)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); + igraph_vector_int_list_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); + igraph_vector_int_list_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(nrgeo=Ry_igraph_vector_int_to_SEXP(&c_nrgeo)); + igraph_vector_int_destroy(&c_nrgeo); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_VECTOR_ELT(r_result, 2, nrgeo); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vpaths")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("epaths")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("nrgeo")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_distances_dijkstra / +/-------------------------------------------*/ +SEXP R_igraph_distances_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_distances_dijkstra(&c_graph, &c_res, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_distances_dijkstra_cutoff / +/-------------------------------------------*/ +SEXP R_igraph_distances_dijkstra_cutoff(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode, SEXP cutoff) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + igraph_real_t c_cutoff; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_REAL(cutoff); + c_cutoff = REAL(cutoff)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_distances_dijkstra_cutoff(&c_graph, &c_res, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode, c_cutoff)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_shortest_paths_dijkstra / +/-------------------------------------------*/ +SEXP R_igraph_get_shortest_paths_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_list_t c_vertices; + igraph_vector_int_list_t c_edges; + igraph_integer_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + igraph_vector_int_t c_parents; + igraph_vector_int_t c_inbound_edges; + SEXP vertices; + SEXP edges; + SEXP parents; + SEXP inbound_edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_parents, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_parents); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_inbound_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_inbound_edges); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_shortest_paths_dijkstra(&c_graph, &c_vertices, &c_edges, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode, &c_parents, &c_inbound_edges)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); + igraph_vector_int_list_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); + igraph_vector_int_list_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + PROTECT(parents=Ry_igraph_vector_int_to_SEXP(&c_parents)); + igraph_vector_int_destroy(&c_parents); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(inbound_edges=Ry_igraph_vector_int_to_SEXP(&c_inbound_edges)); + igraph_vector_int_destroy(&c_inbound_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_VECTOR_ELT(r_result, 2, parents); + SET_VECTOR_ELT(r_result, 3, inbound_edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("parents")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("inbound_edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_shortest_paths_bellman_ford / +/-------------------------------------------*/ +SEXP R_igraph_get_shortest_paths_bellman_ford(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_list_t c_vertices; + igraph_vector_int_list_t c_edges; + igraph_integer_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + igraph_vector_int_t c_parents; + igraph_vector_int_t c_inbound_edges; + SEXP vertices; + SEXP edges; + SEXP parents; + SEXP inbound_edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_parents, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_parents); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_inbound_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_inbound_edges); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_shortest_paths_bellman_ford(&c_graph, &c_vertices, &c_edges, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode, &c_parents, &c_inbound_edges)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); + igraph_vector_int_list_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); + igraph_vector_int_list_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + PROTECT(parents=Ry_igraph_vector_int_to_SEXP(&c_parents)); + igraph_vector_int_destroy(&c_parents); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(inbound_edges=Ry_igraph_vector_int_to_SEXP(&c_inbound_edges)); + igraph_vector_int_destroy(&c_inbound_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_VECTOR_ELT(r_result, 2, parents); + SET_VECTOR_ELT(r_result, 3, inbound_edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("parents")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("inbound_edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_all_shortest_paths_dijkstra / +/-------------------------------------------*/ +SEXP R_igraph_get_all_shortest_paths_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_list_t c_vertices; + igraph_vector_int_list_t c_edges; + igraph_vector_int_t c_nrgeo; + igraph_integer_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + SEXP vertices; + SEXP edges; + SEXP nrgeo; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_nrgeo, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_nrgeo); + c_from = (igraph_integer_t) REAL(from)[0]; + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_all_shortest_paths_dijkstra(&c_graph, &c_vertices, &c_edges, &c_nrgeo, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); + igraph_vector_int_list_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); + igraph_vector_int_list_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(nrgeo=Ry_igraph_vector_int_to_SEXP(&c_nrgeo)); + igraph_vector_int_destroy(&c_nrgeo); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_VECTOR_ELT(r_result, 2, nrgeo); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vpaths")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("epaths")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("nrgeo")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_distances_bellman_ford / +/-------------------------------------------*/ +SEXP R_igraph_distances_bellman_ford(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_distances_bellman_ford(&c_graph, &c_res, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_distances_johnson / +/-------------------------------------------*/ +SEXP R_igraph_distances_johnson(SEXP graph, SEXP from, SEXP to, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_distances_johnson(&c_graph, &c_res, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_distances_floyd_warshall / +/-------------------------------------------*/ +SEXP R_igraph_distances_floyd_warshall(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode, SEXP method) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + igraph_floyd_warshall_algorithm_t c_method; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_method = (igraph_floyd_warshall_algorithm_t) Rf_asInteger(method); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_distances_floyd_warshall(&c_graph, &c_res, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode, c_method)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_voronoi / +/-------------------------------------------*/ +SEXP R_igraph_voronoi(SEXP graph, SEXP generators, SEXP weights, SEXP mode, SEXP tiebreaker) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_membership; + igraph_vector_t c_distances; + igraph_vector_int_t c_generators; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + igraph_voronoi_tiebreaker_t c_tiebreaker; + SEXP membership; + SEXP distances; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); + IGRAPH_R_CHECK(igraph_vector_init(&c_distances, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_distances); + Rz_SEXP_to_vector_int_copy(generators, &c_generators); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_generators); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_tiebreaker = (igraph_voronoi_tiebreaker_t) Rf_asInteger(tiebreaker); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_voronoi(&c_graph, &c_membership, &c_distances, &c_generators, (Rf_isNull(weights) ? 0 : &c_weights), c_mode, c_tiebreaker)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(distances=Ry_igraph_vector_to_SEXP(&c_distances)); + igraph_vector_destroy(&c_distances); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_generators); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, membership); + SET_VECTOR_ELT(r_result, 1, distances); + SET_STRING_ELT(r_names, 0, Rf_mkChar("membership")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("distances")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_all_simple_paths / +/-------------------------------------------*/ +SEXP R_igraph_get_all_simple_paths(SEXP graph, SEXP from, SEXP to, SEXP cutoff, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_res; + igraph_integer_t c_from; + igraph_vs_t c_to; + igraph_integer_t c_cutoff; + igraph_neimode_t c_mode; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + c_from = (igraph_integer_t) REAL(from)[0]; + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + IGRAPH_R_CHECK_INT(cutoff); + c_cutoff = (igraph_integer_t) REAL(cutoff)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_all_simple_paths(&c_graph, &c_res, c_from, c_to, c_cutoff, c_mode)); + + /* Convert output */ + PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); + igraph_vector_int_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_k_shortest_paths / +/-------------------------------------------*/ +SEXP R_igraph_get_k_shortest_paths(SEXP graph, SEXP weights, SEXP k, SEXP from, SEXP to, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_weights; + igraph_vector_int_list_t c_vertex_paths; + igraph_vector_int_list_t c_edge_paths; + igraph_integer_t c_k; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_neimode_t c_mode; + SEXP vertex_paths; + SEXP edge_paths; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertex_paths, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertex_paths); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edge_paths, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edge_paths); + IGRAPH_R_CHECK_INT(k); + c_k = (igraph_integer_t) REAL(k)[0]; + c_from = (igraph_integer_t) REAL(from)[0]; + c_to = (igraph_integer_t) REAL(to)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_k_shortest_paths(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_vertex_paths, &c_edge_paths, c_k, c_from, c_to, c_mode)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(vertex_paths=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertex_paths)); + igraph_vector_int_list_destroy(&c_vertex_paths); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edge_paths=Ry_igraph_vector_int_list_to_SEXPp1(&c_edge_paths)); + igraph_vector_int_list_destroy(&c_edge_paths); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertex_paths); + SET_VECTOR_ELT(r_result, 1, edge_paths); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vpaths")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("epaths")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_widest_path / +/-------------------------------------------*/ +SEXP R_igraph_get_widest_path(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_vertices; + igraph_vector_int_t c_edges; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + SEXP vertices; + SEXP edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + c_to = (igraph_integer_t) REAL(to)[0]; + Rz_SEXP_to_vector(weights, &c_weights); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_widest_path(&c_graph, &c_vertices, &c_edges, c_from, c_to, &c_weights, c_mode)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); + igraph_vector_int_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); + igraph_vector_int_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_get_widest_paths / +/-------------------------------------------*/ +SEXP R_igraph_get_widest_paths(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_list_t c_vertices; + igraph_vector_int_list_t c_edges; + igraph_integer_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + igraph_vector_int_t c_parents; + igraph_vector_int_t c_inbound_edges; + SEXP vertices; + SEXP edges; + SEXP parents; + SEXP inbound_edges; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); + c_from = (igraph_integer_t) REAL(from)[0]; + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + Rz_SEXP_to_vector(weights, &c_weights); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_parents, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_parents); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_inbound_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_inbound_edges); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_widest_paths(&c_graph, &c_vertices, &c_edges, c_from, c_to, &c_weights, c_mode, &c_parents, &c_inbound_edges)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); + igraph_vector_int_list_destroy(&c_vertices); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); + igraph_vector_int_list_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + PROTECT(parents=Ry_igraph_vector_int_to_SEXP(&c_parents)); + igraph_vector_int_destroy(&c_parents); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(inbound_edges=Ry_igraph_vector_int_to_SEXP(&c_inbound_edges)); + igraph_vector_int_destroy(&c_inbound_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_VECTOR_ELT(r_result, 2, parents); + SET_VECTOR_ELT(r_result, 3, inbound_edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("parents")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("inbound_edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_widest_path_widths_dijkstra / +/-------------------------------------------*/ +SEXP R_igraph_widest_path_widths_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + Rz_SEXP_to_vector(weights, &c_weights); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_widest_path_widths_dijkstra(&c_graph, &c_res, c_from, c_to, &c_weights, c_mode)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_widest_path_widths_floyd_warshall / +/-------------------------------------------*/ +SEXP R_igraph_widest_path_widths_floyd_warshall(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_from; + igraph_vs_t c_to; + igraph_vector_t c_weights; + igraph_neimode_t c_mode; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_from_data; + Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); + igraph_vector_int_t c_to_data; + Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); + Rz_SEXP_to_vector(weights, &c_weights); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_widest_path_widths_floyd_warshall(&c_graph, &c_res, c_from, c_to, &c_weights, c_mode)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_from_data); + igraph_vs_destroy(&c_from); + igraph_vector_int_destroy(&c_to_data); + igraph_vs_destroy(&c_to); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_spanner / +/-------------------------------------------*/ +SEXP R_igraph_spanner(SEXP graph, SEXP stretch, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_spanner; + igraph_real_t c_stretch; + igraph_vector_t c_weights; + SEXP spanner; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_spanner, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_spanner); + IGRAPH_R_CHECK_REAL(stretch); + c_stretch = REAL(stretch)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_spanner(&c_graph, &c_spanner, c_stretch, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(spanner=Ry_igraph_vector_int_to_SEXPp1(&c_spanner)); + igraph_vector_int_destroy(&c_spanner); + IGRAPH_FINALLY_CLEAN(1); + r_result = spanner; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_subcomponent / +/-------------------------------------------*/ +SEXP R_igraph_subcomponent(SEXP graph, SEXP vid, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_res; + igraph_integer_t c_vid; + igraph_neimode_t c_mode; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + c_vid = (igraph_integer_t) REAL(vid)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_subcomponent(&c_graph, &c_res, c_vid, c_mode)); + + /* Convert output */ + PROTECT(res=Ry_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_betweenness / +/-------------------------------------------*/ +SEXP R_igraph_betweenness(SEXP graph, SEXP vids, SEXP directed, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_vs_t c_vids; + igraph_bool_t c_directed; + igraph_vector_t c_weights; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_betweenness(&c_graph, &c_res, c_vids, c_directed, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(res=Ry_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_betweenness_cutoff / +/-------------------------------------------*/ +SEXP R_igraph_betweenness_cutoff(SEXP graph, SEXP vids, SEXP directed, SEXP weights, SEXP cutoff) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_vs_t c_vids; + igraph_bool_t c_directed; + igraph_vector_t c_weights; + igraph_real_t c_cutoff; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK_REAL(cutoff); + c_cutoff = REAL(cutoff)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_betweenness_cutoff(&c_graph, &c_res, c_vids, c_directed, (Rf_isNull(weights) ? 0 : &c_weights), c_cutoff)); + + /* Convert output */ + PROTECT(res=Ry_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_betweenness_subset / +/-------------------------------------------*/ +SEXP R_igraph_betweenness_subset(SEXP graph, SEXP vids, SEXP directed, SEXP sources, SEXP targets, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_vs_t c_vids; + igraph_bool_t c_directed; + igraph_vs_t c_sources; + igraph_vs_t c_targets; + igraph_vector_t c_weights; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + igraph_vector_int_t c_sources_data; + Rz_SEXP_to_igraph_vs(sources, &c_graph, &c_sources, &c_sources_data); + igraph_vector_int_t c_targets_data; + Rz_SEXP_to_igraph_vs(targets, &c_graph, &c_targets, &c_targets_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_betweenness_subset(&c_graph, &c_res, c_vids, c_directed, c_sources, c_targets, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - PROTECT(reachable_count=Ry_igraph_vector_int_to_SEXP(&c_reachable_count)); - igraph_vector_int_destroy(&c_reachable_count); + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + igraph_vector_int_destroy(&c_sources_data); + igraph_vs_destroy(&c_sources); + igraph_vector_int_destroy(&c_targets_data); + igraph_vs_destroy(&c_targets); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_edge_betweenness / +/-------------------------------------------*/ +SEXP R_igraph_edge_betweenness(SEXP graph, SEXP directed, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_bool_t c_directed; + igraph_vector_t c_weights; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_edge_betweenness(&c_graph, &c_res, c_directed, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_edge_betweenness_cutoff / +/-------------------------------------------*/ +SEXP R_igraph_edge_betweenness_cutoff(SEXP graph, SEXP directed, SEXP weights, SEXP cutoff) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_bool_t c_directed; + igraph_vector_t c_weights; + igraph_real_t c_cutoff; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK_REAL(cutoff); + c_cutoff = REAL(cutoff)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_edge_betweenness_cutoff(&c_graph, &c_res, c_directed, (Rf_isNull(weights) ? 0 : &c_weights), c_cutoff)); + + /* Convert output */ + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_edge_betweenness_subset / +/-------------------------------------------*/ +SEXP R_igraph_edge_betweenness_subset(SEXP graph, SEXP eids, SEXP directed, SEXP sources, SEXP targets, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_es_t c_eids; + igraph_bool_t c_directed; + igraph_vs_t c_sources; + igraph_vs_t c_targets; + igraph_vector_t c_weights; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_eids_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(eids, &c_graph, &c_eids, &c_eids_data)); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + igraph_vector_int_t c_sources_data; + Rz_SEXP_to_igraph_vs(sources, &c_graph, &c_sources, &c_sources_data); + igraph_vector_int_t c_targets_data; + Rz_SEXP_to_igraph_vs(targets, &c_graph, &c_targets, &c_targets_data); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_edge_betweenness_subset(&c_graph, &c_res, c_eids, c_directed, c_sources, c_targets, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_eids_data); + igraph_es_destroy(&c_eids); + igraph_vector_int_destroy(&c_sources_data); + igraph_vs_destroy(&c_sources); + igraph_vector_int_destroy(&c_targets_data); + igraph_vs_destroy(&c_targets); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_harmonic_centrality / +/-------------------------------------------*/ +SEXP R_igraph_harmonic_centrality(SEXP graph, SEXP vids, SEXP mode, SEXP weights, SEXP normalized) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_vector_t c_weights; + igraph_bool_t c_normalized; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_harmonic_centrality(&c_graph, &c_res, c_vids, c_mode, (Rf_isNull(weights) ? 0 : &c_weights), c_normalized)); + + /* Convert output */ + PROTECT(res=Ry_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_harmonic_centrality_cutoff / +/-------------------------------------------*/ +SEXP R_igraph_harmonic_centrality_cutoff(SEXP graph, SEXP vids, SEXP mode, SEXP weights, SEXP normalized, SEXP cutoff) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_res; + igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_vector_t c_weights; + igraph_bool_t c_normalized; + igraph_real_t c_cutoff; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; + IGRAPH_R_CHECK_REAL(cutoff); + c_cutoff = REAL(cutoff)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_harmonic_centrality_cutoff(&c_graph, &c_res, c_vids, c_mode, (Rf_isNull(weights) ? 0 : &c_weights), c_normalized, c_cutoff)); + + /* Convert output */ + PROTECT(res=Ry_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_pagerank / +/-------------------------------------------*/ +SEXP R_igraph_pagerank(SEXP graph, SEXP algo, SEXP vids, SEXP directed, SEXP damping, SEXP weights, SEXP options) { + /* Declarations */ + igraph_t c_graph; + igraph_pagerank_algo_t c_algo; + igraph_vector_t c_vector; + igraph_real_t c_value; + igraph_vs_t c_vids; + igraph_bool_t c_directed; + igraph_real_t c_damping; + igraph_vector_t c_weights; + igraph_arpack_options_t c_options1; + void* c_options; + SEXP vector; + SEXP value; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_algo = (igraph_pagerank_algo_t) Rf_asInteger(algo); + IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_REAL(damping); + c_damping = REAL(damping)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + if (!Rf_isNull(options)) { + if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { + Rz_SEXP_to_igraph_arpack_options(options, &c_options1); + c_options = &c_options1; + } else { + c_options = NULL; + } + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_pagerank(&c_graph, c_algo, &c_vector, &c_value, c_vids, c_directed, c_damping, (Rf_isNull(weights) ? 0 : &c_weights), c_options)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); + igraph_vector_destroy(&c_vector); IGRAPH_FINALLY_CLEAN(1); - PROTECT(all_reachable=NEW_LOGICAL(1)); - LOGICAL(all_reachable)[0]=c_all_reachable; + PROTECT(value=NEW_NUMERIC(1)); + REAL(value)[0]=c_value; igraph_vector_int_destroy(&c_vids_data); igraph_vs_destroy(&c_vids); - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, reachable_count); - SET_VECTOR_ELT(r_result, 2, all_reachable); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("reachable_count")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("all_reachable")); + if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { + PROTECT(options = Ry_igraph_arpack_options_to_SEXP(&c_options1)); + } else { + PROTECT(options); + } + SET_VECTOR_ELT(r_result, 0, vector); + SET_VECTOR_ELT(r_result, 1, value); + SET_VECTOR_ELT(r_result, 2, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); SET_NAMES(r_result, r_names); UNPROTECT(4); @@ -2470,384 +5229,337 @@ SEXP R_igraph_closeness_cutoff(SEXP graph, SEXP vids, SEXP mode, SEXP weights, S } /*-------------------------------------------/ -/ igraph_get_shortest_path / +/ igraph_personalized_pagerank / /-------------------------------------------*/ -SEXP R_igraph_get_shortest_path(SEXP graph, SEXP from, SEXP to, SEXP mode) { +SEXP R_igraph_personalized_pagerank(SEXP graph, SEXP algo, SEXP vids, SEXP directed, SEXP damping, SEXP personalized, SEXP weights, SEXP options) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_vertices; - igraph_vector_int_t c_edges; - igraph_integer_t c_from; - igraph_integer_t c_to; - igraph_neimode_t c_mode; - SEXP vertices; - SEXP edges; + igraph_pagerank_algo_t c_algo; + igraph_vector_t c_vector; + igraph_real_t c_value; + igraph_vs_t c_vids; + igraph_bool_t c_directed; + igraph_real_t c_damping; + igraph_vector_t c_personalized; + igraph_vector_t c_weights; + igraph_arpack_options_t c_options1; + void* c_options; + SEXP vector; + SEXP value; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); - c_from = (igraph_integer_t) REAL(from)[0]; - c_to = (igraph_integer_t) REAL(to)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_algo = (igraph_pagerank_algo_t) Rf_asInteger(algo); + IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_REAL(damping); + c_damping = REAL(damping)[0]; + if (!Rf_isNull(personalized)) { + Rz_SEXP_to_vector(personalized, &c_personalized); + } + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + if (!Rf_isNull(options)) { + if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { + Rz_SEXP_to_igraph_arpack_options(options, &c_options1); + c_options = &c_options1; + } else { + c_options = NULL; + } + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_shortest_path(&c_graph, &c_vertices, &c_edges, c_from, c_to, c_mode)); + IGRAPH_R_CHECK(igraph_personalized_pagerank(&c_graph, c_algo, &c_vector, &c_value, c_vids, c_directed, c_damping, (Rf_isNull(personalized) ? 0 : &c_personalized), (Rf_isNull(weights) ? 0 : &c_weights), c_options)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); - igraph_vector_int_destroy(&c_vertices); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); - igraph_vector_int_destroy(&c_edges); + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); + igraph_vector_destroy(&c_vector); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, vertices); - SET_VECTOR_ELT(r_result, 1, edges); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + PROTECT(value=NEW_NUMERIC(1)); + REAL(value)[0]=c_value; + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { + PROTECT(options = Ry_igraph_arpack_options_to_SEXP(&c_options1)); + } else { + PROTECT(options); + } + SET_VECTOR_ELT(r_result, 0, vector); + SET_VECTOR_ELT(r_result, 1, value); + SET_VECTOR_ELT(r_result, 2, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); SET_NAMES(r_result, r_names); - UNPROTECT(3); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_get_shortest_path_bellman_ford / +/ igraph_personalized_pagerank_vs / /-------------------------------------------*/ -SEXP R_igraph_get_shortest_path_bellman_ford(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { +SEXP R_igraph_personalized_pagerank_vs(SEXP graph, SEXP algo, SEXP vids, SEXP directed, SEXP damping, SEXP reset_vids, SEXP weights, SEXP options) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_vertices; - igraph_vector_int_t c_edges; - igraph_integer_t c_from; - igraph_integer_t c_to; + igraph_pagerank_algo_t c_algo; + igraph_vector_t c_vector; + igraph_real_t c_value; + igraph_vs_t c_vids; + igraph_bool_t c_directed; + igraph_real_t c_damping; + igraph_vs_t c_reset_vids; igraph_vector_t c_weights; - igraph_neimode_t c_mode; - SEXP vertices; - SEXP edges; + igraph_arpack_options_t c_options1; + void* c_options; + SEXP vector; + SEXP value; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); - c_from = (igraph_integer_t) REAL(from)[0]; - c_to = (igraph_integer_t) REAL(to)[0]; + c_algo = (igraph_pagerank_algo_t) Rf_asInteger(algo); + IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_REAL(damping); + c_damping = REAL(damping)[0]; + igraph_vector_int_t c_reset_vids_data; + Rz_SEXP_to_igraph_vs(reset_vids, &c_graph, &c_reset_vids, &c_reset_vids_data); if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + if (!Rf_isNull(options)) { + if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { + Rz_SEXP_to_igraph_arpack_options(options, &c_options1); + c_options = &c_options1; + } else { + c_options = NULL; + } + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_shortest_path_bellman_ford(&c_graph, &c_vertices, &c_edges, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + IGRAPH_R_CHECK(igraph_personalized_pagerank_vs(&c_graph, c_algo, &c_vector, &c_value, c_vids, c_directed, c_damping, c_reset_vids, (Rf_isNull(weights) ? 0 : &c_weights), c_options)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); - igraph_vector_int_destroy(&c_vertices); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); - igraph_vector_int_destroy(&c_edges); + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); + igraph_vector_destroy(&c_vector); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, vertices); - SET_VECTOR_ELT(r_result, 1, edges); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + PROTECT(value=NEW_NUMERIC(1)); + REAL(value)[0]=c_value; + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + igraph_vector_int_destroy(&c_reset_vids_data); + igraph_vs_destroy(&c_reset_vids); + if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { + PROTECT(options = Ry_igraph_arpack_options_to_SEXP(&c_options1)); + } else { + PROTECT(options); + } + SET_VECTOR_ELT(r_result, 0, vector); + SET_VECTOR_ELT(r_result, 1, value); + SET_VECTOR_ELT(r_result, 2, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); SET_NAMES(r_result, r_names); - UNPROTECT(3); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_get_shortest_path_dijkstra / +/ igraph_rewire / /-------------------------------------------*/ -SEXP R_igraph_get_shortest_path_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { +SEXP R_igraph_rewire(SEXP rewire, SEXP n, SEXP mode) { /* Declarations */ - igraph_t c_graph; - igraph_vector_int_t c_vertices; - igraph_vector_int_t c_edges; - igraph_integer_t c_from; - igraph_integer_t c_to; - igraph_vector_t c_weights; - igraph_neimode_t c_mode; - SEXP vertices; - SEXP edges; + igraph_t c_rewire; + igraph_integer_t c_n; + igraph_rewiring_t c_mode; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); - c_from = (igraph_integer_t) REAL(from)[0]; - c_to = (igraph_integer_t) REAL(to)[0]; - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + Rz_SEXP_to_igraph_copy(rewire, &c_rewire); + IGRAPH_FINALLY(igraph_destroy, &c_rewire); + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + c_mode = (igraph_rewiring_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_shortest_path_dijkstra(&c_graph, &c_vertices, &c_edges, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + IGRAPH_R_CHECK(igraph_rewire(&c_rewire, c_n, c_mode)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); - igraph_vector_int_destroy(&c_vertices); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); - igraph_vector_int_destroy(&c_edges); + PROTECT(rewire=Ry_igraph_to_SEXP(&c_rewire)); + IGRAPH_I_DESTROY(&c_rewire); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, vertices); - SET_VECTOR_ELT(r_result, 1, edges); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + r_result = rewire; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_get_all_shortest_paths / +/ igraph_induced_subgraph / /-------------------------------------------*/ -SEXP R_igraph_get_all_shortest_paths(SEXP graph, SEXP from, SEXP to, SEXP mode) { +SEXP R_igraph_induced_subgraph(SEXP graph, SEXP vids, SEXP impl) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_list_t c_vertices; - igraph_vector_int_list_t c_edges; - igraph_vector_int_t c_nrgeo; - igraph_integer_t c_from; - igraph_vs_t c_to; - igraph_neimode_t c_mode; - SEXP vertices; - SEXP edges; - SEXP nrgeo; + igraph_t c_res; + igraph_vs_t c_vids; + igraph_subgraph_implementation_t c_impl; + SEXP res; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_nrgeo, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_nrgeo); - c_from = (igraph_integer_t) REAL(from)[0]; - igraph_vector_int_t c_to_data; - Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_impl = (igraph_subgraph_implementation_t) Rf_asInteger(impl); /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_all_shortest_paths(&c_graph, &c_vertices, &c_edges, &c_nrgeo, c_from, c_to, c_mode)); + IGRAPH_R_CHECK(igraph_induced_subgraph(&c_graph, &c_res, c_vids, c_impl)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); - igraph_vector_int_list_destroy(&c_vertices); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); - igraph_vector_int_list_destroy(&c_edges); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(nrgeo=Ry_igraph_vector_int_to_SEXP(&c_nrgeo)); - igraph_vector_int_destroy(&c_nrgeo); + IGRAPH_FINALLY(igraph_destroy, &c_res); + PROTECT(res=Ry_igraph_to_SEXP(&c_res)); + IGRAPH_I_DESTROY(&c_res); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_to_data); - igraph_vs_destroy(&c_to); - SET_VECTOR_ELT(r_result, 0, vertices); - SET_VECTOR_ELT(r_result, 1, edges); - SET_VECTOR_ELT(r_result, 2, nrgeo); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vpaths")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("epaths")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("nrgeo")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_get_all_shortest_paths_dijkstra / +/ igraph_subgraph_from_edges / /-------------------------------------------*/ -SEXP R_igraph_get_all_shortest_paths_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { +SEXP R_igraph_subgraph_from_edges(SEXP graph, SEXP eids, SEXP delete_vertices) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_list_t c_vertices; - igraph_vector_int_list_t c_edges; - igraph_vector_int_t c_nrgeo; - igraph_integer_t c_from; - igraph_vs_t c_to; - igraph_vector_t c_weights; - igraph_neimode_t c_mode; - SEXP vertices; - SEXP edges; - SEXP nrgeo; + igraph_t c_res; + igraph_es_t c_eids; + igraph_bool_t c_delete_vertices; + SEXP res; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_nrgeo, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_nrgeo); - c_from = (igraph_integer_t) REAL(from)[0]; - igraph_vector_int_t c_to_data; - Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + igraph_vector_int_t c_eids_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(eids, &c_graph, &c_eids, &c_eids_data)); + IGRAPH_R_CHECK_BOOL(delete_vertices); + c_delete_vertices = LOGICAL(delete_vertices)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_all_shortest_paths_dijkstra(&c_graph, &c_vertices, &c_edges, &c_nrgeo, c_from, c_to, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + IGRAPH_R_CHECK(igraph_subgraph_from_edges(&c_graph, &c_res, c_eids, c_delete_vertices)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); - igraph_vector_int_list_destroy(&c_vertices); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); - igraph_vector_int_list_destroy(&c_edges); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(nrgeo=Ry_igraph_vector_int_to_SEXP(&c_nrgeo)); - igraph_vector_int_destroy(&c_nrgeo); + IGRAPH_FINALLY(igraph_destroy, &c_res); + PROTECT(res=Ry_igraph_to_SEXP(&c_res)); + IGRAPH_I_DESTROY(&c_res); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_to_data); - igraph_vs_destroy(&c_to); - SET_VECTOR_ELT(r_result, 0, vertices); - SET_VECTOR_ELT(r_result, 1, edges); - SET_VECTOR_ELT(r_result, 2, nrgeo); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vpaths")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("epaths")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("nrgeo")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + igraph_vector_int_destroy(&c_eids_data); + igraph_es_destroy(&c_eids); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_voronoi / +/ igraph_reverse_edges / /-------------------------------------------*/ -SEXP R_igraph_voronoi(SEXP graph, SEXP generators, SEXP weights, SEXP mode, SEXP tiebreaker) { +SEXP R_igraph_reverse_edges(SEXP graph, SEXP eids) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_membership; - igraph_vector_t c_distances; - igraph_vector_int_t c_generators; - igraph_vector_t c_weights; - igraph_neimode_t c_mode; - igraph_voronoi_tiebreaker_t c_tiebreaker; - SEXP membership; - SEXP distances; + igraph_es_t c_eids; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); - IGRAPH_R_CHECK(igraph_vector_init(&c_distances, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_distances); - Rz_SEXP_to_vector_int_copy(generators, &c_generators); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_generators); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - c_tiebreaker = (igraph_voronoi_tiebreaker_t) Rf_asInteger(tiebreaker); + Rz_SEXP_to_igraph_copy(graph, &c_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + igraph_vector_int_t c_eids_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(eids, &c_graph, &c_eids, &c_eids_data)); /* Call igraph */ - IGRAPH_R_CHECK(igraph_voronoi(&c_graph, &c_membership, &c_distances, &c_generators, (Rf_isNull(weights) ? 0 : &c_weights), c_mode, c_tiebreaker)); + IGRAPH_R_CHECK(igraph_reverse_edges(&c_graph, c_eids)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); - igraph_vector_int_destroy(&c_membership); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(distances=Ry_igraph_vector_to_SEXP(&c_distances)); - igraph_vector_destroy(&c_distances); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_generators); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, membership); - SET_VECTOR_ELT(r_result, 1, distances); - SET_STRING_ELT(r_names, 0, Rf_mkChar("membership")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("distances")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + igraph_vector_int_destroy(&c_eids_data); + igraph_es_destroy(&c_eids); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_get_all_simple_paths / +/ igraph_average_path_length / /-------------------------------------------*/ -SEXP R_igraph_get_all_simple_paths(SEXP graph, SEXP from, SEXP to, SEXP cutoff, SEXP mode) { +SEXP R_igraph_average_path_length(SEXP graph, SEXP directed, SEXP unconn) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_res; - igraph_integer_t c_from; - igraph_vs_t c_to; - igraph_integer_t c_cutoff; - igraph_neimode_t c_mode; + igraph_real_t c_res; + igraph_real_t c_unconn_pairs; + igraph_bool_t c_directed; + igraph_bool_t c_unconn; SEXP res; + SEXP unconn_pairs; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); - c_from = (igraph_integer_t) REAL(from)[0]; - igraph_vector_int_t c_to_data; - Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); - IGRAPH_R_CHECK_INT(cutoff); - c_cutoff = (igraph_integer_t) REAL(cutoff)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(unconn); + c_unconn = LOGICAL(unconn)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_all_simple_paths(&c_graph, &c_res, c_from, c_to, c_cutoff, c_mode)); + IGRAPH_R_CHECK(igraph_average_path_length(&c_graph, &c_res, &c_unconn_pairs, c_directed, c_unconn)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); - igraph_vector_int_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_to_data); - igraph_vs_destroy(&c_to); - r_result = res; + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + PROTECT(unconn_pairs=NEW_NUMERIC(1)); + REAL(unconn_pairs)[0]=c_unconn_pairs; + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, unconn_pairs); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("unconn_pairs")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_get_k_shortest_paths / +/ igraph_average_path_length_dijkstra / /-------------------------------------------*/ -SEXP R_igraph_get_k_shortest_paths(SEXP graph, SEXP weights, SEXP k, SEXP from, SEXP to, SEXP mode) { +SEXP R_igraph_average_path_length_dijkstra(SEXP graph, SEXP weights, SEXP directed, SEXP unconn) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_weights; - igraph_vector_int_list_t c_vertex_paths; - igraph_vector_int_list_t c_edge_paths; - igraph_integer_t c_k; - igraph_integer_t c_from; - igraph_integer_t c_to; - igraph_neimode_t c_mode; - SEXP vertex_paths; - SEXP edge_paths; + igraph_real_t c_res; + igraph_real_t c_unconn_pairs; + igraph_vector_t c_weights; + igraph_bool_t c_directed; + igraph_bool_t c_unconn; + SEXP res; + SEXP unconn_pairs; SEXP r_result, r_names; /* Convert input */ @@ -2855,31 +5567,24 @@ SEXP R_igraph_get_k_shortest_paths(SEXP graph, SEXP weights, SEXP k, SEXP from, if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertex_paths, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertex_paths); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edge_paths, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edge_paths); - IGRAPH_R_CHECK_INT(k); - c_k = (igraph_integer_t) REAL(k)[0]; - c_from = (igraph_integer_t) REAL(from)[0]; - c_to = (igraph_integer_t) REAL(to)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(unconn); + c_unconn = LOGICAL(unconn)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_k_shortest_paths(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_vertex_paths, &c_edge_paths, c_k, c_from, c_to, c_mode)); + IGRAPH_R_CHECK(igraph_average_path_length_dijkstra(&c_graph, &c_res, &c_unconn_pairs, (Rf_isNull(weights) ? 0 : &c_weights), c_directed, c_unconn)); /* Convert output */ PROTECT(r_result=NEW_LIST(2)); PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(vertex_paths=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertex_paths)); - igraph_vector_int_list_destroy(&c_vertex_paths); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edge_paths=Ry_igraph_vector_int_list_to_SEXPp1(&c_edge_paths)); - igraph_vector_int_list_destroy(&c_edge_paths); - IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, vertex_paths); - SET_VECTOR_ELT(r_result, 1, edge_paths); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vpaths")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("epaths")); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + PROTECT(unconn_pairs=NEW_NUMERIC(1)); + REAL(unconn_pairs)[0]=c_unconn_pairs; + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, unconn_pairs); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("unconnected")); SET_NAMES(r_result, r_names); UNPROTECT(3); @@ -2888,47 +5593,39 @@ SEXP R_igraph_get_k_shortest_paths(SEXP graph, SEXP weights, SEXP k, SEXP from, } /*-------------------------------------------/ -/ igraph_get_widest_path / +/ igraph_path_length_hist / /-------------------------------------------*/ -SEXP R_igraph_get_widest_path(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { +SEXP R_igraph_path_length_hist(SEXP graph, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_vertices; - igraph_vector_int_t c_edges; - igraph_integer_t c_from; - igraph_integer_t c_to; - igraph_vector_t c_weights; - igraph_neimode_t c_mode; - SEXP vertices; - SEXP edges; + igraph_vector_t c_res; + igraph_real_t c_unconnected; + igraph_bool_t c_directed; + SEXP res; + SEXP unconnected; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); - c_from = (igraph_integer_t) REAL(from)[0]; - c_to = (igraph_integer_t) REAL(to)[0]; - Rz_SEXP_to_vector(weights, &c_weights); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_widest_path(&c_graph, &c_vertices, &c_edges, c_from, c_to, &c_weights, c_mode)); + IGRAPH_R_CHECK(igraph_path_length_hist(&c_graph, &c_res, &c_unconnected, c_directed)); /* Convert output */ PROTECT(r_result=NEW_LIST(2)); PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); - igraph_vector_int_destroy(&c_vertices); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); - igraph_vector_int_destroy(&c_edges); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, vertices); - SET_VECTOR_ELT(r_result, 1, edges); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + PROTECT(unconnected=NEW_NUMERIC(1)); + REAL(unconnected)[0]=c_unconnected; + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, unconnected); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("unconnected")); SET_NAMES(r_result, r_names); UNPROTECT(3); @@ -2937,110 +5634,60 @@ SEXP R_igraph_get_widest_path(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP } /*-------------------------------------------/ -/ igraph_get_widest_paths / +/ igraph_simplify / /-------------------------------------------*/ -SEXP R_igraph_get_widest_paths(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { +SEXP R_igraph_simplify(SEXP graph, SEXP remove_multiple, SEXP remove_loops, SEXP edge_attr_comb) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_list_t c_vertices; - igraph_vector_int_list_t c_edges; - igraph_integer_t c_from; - igraph_vs_t c_to; - igraph_vector_t c_weights; - igraph_neimode_t c_mode; - igraph_vector_int_t c_parents; - igraph_vector_int_t c_inbound_edges; - SEXP vertices; - SEXP edges; - SEXP parents; - SEXP inbound_edges; + igraph_bool_t c_remove_multiple; + igraph_bool_t c_remove_loops; + igraph_attribute_combination_t c_edge_attr_comb; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_vertices, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_vertices); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_edges); - c_from = (igraph_integer_t) REAL(from)[0]; - igraph_vector_int_t c_to_data; - Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); - Rz_SEXP_to_vector(weights, &c_weights); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_parents, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_parents); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_inbound_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_inbound_edges); + Rz_SEXP_to_igraph_copy(graph, &c_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + IGRAPH_R_CHECK_BOOL(remove_multiple); + c_remove_multiple = LOGICAL(remove_multiple)[0]; + IGRAPH_R_CHECK_BOOL(remove_loops); + c_remove_loops = LOGICAL(remove_loops)[0]; + Rz_SEXP_to_attr_comb(edge_attr_comb, &c_edge_attr_comb); + IGRAPH_FINALLY(igraph_attribute_combination_destroy, &c_edge_attr_comb); /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_widest_paths(&c_graph, &c_vertices, &c_edges, c_from, c_to, &c_weights, c_mode, &c_parents, &c_inbound_edges)); + IGRAPH_R_CHECK(igraph_simplify(&c_graph, c_remove_multiple, c_remove_loops, &c_edge_attr_comb)); /* Convert output */ - PROTECT(r_result=NEW_LIST(4)); - PROTECT(r_names=NEW_CHARACTER(4)); - PROTECT(vertices=Ry_igraph_vector_int_list_to_SEXPp1(&c_vertices)); - igraph_vector_int_list_destroy(&c_vertices); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_edges)); - igraph_vector_int_list_destroy(&c_edges); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_to_data); - igraph_vs_destroy(&c_to); - PROTECT(parents=Ry_igraph_vector_int_to_SEXP(&c_parents)); - igraph_vector_int_destroy(&c_parents); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - PROTECT(inbound_edges=Ry_igraph_vector_int_to_SEXP(&c_inbound_edges)); - igraph_vector_int_destroy(&c_inbound_edges); + igraph_attribute_combination_destroy(&c_edge_attr_comb); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, vertices); - SET_VECTOR_ELT(r_result, 1, edges); - SET_VECTOR_ELT(r_result, 2, parents); - SET_VECTOR_ELT(r_result, 3, inbound_edges); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("parents")); - SET_STRING_ELT(r_names, 3, Rf_mkChar("inbound_edges")); - SET_NAMES(r_result, r_names); - UNPROTECT(5); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_widest_path_widths_dijkstra / +/ igraph_transitivity_undirected / /-------------------------------------------*/ -SEXP R_igraph_widest_path_widths_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { +SEXP R_igraph_transitivity_undirected(SEXP graph, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_matrix_t c_res; - igraph_vs_t c_from; - igraph_vs_t c_to; - igraph_vector_t c_weights; - igraph_neimode_t c_mode; + igraph_real_t c_res; + igraph_transitivity_mode_t c_mode; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - igraph_vector_int_t c_from_data; - Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); - igraph_vector_int_t c_to_data; - Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); - Rz_SEXP_to_vector(weights, &c_weights); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_mode = (igraph_transitivity_mode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_widest_path_widths_dijkstra(&c_graph, &c_res, c_from, c_to, &c_weights, c_mode)); + IGRAPH_R_CHECK(igraph_transitivity_undirected(&c_graph, &c_res, c_mode)); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_from_data); - igraph_vs_destroy(&c_from); - igraph_vector_int_destroy(&c_to_data); - igraph_vs_destroy(&c_to); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -3048,40 +5695,33 @@ SEXP R_igraph_widest_path_widths_dijkstra(SEXP graph, SEXP from, SEXP to, SEXP w } /*-------------------------------------------/ -/ igraph_widest_path_widths_floyd_warshall / +/ igraph_transitivity_local_undirected / /-------------------------------------------*/ -SEXP R_igraph_widest_path_widths_floyd_warshall(SEXP graph, SEXP from, SEXP to, SEXP weights, SEXP mode) { +SEXP R_igraph_transitivity_local_undirected(SEXP graph, SEXP vids, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_matrix_t c_res; - igraph_vs_t c_from; - igraph_vs_t c_to; - igraph_vector_t c_weights; - igraph_neimode_t c_mode; + igraph_vector_t c_res; + igraph_vs_t c_vids; + igraph_transitivity_mode_t c_mode; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - igraph_vector_int_t c_from_data; - Rz_SEXP_to_igraph_vs(from, &c_graph, &c_from, &c_from_data); - igraph_vector_int_t c_to_data; - Rz_SEXP_to_igraph_vs(to, &c_graph, &c_to, &c_to_data); - Rz_SEXP_to_vector(weights, &c_weights); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_transitivity_mode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_widest_path_widths_floyd_warshall(&c_graph, &c_res, c_from, c_to, &c_weights, c_mode)); + IGRAPH_R_CHECK(igraph_transitivity_local_undirected(&c_graph, &c_res, c_vids, c_mode)); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_from_data); - igraph_vs_destroy(&c_from); - igraph_vector_int_destroy(&c_to_data); - igraph_vs_destroy(&c_to); + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); r_result = res; UNPROTECT(1); @@ -3089,50 +5729,41 @@ SEXP R_igraph_widest_path_widths_floyd_warshall(SEXP graph, SEXP from, SEXP to, } /*-------------------------------------------/ -/ igraph_spanner / +/ igraph_transitivity_avglocal_undirected / /-------------------------------------------*/ -SEXP R_igraph_spanner(SEXP graph, SEXP stretch, SEXP weights) { +SEXP R_igraph_transitivity_avglocal_undirected(SEXP graph, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_spanner; - igraph_real_t c_stretch; - igraph_vector_t c_weights; - SEXP spanner; + igraph_real_t c_res; + igraph_transitivity_mode_t c_mode; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_spanner, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_spanner); - IGRAPH_R_CHECK_REAL(stretch); - c_stretch = REAL(stretch)[0]; - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + c_mode = (igraph_transitivity_mode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_spanner(&c_graph, &c_spanner, c_stretch, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_transitivity_avglocal_undirected(&c_graph, &c_res, c_mode)); /* Convert output */ - PROTECT(spanner=Ry_igraph_vector_int_to_SEXPp1(&c_spanner)); - igraph_vector_int_destroy(&c_spanner); - IGRAPH_FINALLY_CLEAN(1); - r_result = spanner; + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_betweenness_cutoff / +/ igraph_transitivity_barrat / /-------------------------------------------*/ -SEXP R_igraph_betweenness_cutoff(SEXP graph, SEXP vids, SEXP directed, SEXP weights, SEXP cutoff) { +SEXP R_igraph_transitivity_barrat(SEXP graph, SEXP vids, SEXP weights, SEXP mode) { /* Declarations */ igraph_t c_graph; igraph_vector_t c_res; igraph_vs_t c_vids; - igraph_bool_t c_directed; igraph_vector_t c_weights; - igraph_real_t c_cutoff; + igraph_transitivity_mode_t c_mode; SEXP res; SEXP r_result; @@ -3142,15 +5773,12 @@ SEXP R_igraph_betweenness_cutoff(SEXP graph, SEXP vids, SEXP directed, SEXP weig IGRAPH_FINALLY(igraph_vector_destroy, &c_res); igraph_vector_int_t c_vids_data; Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK_REAL(cutoff); - c_cutoff = REAL(cutoff)[0]; + c_mode = (igraph_transitivity_mode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_betweenness_cutoff(&c_graph, &c_res, c_vids, c_directed, (Rf_isNull(weights) ? 0 : &c_weights), c_cutoff)); + IGRAPH_R_CHECK(igraph_transitivity_barrat(&c_graph, &c_res, c_vids, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); /* Convert output */ PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); @@ -3165,17 +5793,16 @@ SEXP R_igraph_betweenness_cutoff(SEXP graph, SEXP vids, SEXP directed, SEXP weig } /*-------------------------------------------/ -/ igraph_betweenness_subset / +/ igraph_ecc / /-------------------------------------------*/ -SEXP R_igraph_betweenness_subset(SEXP graph, SEXP vids, SEXP directed, SEXP sources, SEXP targets, SEXP weights) { +SEXP R_igraph_ecc(SEXP graph, SEXP eids, SEXP k, SEXP offset, SEXP normalize) { /* Declarations */ igraph_t c_graph; igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_bool_t c_directed; - igraph_vs_t c_sources; - igraph_vs_t c_targets; - igraph_vector_t c_weights; + igraph_es_t c_eids; + igraph_integer_t c_k; + igraph_bool_t c_offset; + igraph_bool_t c_normalize; SEXP res; SEXP r_result; @@ -3183,30 +5810,23 @@ SEXP R_igraph_betweenness_subset(SEXP graph, SEXP vids, SEXP directed, SEXP sour Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - igraph_vector_int_t c_sources_data; - Rz_SEXP_to_igraph_vs(sources, &c_graph, &c_sources, &c_sources_data); - igraph_vector_int_t c_targets_data; - Rz_SEXP_to_igraph_vs(targets, &c_graph, &c_targets, &c_targets_data); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + igraph_vector_int_t c_eids_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(eids, &c_graph, &c_eids, &c_eids_data)); + IGRAPH_R_CHECK_INT(k); + c_k = (igraph_integer_t) REAL(k)[0]; + IGRAPH_R_CHECK_BOOL(offset); + c_offset = LOGICAL(offset)[0]; + IGRAPH_R_CHECK_BOOL(normalize); + c_normalize = LOGICAL(normalize)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_betweenness_subset(&c_graph, &c_res, c_vids, c_directed, c_sources, c_targets, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_ecc(&c_graph, &c_res, c_eids, c_k, c_offset, c_normalize)); /* Convert output */ PROTECT(res=Ry_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); - igraph_vector_int_destroy(&c_sources_data); - igraph_vs_destroy(&c_sources); - igraph_vector_int_destroy(&c_targets_data); - igraph_vs_destroy(&c_targets); + igraph_vector_int_destroy(&c_eids_data); + igraph_es_destroy(&c_eids); r_result = res; UNPROTECT(1); @@ -3214,33 +5834,28 @@ SEXP R_igraph_betweenness_subset(SEXP graph, SEXP vids, SEXP directed, SEXP sour } /*-------------------------------------------/ -/ igraph_edge_betweenness / +/ igraph_reciprocity / /-------------------------------------------*/ -SEXP R_igraph_edge_betweenness(SEXP graph, SEXP directed, SEXP weights) { +SEXP R_igraph_reciprocity(SEXP graph, SEXP ignore_loops, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_bool_t c_directed; - igraph_vector_t c_weights; + igraph_real_t c_res; + igraph_bool_t c_ignore_loops; + igraph_reciprocity_t c_mode; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + IGRAPH_R_CHECK_BOOL(ignore_loops); + c_ignore_loops = LOGICAL(ignore_loops)[0]; + c_mode = (igraph_reciprocity_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_edge_betweenness(&c_graph, &c_res, c_directed, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_reciprocity(&c_graph, &c_res, c_ignore_loops, c_mode)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -3248,15 +5863,14 @@ SEXP R_igraph_edge_betweenness(SEXP graph, SEXP directed, SEXP weights) { } /*-------------------------------------------/ -/ igraph_edge_betweenness_cutoff / +/ igraph_constraint / /-------------------------------------------*/ -SEXP R_igraph_edge_betweenness_cutoff(SEXP graph, SEXP directed, SEXP weights, SEXP cutoff) { +SEXP R_igraph_constraint(SEXP graph, SEXP vids, SEXP weights) { /* Declarations */ igraph_t c_graph; igraph_vector_t c_res; - igraph_bool_t c_directed; + igraph_vs_t c_vids; igraph_vector_t c_weights; - igraph_real_t c_cutoff; SEXP res; SEXP r_result; @@ -3264,20 +5878,20 @@ SEXP R_igraph_edge_betweenness_cutoff(SEXP graph, SEXP directed, SEXP weights, S Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK_REAL(cutoff); - c_cutoff = REAL(cutoff)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_edge_betweenness_cutoff(&c_graph, &c_res, c_directed, (Rf_isNull(weights) ? 0 : &c_weights), c_cutoff)); + IGRAPH_R_CHECK(igraph_constraint(&c_graph, &c_res, c_vids, (Rf_isNull(weights) ? 0 : &c_weights))); /* Convert output */ PROTECT(res=Ry_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); @@ -3285,48 +5899,34 @@ SEXP R_igraph_edge_betweenness_cutoff(SEXP graph, SEXP directed, SEXP weights, S } /*-------------------------------------------/ -/ igraph_edge_betweenness_subset / +/ igraph_maxdegree / /-------------------------------------------*/ -SEXP R_igraph_edge_betweenness_subset(SEXP graph, SEXP eids, SEXP directed, SEXP sources, SEXP targets, SEXP weights) { +SEXP R_igraph_maxdegree(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_es_t c_eids; - igraph_bool_t c_directed; - igraph_vs_t c_sources; - igraph_vs_t c_targets; - igraph_vector_t c_weights; + igraph_integer_t c_res; + igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_bool_t c_loops; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_eids_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(eids, &c_graph, &c_eids, &c_eids_data)); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - igraph_vector_int_t c_sources_data; - Rz_SEXP_to_igraph_vs(sources, &c_graph, &c_sources, &c_sources_data); - igraph_vector_int_t c_targets_data; - Rz_SEXP_to_igraph_vs(targets, &c_graph, &c_targets, &c_targets_data); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + c_res=0; + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_edge_betweenness_subset(&c_graph, &c_res, c_eids, c_directed, c_sources, c_targets, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_maxdegree(&c_graph, &c_res, c_vids, c_mode, c_loops)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_eids_data); - igraph_es_destroy(&c_eids); - igraph_vector_int_destroy(&c_sources_data); - igraph_vs_destroy(&c_sources); - igraph_vector_int_destroy(&c_targets_data); - igraph_vs_destroy(&c_targets); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=(double) c_res; + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); r_result = res; UNPROTECT(1); @@ -3334,43 +5934,26 @@ SEXP R_igraph_edge_betweenness_subset(SEXP graph, SEXP eids, SEXP directed, SEXP } /*-------------------------------------------/ -/ igraph_harmonic_centrality_cutoff / +/ igraph_density / /-------------------------------------------*/ -SEXP R_igraph_harmonic_centrality_cutoff(SEXP graph, SEXP vids, SEXP mode, SEXP weights, SEXP normalized, SEXP cutoff) { +SEXP R_igraph_density(SEXP graph, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - igraph_vector_t c_weights; - igraph_bool_t c_normalized; - igraph_real_t c_cutoff; + igraph_real_t c_res; + igraph_bool_t c_loops; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; - IGRAPH_R_CHECK_REAL(cutoff); - c_cutoff = REAL(cutoff)[0]; + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_harmonic_centrality_cutoff(&c_graph, &c_res, c_vids, c_mode, (Rf_isNull(weights) ? 0 : &c_weights), c_normalized, c_cutoff)); + IGRAPH_R_CHECK(igraph_density(&c_graph, &c_res, c_loops)); /* Convert output */ - PROTECT(res=Ry_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); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -3378,211 +5961,143 @@ SEXP R_igraph_harmonic_centrality_cutoff(SEXP graph, SEXP vids, SEXP mode, SEXP } /*-------------------------------------------/ -/ igraph_personalized_pagerank / +/ igraph_mean_degree / /-------------------------------------------*/ -SEXP R_igraph_personalized_pagerank(SEXP graph, SEXP algo, SEXP vids, SEXP directed, SEXP damping, SEXP personalized, SEXP weights, SEXP options) { +SEXP R_igraph_mean_degree(SEXP graph, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_pagerank_algo_t c_algo; - igraph_vector_t c_vector; - igraph_real_t c_value; - igraph_vs_t c_vids; - igraph_bool_t c_directed; - igraph_real_t c_damping; - igraph_vector_t c_personalized; - igraph_vector_t c_weights; - igraph_arpack_options_t c_options1; - void* c_options; - SEXP vector; - SEXP value; + igraph_real_t c_res; + igraph_bool_t c_loops; + SEXP res; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_algo = (igraph_pagerank_algo_t) Rf_asInteger(algo); - IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_REAL(damping); - c_damping = REAL(damping)[0]; - if (!Rf_isNull(personalized)) { - Rz_SEXP_to_vector(personalized, &c_personalized); - } - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - if (!Rf_isNull(options)) { - if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { - Rz_SEXP_to_igraph_arpack_options(options, &c_options1); - c_options = &c_options1; - } else { - c_options = NULL; - } - } + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_personalized_pagerank(&c_graph, c_algo, &c_vector, &c_value, c_vids, c_directed, c_damping, (Rf_isNull(personalized) ? 0 : &c_personalized), (Rf_isNull(weights) ? 0 : &c_weights), c_options)); + IGRAPH_R_CHECK(igraph_mean_degree(&c_graph, &c_res, c_loops)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); - igraph_vector_destroy(&c_vector); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(value=NEW_NUMERIC(1)); - REAL(value)[0]=c_value; - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { - PROTECT(options = Ry_igraph_arpack_options_to_SEXP(&c_options1)); - } else { - PROTECT(options); - } - SET_VECTOR_ELT(r_result, 0, vector); - SET_VECTOR_ELT(r_result, 1, value); - SET_VECTOR_ELT(r_result, 2, options); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_personalized_pagerank_vs / +/ igraph_neighborhood_size / /-------------------------------------------*/ -SEXP R_igraph_personalized_pagerank_vs(SEXP graph, SEXP algo, SEXP vids, SEXP directed, SEXP damping, SEXP reset_vids, SEXP weights, SEXP options) { +SEXP R_igraph_neighborhood_size(SEXP graph, SEXP vids, SEXP order, SEXP mode, SEXP mindist) { /* Declarations */ igraph_t c_graph; - igraph_pagerank_algo_t c_algo; - igraph_vector_t c_vector; - igraph_real_t c_value; + igraph_vector_int_t c_res; igraph_vs_t c_vids; - igraph_bool_t c_directed; - igraph_real_t c_damping; - igraph_vs_t c_reset_vids; - igraph_vector_t c_weights; - igraph_arpack_options_t c_options1; - void* c_options; - SEXP vector; - SEXP value; + igraph_integer_t c_order; + igraph_neimode_t c_mode; + igraph_integer_t c_mindist; + SEXP res; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_algo = (igraph_pagerank_algo_t) Rf_asInteger(algo); - IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); igraph_vector_int_t c_vids_data; Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_REAL(damping); - c_damping = REAL(damping)[0]; - igraph_vector_int_t c_reset_vids_data; - Rz_SEXP_to_igraph_vs(reset_vids, &c_graph, &c_reset_vids, &c_reset_vids_data); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - if (!Rf_isNull(options)) { - if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { - Rz_SEXP_to_igraph_arpack_options(options, &c_options1); - c_options = &c_options1; - } else { - c_options = NULL; - } - } + IGRAPH_R_CHECK_INT(order); + c_order = (igraph_integer_t) REAL(order)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_INT(mindist); + c_mindist = (igraph_integer_t) REAL(mindist)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_personalized_pagerank_vs(&c_graph, c_algo, &c_vector, &c_value, c_vids, c_directed, c_damping, c_reset_vids, (Rf_isNull(weights) ? 0 : &c_weights), c_options)); + IGRAPH_R_CHECK(igraph_neighborhood_size(&c_graph, &c_res, c_vids, c_order, c_mode, c_mindist)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); - igraph_vector_destroy(&c_vector); + PROTECT(res=Ry_igraph_vector_int_to_SEXP(&c_res)); + igraph_vector_int_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - PROTECT(value=NEW_NUMERIC(1)); - REAL(value)[0]=c_value; igraph_vector_int_destroy(&c_vids_data); igraph_vs_destroy(&c_vids); - igraph_vector_int_destroy(&c_reset_vids_data); - igraph_vs_destroy(&c_reset_vids); - if (c_algo == IGRAPH_PAGERANK_ALGO_ARPACK) { - PROTECT(options = Ry_igraph_arpack_options_to_SEXP(&c_options1)); - } else { - PROTECT(options); - } - SET_VECTOR_ELT(r_result, 0, vector); - SET_VECTOR_ELT(r_result, 1, value); - SET_VECTOR_ELT(r_result, 2, options); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_rewire / +/ igraph_neighborhood / /-------------------------------------------*/ -SEXP R_igraph_rewire(SEXP rewire, SEXP n, SEXP mode) { +SEXP R_igraph_neighborhood(SEXP graph, SEXP vids, SEXP order, SEXP mode, SEXP mindist) { /* Declarations */ - igraph_t c_rewire; - igraph_integer_t c_n; - igraph_rewiring_t c_mode; + igraph_t c_graph; + igraph_vector_int_list_t c_res; + igraph_vs_t c_vids; + igraph_integer_t c_order; + igraph_neimode_t c_mode; + igraph_integer_t c_mindist; + SEXP res; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph_copy(rewire, &c_rewire); - IGRAPH_FINALLY(igraph_destroy, &c_rewire); - IGRAPH_R_CHECK_INT(n); - c_n = (igraph_integer_t) REAL(n)[0]; - c_mode = (igraph_rewiring_t) Rf_asInteger(mode); + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + IGRAPH_R_CHECK_INT(order); + c_order = (igraph_integer_t) REAL(order)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_INT(mindist); + c_mindist = (igraph_integer_t) REAL(mindist)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_rewire(&c_rewire, c_n, c_mode)); + IGRAPH_R_CHECK(igraph_neighborhood(&c_graph, &c_res, c_vids, c_order, c_mode, c_mindist)); /* Convert output */ - PROTECT(rewire=Ry_igraph_to_SEXP(&c_rewire)); - IGRAPH_I_DESTROY(&c_rewire); + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - r_result = rewire; + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_induced_subgraph / +/ igraph_neighborhood_graphs / /-------------------------------------------*/ -SEXP R_igraph_induced_subgraph(SEXP graph, SEXP vids, SEXP impl) { +SEXP R_igraph_neighborhood_graphs(SEXP graph, SEXP vids, SEXP order, SEXP mode, SEXP mindist) { /* Declarations */ igraph_t c_graph; - igraph_t c_res; + igraph_graph_list_t c_res; igraph_vs_t c_vids; - igraph_subgraph_implementation_t c_impl; + igraph_integer_t c_order; + igraph_neimode_t c_mode; + igraph_integer_t c_mindist; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_graph_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_graph_list_destroy, &c_res); igraph_vector_int_t c_vids_data; Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_impl = (igraph_subgraph_implementation_t) Rf_asInteger(impl); + IGRAPH_R_CHECK_INT(order); + c_order = (igraph_integer_t) REAL(order)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_INT(mindist); + c_mindist = (igraph_integer_t) REAL(mindist)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_induced_subgraph(&c_graph, &c_res, c_vids, c_impl)); + IGRAPH_R_CHECK(igraph_neighborhood_graphs(&c_graph, &c_res, c_vids, c_order, c_mode, c_mindist)); /* Convert output */ - IGRAPH_FINALLY(igraph_destroy, &c_res); - PROTECT(res=Ry_igraph_to_SEXP(&c_res)); - IGRAPH_I_DESTROY(&c_res); + PROTECT(res=Ry_igraph_graphlist_to_SEXP(&c_res)); + IGRAPH_FREE(c_res.stor_begin); IGRAPH_FINALLY_CLEAN(1); igraph_vector_int_destroy(&c_vids_data); igraph_vs_destroy(&c_vids); @@ -3593,33 +6108,28 @@ SEXP R_igraph_induced_subgraph(SEXP graph, SEXP vids, SEXP impl) { } /*-------------------------------------------/ -/ igraph_subgraph_from_edges / +/ igraph_topological_sorting / /-------------------------------------------*/ -SEXP R_igraph_subgraph_from_edges(SEXP graph, SEXP eids, SEXP delete_vertices) { +SEXP R_igraph_topological_sorting(SEXP graph, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_t c_res; - igraph_es_t c_eids; - igraph_bool_t c_delete_vertices; + igraph_vector_int_t c_res; + igraph_neimode_t c_mode; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - igraph_vector_int_t c_eids_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(eids, &c_graph, &c_eids, &c_eids_data)); - IGRAPH_R_CHECK_BOOL(delete_vertices); - c_delete_vertices = LOGICAL(delete_vertices)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_subgraph_from_edges(&c_graph, &c_res, c_eids, c_delete_vertices)); + IGRAPH_R_CHECK(igraph_topological_sorting(&c_graph, &c_res, c_mode)); /* Convert output */ - IGRAPH_FINALLY(igraph_destroy, &c_res); - PROTECT(res=Ry_igraph_to_SEXP(&c_res)); - IGRAPH_I_DESTROY(&c_res); + PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); + igraph_vector_int_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_eids_data); - igraph_es_destroy(&c_eids); r_result = res; UNPROTECT(1); @@ -3627,175 +6137,201 @@ SEXP R_igraph_subgraph_from_edges(SEXP graph, SEXP eids, SEXP delete_vertices) { } /*-------------------------------------------/ -/ igraph_reverse_edges / +/ igraph_feedback_arc_set / /-------------------------------------------*/ -SEXP R_igraph_reverse_edges(SEXP graph, SEXP eids) { +SEXP R_igraph_feedback_arc_set(SEXP graph, SEXP weights, SEXP algo) { /* Declarations */ igraph_t c_graph; - igraph_es_t c_eids; + igraph_vector_int_t c_result; + igraph_vector_t c_weights; + igraph_fas_algorithm_t c_algo; + SEXP result; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph_copy(graph, &c_graph); - IGRAPH_FINALLY(igraph_destroy, &c_graph); - igraph_vector_int_t c_eids_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(eids, &c_graph, &c_eids, &c_eids_data)); + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_result, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_result); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_algo = (igraph_fas_algorithm_t) Rf_asInteger(algo); /* Call igraph */ - IGRAPH_R_CHECK(igraph_reverse_edges(&c_graph, c_eids)); + IGRAPH_R_CHECK(igraph_feedback_arc_set(&c_graph, &c_result, (Rf_isNull(weights) ? 0 : &c_weights), c_algo)); /* Convert output */ - PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); - IGRAPH_I_DESTROY(&c_graph); + PROTECT(result=Ry_igraph_vector_int_to_SEXPp1(&c_result)); + igraph_vector_int_destroy(&c_result); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_eids_data); - igraph_es_destroy(&c_eids); - r_result = graph; + r_result = result; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_average_path_length_dijkstra / +/ igraph_feedback_vertex_set / /-------------------------------------------*/ -SEXP R_igraph_average_path_length_dijkstra(SEXP graph, SEXP weights, SEXP directed, SEXP unconn) { +SEXP R_igraph_feedback_vertex_set(SEXP graph, SEXP weights, SEXP algo) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_res; - igraph_real_t c_unconn_pairs; + igraph_vector_int_t c_result; igraph_vector_t c_weights; - igraph_bool_t c_directed; - igraph_bool_t c_unconn; - SEXP res; - SEXP unconn_pairs; + igraph_fvs_algorithm_t c_algo; + SEXP result; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_result, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_result); if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(unconn); - c_unconn = LOGICAL(unconn)[0]; + c_algo = (igraph_fvs_algorithm_t) Rf_asInteger(algo); /* Call igraph */ - IGRAPH_R_CHECK(igraph_average_path_length_dijkstra(&c_graph, &c_res, &c_unconn_pairs, (Rf_isNull(weights) ? 0 : &c_weights), c_directed, c_unconn)); + IGRAPH_R_CHECK(igraph_feedback_vertex_set(&c_graph, &c_result, (Rf_isNull(weights) ? 0 : &c_weights), c_algo)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - PROTECT(unconn_pairs=NEW_NUMERIC(1)); - REAL(unconn_pairs)[0]=c_unconn_pairs; - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, unconn_pairs); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("unconnected")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + PROTECT(result=Ry_igraph_vector_int_to_SEXPp1(&c_result)); + igraph_vector_int_destroy(&c_result); + IGRAPH_FINALLY_CLEAN(1); + r_result = result; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_is_loop / +/-------------------------------------------*/ +SEXP R_igraph_is_loop(SEXP graph, SEXP es) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_bool_t c_res; + igraph_es_t c_es; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_bool_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_res); + igraph_vector_int_t c_es_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_is_loop(&c_graph, &c_res, c_es)); + + /* Convert output */ + PROTECT(res=Ry_igraph_vector_bool_to_SEXP(&c_res)); + igraph_vector_bool_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_es_data); + igraph_es_destroy(&c_es); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_is_dag / +/-------------------------------------------*/ +SEXP R_igraph_is_dag(SEXP graph) { + /* Declarations */ + igraph_t c_graph; + igraph_bool_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_is_dag(&c_graph, &c_res)); + + /* Convert output */ + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_path_length_hist / +/ igraph_is_acyclic / /-------------------------------------------*/ -SEXP R_igraph_path_length_hist(SEXP graph, SEXP directed) { +SEXP R_igraph_is_acyclic(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_real_t c_unconnected; - igraph_bool_t c_directed; + igraph_bool_t c_res; SEXP res; - SEXP unconnected; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_path_length_hist(&c_graph, &c_res, &c_unconnected, c_directed)); + IGRAPH_R_CHECK(igraph_is_acyclic(&c_graph, &c_res)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(unconnected=NEW_NUMERIC(1)); - REAL(unconnected)[0]=c_unconnected; - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, unconnected); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("unconnected")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_simplify / +/ igraph_is_simple / /-------------------------------------------*/ -SEXP R_igraph_simplify(SEXP graph, SEXP remove_multiple, SEXP remove_loops, SEXP edge_attr_comb) { +SEXP R_igraph_is_simple(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_remove_multiple; - igraph_bool_t c_remove_loops; - igraph_attribute_combination_t c_edge_attr_comb; + igraph_bool_t c_res; + SEXP res; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph_copy(graph, &c_graph); - IGRAPH_FINALLY(igraph_destroy, &c_graph); - IGRAPH_R_CHECK_BOOL(remove_multiple); - c_remove_multiple = LOGICAL(remove_multiple)[0]; - IGRAPH_R_CHECK_BOOL(remove_loops); - c_remove_loops = LOGICAL(remove_loops)[0]; - Rz_SEXP_to_attr_comb(edge_attr_comb, &c_edge_attr_comb); - IGRAPH_FINALLY(igraph_attribute_combination_destroy, &c_edge_attr_comb); + Rz_SEXP_to_igraph(graph, &c_graph); /* Call igraph */ - IGRAPH_R_CHECK(igraph_simplify(&c_graph, c_remove_multiple, c_remove_loops, &c_edge_attr_comb)); + IGRAPH_R_CHECK(igraph_is_simple(&c_graph, &c_res)); /* Convert output */ - PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); - IGRAPH_I_DESTROY(&c_graph); - IGRAPH_FINALLY_CLEAN(1); - igraph_attribute_combination_destroy(&c_edge_attr_comb); - IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_transitivity_undirected / +/ igraph_is_multiple / /-------------------------------------------*/ -SEXP R_igraph_transitivity_undirected(SEXP graph, SEXP mode) { +SEXP R_igraph_is_multiple(SEXP graph, SEXP es) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_res; - igraph_transitivity_mode_t c_mode; + igraph_vector_bool_t c_res; + igraph_es_t c_es; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_mode = (igraph_transitivity_mode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_bool_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_res); + igraph_vector_int_t c_es_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); /* Call igraph */ - IGRAPH_R_CHECK(igraph_transitivity_undirected(&c_graph, &c_res, c_mode)); + IGRAPH_R_CHECK(igraph_is_multiple(&c_graph, &c_res, c_es)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; + PROTECT(res=Ry_igraph_vector_bool_to_SEXP(&c_res)); + igraph_vector_bool_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_es_data); + igraph_es_destroy(&c_es); r_result = res; UNPROTECT(1); @@ -3803,33 +6339,23 @@ SEXP R_igraph_transitivity_undirected(SEXP graph, SEXP mode) { } /*-------------------------------------------/ -/ igraph_transitivity_local_undirected / +/ igraph_has_loop / /-------------------------------------------*/ -SEXP R_igraph_transitivity_local_undirected(SEXP graph, SEXP vids, SEXP mode) { +SEXP R_igraph_has_loop(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_transitivity_mode_t c_mode; + igraph_bool_t c_res; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_transitivity_mode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_transitivity_local_undirected(&c_graph, &c_res, c_vids, c_mode)); + IGRAPH_R_CHECK(igraph_has_loop(&c_graph, &c_res)); /* Convert output */ - PROTECT(res=Ry_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); + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -3837,25 +6363,23 @@ SEXP R_igraph_transitivity_local_undirected(SEXP graph, SEXP vids, SEXP mode) { } /*-------------------------------------------/ -/ igraph_transitivity_avglocal_undirected / +/ igraph_has_multiple / /-------------------------------------------*/ -SEXP R_igraph_transitivity_avglocal_undirected(SEXP graph, SEXP mode) { +SEXP R_igraph_has_multiple(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_res; - igraph_transitivity_mode_t c_mode; + igraph_bool_t c_res; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_mode = (igraph_transitivity_mode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_transitivity_avglocal_undirected(&c_graph, &c_res, c_mode)); + IGRAPH_R_CHECK(igraph_has_multiple(&c_graph, &c_res)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -3863,78 +6387,56 @@ SEXP R_igraph_transitivity_avglocal_undirected(SEXP graph, SEXP mode) { } /*-------------------------------------------/ -/ igraph_transitivity_barrat / +/ igraph_count_loops / /-------------------------------------------*/ -SEXP R_igraph_transitivity_barrat(SEXP graph, SEXP vids, SEXP weights, SEXP mode) { +SEXP R_igraph_count_loops(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_vector_t c_weights; - igraph_transitivity_mode_t c_mode; - SEXP res; + igraph_integer_t c_loop_count; + SEXP loop_count; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - c_mode = (igraph_transitivity_mode_t) Rf_asInteger(mode); + c_loop_count=0; /* Call igraph */ - IGRAPH_R_CHECK(igraph_transitivity_barrat(&c_graph, &c_res, c_vids, (Rf_isNull(weights) ? 0 : &c_weights), c_mode)); + IGRAPH_R_CHECK(igraph_count_loops(&c_graph, &c_loop_count)); /* Convert output */ - PROTECT(res=Ry_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; + PROTECT(loop_count=NEW_NUMERIC(1)); + REAL(loop_count)[0]=(double) c_loop_count; + r_result = loop_count; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_ecc / +/ igraph_count_multiple / /-------------------------------------------*/ -SEXP R_igraph_ecc(SEXP graph, SEXP eids, SEXP k, SEXP offset, SEXP normalize) { +SEXP R_igraph_count_multiple(SEXP graph, SEXP es) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_es_t c_eids; - igraph_integer_t c_k; - igraph_bool_t c_offset; - igraph_bool_t c_normalize; + igraph_vector_int_t c_res; + igraph_es_t c_es; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_eids_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(eids, &c_graph, &c_eids, &c_eids_data)); - IGRAPH_R_CHECK_INT(k); - c_k = (igraph_integer_t) REAL(k)[0]; - IGRAPH_R_CHECK_BOOL(offset); - c_offset = LOGICAL(offset)[0]; - IGRAPH_R_CHECK_BOOL(normalize); - c_normalize = LOGICAL(normalize)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + igraph_vector_int_t c_es_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); /* Call igraph */ - IGRAPH_R_CHECK(igraph_ecc(&c_graph, &c_res, c_eids, c_k, c_offset, c_normalize)); + IGRAPH_R_CHECK(igraph_count_multiple(&c_graph, &c_res, c_es)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + PROTECT(res=Ry_igraph_vector_int_to_SEXP(&c_res)); + igraph_vector_int_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_eids_data); - igraph_es_destroy(&c_eids); + igraph_vector_int_destroy(&c_es_data); + igraph_es_destroy(&c_es); r_result = res; UNPROTECT(1); @@ -3942,64 +6444,61 @@ SEXP R_igraph_ecc(SEXP graph, SEXP eids, SEXP k, SEXP offset, SEXP normalize) { } /*-------------------------------------------/ -/ igraph_reciprocity / +/ igraph_girth / /-------------------------------------------*/ -SEXP R_igraph_reciprocity(SEXP graph, SEXP ignore_loops, SEXP mode) { +SEXP R_igraph_girth(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_res; - igraph_bool_t c_ignore_loops; - igraph_reciprocity_t c_mode; - SEXP res; + igraph_real_t c_girth; + igraph_vector_int_t c_circle; + SEXP girth; + SEXP circle; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK_BOOL(ignore_loops); - c_ignore_loops = LOGICAL(ignore_loops)[0]; - c_mode = (igraph_reciprocity_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_circle, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_circle); /* Call igraph */ - IGRAPH_R_CHECK(igraph_reciprocity(&c_graph, &c_res, c_ignore_loops, c_mode)); + IGRAPH_R_CHECK(igraph_girth(&c_graph, &c_girth, &c_circle)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(girth=NEW_NUMERIC(1)); + REAL(girth)[0]=c_girth; + PROTECT(circle=Ry_igraph_vector_int_to_SEXPp1(&c_circle)); + igraph_vector_int_destroy(&c_circle); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, girth); + SET_VECTOR_ELT(r_result, 1, circle); + SET_STRING_ELT(r_names, 0, Rf_mkChar("girth")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("circle")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_constraint / +/ igraph_is_perfect / /-------------------------------------------*/ -SEXP R_igraph_constraint(SEXP graph, SEXP vids, SEXP weights) { +SEXP R_igraph_is_perfect(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_vector_t c_weights; + igraph_bool_t c_res; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } /* Call igraph */ - IGRAPH_R_CHECK(igraph_constraint(&c_graph, &c_res, c_vids, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_is_perfect(&c_graph, &c_res)); /* Convert output */ - PROTECT(res=Ry_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); + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -4007,197 +6506,303 @@ SEXP R_igraph_constraint(SEXP graph, SEXP vids, SEXP weights) { } /*-------------------------------------------/ -/ igraph_maxdegree / +/ igraph_add_edge / /-------------------------------------------*/ -SEXP R_igraph_maxdegree(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { +SEXP R_igraph_add_edge(SEXP graph, SEXP from, SEXP to) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_res; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - igraph_bool_t c_loops; - SEXP res; + igraph_integer_t c_from; + igraph_integer_t c_to; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - c_res=0; - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + Rz_SEXP_to_igraph_copy(graph, &c_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + IGRAPH_R_CHECK_INT(from); + c_from = (igraph_integer_t) REAL(from)[0]; + IGRAPH_R_CHECK_INT(to); + c_to = (igraph_integer_t) REAL(to)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_maxdegree(&c_graph, &c_res, c_vids, c_mode, c_loops)); + IGRAPH_R_CHECK(igraph_add_edge(&c_graph, c_from, c_to)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=(double) c_res; - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - r_result = res; + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_density / +/ igraph_eigenvector_centrality / /-------------------------------------------*/ -SEXP R_igraph_density(SEXP graph, SEXP loops) { +SEXP R_igraph_eigenvector_centrality(SEXP graph, SEXP directed, SEXP scale, SEXP weights, SEXP options) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_res; - igraph_bool_t c_loops; - SEXP res; + igraph_vector_t c_vector; + igraph_real_t c_value; + igraph_bool_t c_directed; + igraph_bool_t c_scale; + igraph_vector_t c_weights; + igraph_arpack_options_t c_options; + SEXP vector; + SEXP value; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(scale); + c_scale = LOGICAL(scale)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + Rz_SEXP_to_igraph_arpack_options(options, &c_options); /* Call igraph */ - IGRAPH_R_CHECK(igraph_density(&c_graph, &c_res, c_loops)); + IGRAPH_R_CHECK(igraph_eigenvector_centrality(&c_graph, &c_vector, &c_value, c_directed, c_scale, (Rf_isNull(weights) ? 0 : &c_weights), &c_options)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); + igraph_vector_destroy(&c_vector); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(value=NEW_NUMERIC(1)); + REAL(value)[0]=c_value; + PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); + SET_VECTOR_ELT(r_result, 0, vector); + SET_VECTOR_ELT(r_result, 1, value); + SET_VECTOR_ELT(r_result, 2, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_mean_degree / +/ igraph_hub_score / /-------------------------------------------*/ -SEXP R_igraph_mean_degree(SEXP graph, SEXP loops) { +SEXP R_igraph_hub_score(SEXP graph, SEXP scale, SEXP weights, SEXP options) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_res; - igraph_bool_t c_loops; - SEXP res; + igraph_vector_t c_vector; + igraph_real_t c_value; + igraph_bool_t c_scale; + igraph_vector_t c_weights; + igraph_arpack_options_t c_options; + SEXP vector; + SEXP value; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + IGRAPH_R_CHECK_BOOL(scale); + c_scale = LOGICAL(scale)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + Rz_SEXP_to_igraph_arpack_options(options, &c_options); /* Call igraph */ - IGRAPH_R_CHECK(igraph_mean_degree(&c_graph, &c_res, c_loops)); + IGRAPH_R_CHECK(igraph_hub_score(&c_graph, &c_vector, &c_value, c_scale, (Rf_isNull(weights) ? 0 : &c_weights), &c_options)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); + igraph_vector_destroy(&c_vector); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(value=NEW_NUMERIC(1)); + REAL(value)[0]=c_value; + PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); + SET_VECTOR_ELT(r_result, 0, vector); + SET_VECTOR_ELT(r_result, 1, value); + SET_VECTOR_ELT(r_result, 2, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_topological_sorting / +/ igraph_authority_score / /-------------------------------------------*/ -SEXP R_igraph_topological_sorting(SEXP graph, SEXP mode) { +SEXP R_igraph_authority_score(SEXP graph, SEXP scale, SEXP weights, SEXP options) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_res; - igraph_neimode_t c_mode; - SEXP res; + igraph_vector_t c_vector; + igraph_real_t c_value; + igraph_bool_t c_scale; + igraph_vector_t c_weights; + igraph_arpack_options_t c_options; + SEXP vector; + SEXP value; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + IGRAPH_R_CHECK_BOOL(scale); + c_scale = LOGICAL(scale)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + Rz_SEXP_to_igraph_arpack_options(options, &c_options); /* Call igraph */ - IGRAPH_R_CHECK(igraph_topological_sorting(&c_graph, &c_res, c_mode)); + IGRAPH_R_CHECK(igraph_authority_score(&c_graph, &c_vector, &c_value, c_scale, (Rf_isNull(weights) ? 0 : &c_weights), &c_options)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); - igraph_vector_int_destroy(&c_res); + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); + igraph_vector_destroy(&c_vector); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + PROTECT(value=NEW_NUMERIC(1)); + REAL(value)[0]=c_value; + PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); + SET_VECTOR_ELT(r_result, 0, vector); + SET_VECTOR_ELT(r_result, 1, value); + SET_VECTOR_ELT(r_result, 2, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_feedback_arc_set / +/ igraph_hub_and_authority_scores / /-------------------------------------------*/ -SEXP R_igraph_feedback_arc_set(SEXP graph, SEXP weights, SEXP algo) { +SEXP R_igraph_hub_and_authority_scores(SEXP graph, SEXP scale, SEXP weights, SEXP options) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_result; + igraph_vector_t c_hub; + igraph_vector_t c_authority; + igraph_real_t c_value; + igraph_bool_t c_scale; igraph_vector_t c_weights; - igraph_fas_algorithm_t c_algo; - SEXP result; + igraph_arpack_options_t c_options; + SEXP hub; + SEXP authority; + SEXP value; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_result, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_result); + IGRAPH_R_CHECK(igraph_vector_init(&c_hub, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_hub); + IGRAPH_R_CHECK(igraph_vector_init(&c_authority, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_authority); + IGRAPH_R_CHECK_BOOL(scale); + c_scale = LOGICAL(scale)[0]; if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - c_algo = (igraph_fas_algorithm_t) Rf_asInteger(algo); + Rz_SEXP_to_igraph_arpack_options(options, &c_options); /* Call igraph */ - IGRAPH_R_CHECK(igraph_feedback_arc_set(&c_graph, &c_result, (Rf_isNull(weights) ? 0 : &c_weights), c_algo)); + IGRAPH_R_CHECK(igraph_hub_and_authority_scores(&c_graph, &c_hub, &c_authority, &c_value, c_scale, (Rf_isNull(weights) ? 0 : &c_weights), &c_options)); /* Convert output */ - PROTECT(result=Ry_igraph_vector_int_to_SEXPp1(&c_result)); - igraph_vector_int_destroy(&c_result); + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(hub=Ry_igraph_vector_to_SEXP(&c_hub)); + igraph_vector_destroy(&c_hub); IGRAPH_FINALLY_CLEAN(1); - r_result = result; + PROTECT(authority=Ry_igraph_vector_to_SEXP(&c_authority)); + igraph_vector_destroy(&c_authority); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(value=NEW_NUMERIC(1)); + REAL(value)[0]=c_value; + PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); + SET_VECTOR_ELT(r_result, 0, hub); + SET_VECTOR_ELT(r_result, 1, authority); + SET_VECTOR_ELT(r_result, 2, value); + SET_VECTOR_ELT(r_result, 3, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("hub")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("authority")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("options")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_feedback_vertex_set / +/ igraph_unfold_tree / /-------------------------------------------*/ -SEXP R_igraph_feedback_vertex_set(SEXP graph, SEXP weights, SEXP algo) { +SEXP R_igraph_unfold_tree(SEXP graph, SEXP mode, SEXP roots) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_result; - igraph_vector_t c_weights; - igraph_fvs_algorithm_t c_algo; - SEXP result; + igraph_t c_tree; + igraph_neimode_t c_mode; + igraph_vector_int_t c_roots; + igraph_vector_int_t c_vertex_index; + SEXP tree; + SEXP vertex_index; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_result, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_result); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - c_algo = (igraph_fvs_algorithm_t) Rf_asInteger(algo); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(roots, &c_roots)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_roots); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_index, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_index); /* Call igraph */ - IGRAPH_R_CHECK(igraph_feedback_vertex_set(&c_graph, &c_result, (Rf_isNull(weights) ? 0 : &c_weights), c_algo)); + IGRAPH_R_CHECK(igraph_unfold_tree(&c_graph, &c_tree, c_mode, &c_roots, &c_vertex_index)); /* Convert output */ - PROTECT(result=Ry_igraph_vector_int_to_SEXPp1(&c_result)); - igraph_vector_int_destroy(&c_result); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + IGRAPH_FINALLY(igraph_destroy, &c_tree); + PROTECT(tree=Ry_igraph_to_SEXP(&c_tree)); + IGRAPH_I_DESTROY(&c_tree); IGRAPH_FINALLY_CLEAN(1); - r_result = result; + igraph_vector_int_destroy(&c_roots); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(vertex_index=Ry_igraph_vector_int_to_SEXPp1(&c_vertex_index)); + igraph_vector_int_destroy(&c_vertex_index); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, tree); + SET_VECTOR_ELT(r_result, 1, vertex_index); + SET_STRING_ELT(r_names, 0, Rf_mkChar("tree")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("vertex_index")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_loop / +/ igraph_is_mutual / /-------------------------------------------*/ -SEXP R_igraph_is_loop(SEXP graph, SEXP es) { +SEXP R_igraph_is_mutual(SEXP graph, SEXP es, SEXP loops) { /* Declarations */ igraph_t c_graph; igraph_vector_bool_t c_res; igraph_es_t c_es; + igraph_bool_t c_loops; SEXP res; SEXP r_result; @@ -4207,8 +6812,10 @@ SEXP R_igraph_is_loop(SEXP graph, SEXP es) { IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_res); igraph_vector_int_t c_es_data; IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_loop(&c_graph, &c_res, c_es)); + IGRAPH_R_CHECK(igraph_is_mutual(&c_graph, &c_res, c_es, c_loops)); /* Convert output */ PROTECT(res=Ry_igraph_vector_bool_to_SEXP(&c_res)); @@ -4223,19 +6830,22 @@ SEXP R_igraph_is_loop(SEXP graph, SEXP es) { } /*-------------------------------------------/ -/ igraph_is_dag / +/ igraph_has_mutual / /-------------------------------------------*/ -SEXP R_igraph_is_dag(SEXP graph) { +SEXP R_igraph_has_mutual(SEXP graph, SEXP loops) { /* Declarations */ igraph_t c_graph; igraph_bool_t c_res; + igraph_bool_t c_loops; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_dag(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_has_mutual(&c_graph, &c_res, c_loops)); /* Convert output */ PROTECT(res=NEW_LOGICAL(1)); @@ -4247,103 +6857,243 @@ SEXP R_igraph_is_dag(SEXP graph) { } /*-------------------------------------------/ -/ igraph_is_acyclic / +/ igraph_maximum_cardinality_search / /-------------------------------------------*/ -SEXP R_igraph_is_acyclic(SEXP graph) { +SEXP R_igraph_maximum_cardinality_search(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_res; - SEXP res; + igraph_vector_int_t c_alpha; + igraph_vector_int_t c_alpham1; + SEXP alpha; + SEXP alpham1; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_alpha, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_alpha); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_alpham1, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_alpham1); /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_acyclic(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_maximum_cardinality_search(&c_graph, &c_alpha, &c_alpham1)); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; - r_result = res; + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(alpha=Ry_igraph_vector_int_to_SEXPp1(&c_alpha)); + igraph_vector_int_destroy(&c_alpha); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(alpham1=Ry_igraph_vector_int_to_SEXPp1(&c_alpham1)); + igraph_vector_int_destroy(&c_alpham1); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, alpha); + SET_VECTOR_ELT(r_result, 1, alpham1); + SET_STRING_ELT(r_names, 0, Rf_mkChar("alpha")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("alpham1")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_simple / +/ igraph_is_chordal / /-------------------------------------------*/ -SEXP R_igraph_is_simple(SEXP graph) { +SEXP R_igraph_is_chordal(SEXP graph, SEXP alpha, SEXP alpham1) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_res; - SEXP res; + igraph_vector_int_t c_alpha; + igraph_vector_int_t c_alpham1; + igraph_bool_t c_chordal; + igraph_vector_int_t c_fillin; + igraph_t c_newgraph; + SEXP chordal; + SEXP fillin; + SEXP newgraph; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(alpha)) { + Rz_SEXP_to_vector_int_copy(alpha, &c_alpha); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_alpha); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_alpha, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_alpha); + } + if (!Rf_isNull(alpham1)) { + Rz_SEXP_to_vector_int_copy(alpham1, &c_alpham1); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_alpham1); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_alpham1, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_alpham1); + } + IGRAPH_R_CHECK(igraph_vector_int_init(&c_fillin, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_fillin); /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_simple(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_is_chordal(&c_graph, (Rf_isNull(alpha) ? 0 : &c_alpha), (Rf_isNull(alpham1) ? 0 : &c_alpham1), &c_chordal, &c_fillin, &c_newgraph)); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; - r_result = res; + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + igraph_vector_int_destroy(&c_alpha); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_alpham1); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(chordal=NEW_LOGICAL(1)); + LOGICAL(chordal)[0]=c_chordal; + PROTECT(fillin=Ry_igraph_vector_int_to_SEXP(&c_fillin)); + igraph_vector_int_destroy(&c_fillin); + IGRAPH_FINALLY_CLEAN(1); + IGRAPH_FINALLY(igraph_destroy, &c_newgraph); + PROTECT(newgraph=Ry_igraph_to_SEXP(&c_newgraph)); + IGRAPH_I_DESTROY(&c_newgraph); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, chordal); + SET_VECTOR_ELT(r_result, 1, fillin); + SET_VECTOR_ELT(r_result, 2, newgraph); + SET_STRING_ELT(r_names, 0, Rf_mkChar("chordal")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("fillin")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("newgraph")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_multiple / +/ igraph_avg_nearest_neighbor_degree / /-------------------------------------------*/ -SEXP R_igraph_is_multiple(SEXP graph, SEXP es) { +SEXP R_igraph_avg_nearest_neighbor_degree(SEXP graph, SEXP vids, SEXP mode, SEXP neighbor_degree_mode, SEXP weights) { /* Declarations */ igraph_t c_graph; - igraph_vector_bool_t c_res; - igraph_es_t c_es; - SEXP res; + igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_neimode_t c_neighbor_degree_mode; + igraph_vector_t c_knn; + igraph_vector_t c_knnk; + igraph_vector_t c_weights; + SEXP knn; + SEXP knnk; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_neighbor_degree_mode = (igraph_neimode_t) Rf_asInteger(neighbor_degree_mode); + IGRAPH_R_CHECK(igraph_vector_init(&c_knn, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_knn); + IGRAPH_R_CHECK(igraph_vector_init(&c_knnk, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_knnk); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_avg_nearest_neighbor_degree(&c_graph, c_vids, c_mode, c_neighbor_degree_mode, &c_knn, &c_knnk, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + PROTECT(knn=Ry_igraph_vector_to_SEXP(&c_knn)); + igraph_vector_destroy(&c_knn); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(knnk=Ry_igraph_vector_to_SEXP(&c_knnk)); + igraph_vector_destroy(&c_knnk); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, knn); + SET_VECTOR_ELT(r_result, 1, knnk); + SET_STRING_ELT(r_names, 0, Rf_mkChar("knn")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("knnk")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_degree_correlation_vector / +/-------------------------------------------*/ +SEXP R_igraph_degree_correlation_vector(SEXP graph, SEXP weights, SEXP from_mode, SEXP to_mode, SEXP directed_neighbors) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_weights; + igraph_vector_t c_knnk; + igraph_neimode_t c_from_mode; + igraph_neimode_t c_to_mode; + igraph_bool_t c_directed_neighbors; + SEXP knnk; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_bool_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_res); - igraph_vector_int_t c_es_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK(igraph_vector_init(&c_knnk, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_knnk); + c_from_mode = (igraph_neimode_t) Rf_asInteger(from_mode); + c_to_mode = (igraph_neimode_t) Rf_asInteger(to_mode); + IGRAPH_R_CHECK_BOOL(directed_neighbors); + c_directed_neighbors = LOGICAL(directed_neighbors)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_multiple(&c_graph, &c_res, c_es)); + IGRAPH_R_CHECK(igraph_degree_correlation_vector(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_knnk, c_from_mode, c_to_mode, c_directed_neighbors)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_bool_to_SEXP(&c_res)); - igraph_vector_bool_destroy(&c_res); + PROTECT(knnk=Ry_igraph_vector_to_SEXP(&c_knnk)); + igraph_vector_destroy(&c_knnk); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_es_data); - igraph_es_destroy(&c_es); - r_result = res; + r_result = knnk; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_has_loop / +/ igraph_rich_club_sequence / /-------------------------------------------*/ -SEXP R_igraph_has_loop(SEXP graph) { +SEXP R_igraph_rich_club_sequence(SEXP graph, SEXP weights, SEXP vertex_order, SEXP normalized, SEXP loops, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_res; + igraph_vector_t c_weights; + igraph_vector_t c_res; + igraph_vector_int_t c_vertex_order; + igraph_bool_t c_normalized; + igraph_bool_t c_loops; + igraph_bool_t c_directed; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + Rz_SEXP_to_vector_int_copy(vertex_order, &c_vertex_order); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_order); + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_has_loop(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_rich_club_sequence(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, &c_vertex_order, c_normalized, c_loops, c_directed)); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_vertex_order); + IGRAPH_FINALLY_CLEAN(1); r_result = res; UNPROTECT(1); @@ -4351,80 +7101,154 @@ SEXP R_igraph_has_loop(SEXP graph) { } /*-------------------------------------------/ -/ igraph_has_multiple / +/ igraph_strength / /-------------------------------------------*/ -SEXP R_igraph_has_multiple(SEXP graph) { +SEXP R_igraph_strength(SEXP graph, SEXP vids, SEXP mode, SEXP loops, SEXP weights) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_res; + igraph_vector_t c_res; + igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_bool_t c_loops; + igraph_vector_t c_weights; SEXP res; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_strength(&c_graph, &c_res, c_vids, c_mode, c_loops, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(res=Ry_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_centralization / +/-------------------------------------------*/ +SEXP R_igraph_centralization(SEXP scores, SEXP theoretical_max, SEXP normalized) { + /* Declarations */ + igraph_vector_t c_scores; + igraph_real_t c_theoretical_max; + igraph_bool_t c_normalized; + igraph_real_t c_result; + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_vector(scores, &c_scores); + IGRAPH_R_CHECK_REAL(theoretical_max); + c_theoretical_max = REAL(theoretical_max)[0]; + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_has_multiple(&c_graph, &c_res)); + c_result=igraph_centralization(&c_scores, c_theoretical_max, c_normalized); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; - r_result = res; + + PROTECT(r_result=NEW_NUMERIC(1)); + REAL(r_result)[0]=c_result; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_count_loops / +/ igraph_centralization_degree / /-------------------------------------------*/ -SEXP R_igraph_count_loops(SEXP graph) { +SEXP R_igraph_centralization_degree(SEXP graph, SEXP mode, SEXP loops, SEXP normalized) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_loop_count; - SEXP loop_count; + igraph_vector_t c_res; + igraph_neimode_t c_mode; + igraph_bool_t c_loops; + igraph_real_t c_centralization; + igraph_real_t c_theoretical_max; + igraph_bool_t c_normalized; + SEXP res; + SEXP centralization; + SEXP theoretical_max; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_loop_count=0; + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_count_loops(&c_graph, &c_loop_count)); + IGRAPH_R_CHECK(igraph_centralization_degree(&c_graph, &c_res, c_mode, c_loops, &c_centralization, &c_theoretical_max, c_normalized)); /* Convert output */ - PROTECT(loop_count=NEW_NUMERIC(1)); - REAL(loop_count)[0]=(double) c_loop_count; - r_result = loop_count; + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(centralization=NEW_NUMERIC(1)); + REAL(centralization)[0]=c_centralization; + PROTECT(theoretical_max=NEW_NUMERIC(1)); + REAL(theoretical_max)[0]=c_theoretical_max; + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, centralization); + SET_VECTOR_ELT(r_result, 2, theoretical_max); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("centralization")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("theoretical_max")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_count_multiple / +/ igraph_centralization_degree_tmax / /-------------------------------------------*/ -SEXP R_igraph_count_multiple(SEXP graph, SEXP es) { +SEXP R_igraph_centralization_degree_tmax(SEXP graph, SEXP nodes, SEXP mode, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_res; - igraph_es_t c_es; + igraph_integer_t c_nodes; + igraph_neimode_t c_mode; + igraph_bool_t c_loops; + igraph_real_t c_res; SEXP res; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); - igraph_vector_int_t c_es_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); + if (!Rf_isNull(graph)) { + Rz_SEXP_to_igraph(graph, &c_graph); + } + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_count_multiple(&c_graph, &c_res, c_es)); + IGRAPH_R_CHECK(igraph_centralization_degree_tmax((Rf_isNull(graph) ? 0 : &c_graph), c_nodes, c_mode, c_loops, &c_res)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_to_SEXP(&c_res)); - igraph_vector_int_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_es_data); - igraph_es_destroy(&c_es); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -4432,61 +7256,81 @@ SEXP R_igraph_count_multiple(SEXP graph, SEXP es) { } /*-------------------------------------------/ -/ igraph_girth / +/ igraph_centralization_betweenness / /-------------------------------------------*/ -SEXP R_igraph_girth(SEXP graph) { +SEXP R_igraph_centralization_betweenness(SEXP graph, SEXP directed, SEXP normalized) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_girth; - igraph_vector_int_t c_circle; - SEXP girth; - SEXP circle; + igraph_vector_t c_res; + igraph_bool_t c_directed; + igraph_real_t c_centralization; + igraph_real_t c_theoretical_max; + igraph_bool_t c_normalized; + SEXP res; + SEXP centralization; + SEXP theoretical_max; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_circle, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_circle); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_girth(&c_graph, &c_girth, &c_circle)); + IGRAPH_R_CHECK(igraph_centralization_betweenness(&c_graph, &c_res, c_directed, &c_centralization, &c_theoretical_max, c_normalized)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(girth=NEW_NUMERIC(1)); - REAL(girth)[0]=c_girth; - PROTECT(circle=Ry_igraph_vector_int_to_SEXPp1(&c_circle)); - igraph_vector_int_destroy(&c_circle); + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, girth); - SET_VECTOR_ELT(r_result, 1, circle); - SET_STRING_ELT(r_names, 0, Rf_mkChar("girth")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("circle")); + PROTECT(centralization=NEW_NUMERIC(1)); + REAL(centralization)[0]=c_centralization; + PROTECT(theoretical_max=NEW_NUMERIC(1)); + REAL(theoretical_max)[0]=c_theoretical_max; + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, centralization); + SET_VECTOR_ELT(r_result, 2, theoretical_max); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("centralization")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("theoretical_max")); SET_NAMES(r_result, r_names); - UNPROTECT(3); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_perfect / +/ igraph_centralization_betweenness_tmax / /-------------------------------------------*/ -SEXP R_igraph_is_perfect(SEXP graph) { +SEXP R_igraph_centralization_betweenness_tmax(SEXP graph, SEXP nodes, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_res; + igraph_integer_t c_nodes; + igraph_bool_t c_directed; + igraph_real_t c_res; SEXP res; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(graph)) { + Rz_SEXP_to_igraph(graph, &c_graph); + } + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_perfect(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_centralization_betweenness_tmax((Rf_isNull(graph) ? 0 : &c_graph), c_nodes, c_directed, &c_res)); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -4494,51 +7338,47 @@ SEXP R_igraph_is_perfect(SEXP graph) { } /*-------------------------------------------/ -/ igraph_eigenvector_centrality / +/ igraph_centralization_closeness / /-------------------------------------------*/ -SEXP R_igraph_eigenvector_centrality(SEXP graph, SEXP directed, SEXP scale, SEXP weights, SEXP options) { +SEXP R_igraph_centralization_closeness(SEXP graph, SEXP mode, SEXP normalized) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_vector; - igraph_real_t c_value; - igraph_bool_t c_directed; - igraph_bool_t c_scale; - igraph_vector_t c_weights; - igraph_arpack_options_t c_options; - SEXP vector; - SEXP value; + igraph_vector_t c_res; + igraph_neimode_t c_mode; + igraph_real_t c_centralization; + igraph_real_t c_theoretical_max; + igraph_bool_t c_normalized; + SEXP res; + SEXP centralization; + SEXP theoretical_max; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(scale); - c_scale = LOGICAL(scale)[0]; - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - Rz_SEXP_to_igraph_arpack_options(options, &c_options); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_eigenvector_centrality(&c_graph, &c_vector, &c_value, c_directed, c_scale, (Rf_isNull(weights) ? 0 : &c_weights), &c_options)); + IGRAPH_R_CHECK(igraph_centralization_closeness(&c_graph, &c_res, c_mode, &c_centralization, &c_theoretical_max, c_normalized)); /* Convert output */ PROTECT(r_result=NEW_LIST(3)); PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); - igraph_vector_destroy(&c_vector); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - PROTECT(value=NEW_NUMERIC(1)); - REAL(value)[0]=c_value; - PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); - SET_VECTOR_ELT(r_result, 0, vector); - SET_VECTOR_ELT(r_result, 1, value); - SET_VECTOR_ELT(r_result, 2, options); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); + PROTECT(centralization=NEW_NUMERIC(1)); + REAL(centralization)[0]=c_centralization; + PROTECT(theoretical_max=NEW_NUMERIC(1)); + REAL(theoretical_max)[0]=c_theoretical_max; + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, centralization); + SET_VECTOR_ELT(r_result, 2, theoretical_max); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("centralization")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("theoretical_max")); SET_NAMES(r_result, r_names); UNPROTECT(4); @@ -4547,140 +7387,164 @@ SEXP R_igraph_eigenvector_centrality(SEXP graph, SEXP directed, SEXP scale, SEXP } /*-------------------------------------------/ -/ igraph_hub_and_authority_scores / +/ igraph_centralization_closeness_tmax / +/-------------------------------------------*/ +SEXP R_igraph_centralization_closeness_tmax(SEXP graph, SEXP nodes, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_nodes; + igraph_neimode_t c_mode; + igraph_real_t c_res; + SEXP res; + + SEXP r_result; + /* Convert input */ + if (!Rf_isNull(graph)) { + Rz_SEXP_to_igraph(graph, &c_graph); + } + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_centralization_closeness_tmax((Rf_isNull(graph) ? 0 : &c_graph), c_nodes, c_mode, &c_res)); + + /* Convert output */ + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_centralization_eigenvector_centrality / /-------------------------------------------*/ -SEXP R_igraph_hub_and_authority_scores(SEXP graph, SEXP scale, SEXP weights, SEXP options) { +SEXP R_igraph_centralization_eigenvector_centrality(SEXP graph, SEXP directed, SEXP scale, SEXP options, SEXP normalized) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_hub; - igraph_vector_t c_authority; + igraph_vector_t c_vector; igraph_real_t c_value; + igraph_bool_t c_directed; igraph_bool_t c_scale; - igraph_vector_t c_weights; igraph_arpack_options_t c_options; - SEXP hub; - SEXP authority; + igraph_real_t c_centralization; + igraph_real_t c_theoretical_max; + igraph_bool_t c_normalized; + SEXP vector; SEXP value; + SEXP centralization; + SEXP theoretical_max; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_hub, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_hub); - IGRAPH_R_CHECK(igraph_vector_init(&c_authority, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_authority); + IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; IGRAPH_R_CHECK_BOOL(scale); c_scale = LOGICAL(scale)[0]; - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } Rz_SEXP_to_igraph_arpack_options(options, &c_options); + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_hub_and_authority_scores(&c_graph, &c_hub, &c_authority, &c_value, c_scale, (Rf_isNull(weights) ? 0 : &c_weights), &c_options)); + IGRAPH_R_CHECK(igraph_centralization_eigenvector_centrality(&c_graph, &c_vector, &c_value, c_directed, c_scale, &c_options, &c_centralization, &c_theoretical_max, c_normalized)); /* Convert output */ - PROTECT(r_result=NEW_LIST(4)); - PROTECT(r_names=NEW_CHARACTER(4)); - PROTECT(hub=Ry_igraph_vector_to_SEXP(&c_hub)); - igraph_vector_destroy(&c_hub); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(authority=Ry_igraph_vector_to_SEXP(&c_authority)); - igraph_vector_destroy(&c_authority); + PROTECT(r_result=NEW_LIST(5)); + PROTECT(r_names=NEW_CHARACTER(5)); + PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); + igraph_vector_destroy(&c_vector); IGRAPH_FINALLY_CLEAN(1); PROTECT(value=NEW_NUMERIC(1)); REAL(value)[0]=c_value; PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); - SET_VECTOR_ELT(r_result, 0, hub); - SET_VECTOR_ELT(r_result, 1, authority); - SET_VECTOR_ELT(r_result, 2, value); - SET_VECTOR_ELT(r_result, 3, options); - SET_STRING_ELT(r_names, 0, Rf_mkChar("hub")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("authority")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("value")); - SET_STRING_ELT(r_names, 3, Rf_mkChar("options")); + PROTECT(centralization=NEW_NUMERIC(1)); + REAL(centralization)[0]=c_centralization; + PROTECT(theoretical_max=NEW_NUMERIC(1)); + REAL(theoretical_max)[0]=c_theoretical_max; + SET_VECTOR_ELT(r_result, 0, vector); + SET_VECTOR_ELT(r_result, 1, value); + SET_VECTOR_ELT(r_result, 2, options); + SET_VECTOR_ELT(r_result, 3, centralization); + SET_VECTOR_ELT(r_result, 4, theoretical_max); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("centralization")); + SET_STRING_ELT(r_names, 4, Rf_mkChar("theoretical_max")); SET_NAMES(r_result, r_names); - UNPROTECT(5); + UNPROTECT(6); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_unfold_tree / +/ igraph_centralization_eigenvector_centrality_tmax / /-------------------------------------------*/ -SEXP R_igraph_unfold_tree(SEXP graph, SEXP mode, SEXP roots) { +SEXP R_igraph_centralization_eigenvector_centrality_tmax(SEXP graph, SEXP nodes, SEXP directed, SEXP scale) { /* Declarations */ igraph_t c_graph; - igraph_t c_tree; - igraph_neimode_t c_mode; - igraph_vector_int_t c_roots; - igraph_vector_int_t c_vertex_index; - SEXP tree; - SEXP vertex_index; + igraph_integer_t c_nodes; + igraph_bool_t c_directed; + igraph_bool_t c_scale; + igraph_real_t c_res; + SEXP res; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(roots, &c_roots)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_roots); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_index, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_index); + if (!Rf_isNull(graph)) { + Rz_SEXP_to_igraph(graph, &c_graph); + } + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(scale); + c_scale = LOGICAL(scale)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_unfold_tree(&c_graph, &c_tree, c_mode, &c_roots, &c_vertex_index)); + IGRAPH_R_CHECK(igraph_centralization_eigenvector_centrality_tmax((Rf_isNull(graph) ? 0 : &c_graph), c_nodes, c_directed, c_scale, &c_res)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - IGRAPH_FINALLY(igraph_destroy, &c_tree); - PROTECT(tree=Ry_igraph_to_SEXP(&c_tree)); - IGRAPH_I_DESTROY(&c_tree); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_roots); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(vertex_index=Ry_igraph_vector_int_to_SEXPp1(&c_vertex_index)); - igraph_vector_int_destroy(&c_vertex_index); - IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, tree); - SET_VECTOR_ELT(r_result, 1, vertex_index); - SET_STRING_ELT(r_names, 0, Rf_mkChar("tree")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("vertex_index")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_mutual / +/ igraph_assortativity_nominal / /-------------------------------------------*/ -SEXP R_igraph_is_mutual(SEXP graph, SEXP es, SEXP loops) { +SEXP R_igraph_assortativity_nominal(SEXP graph, SEXP types, SEXP directed, SEXP normalized) { /* Declarations */ igraph_t c_graph; - igraph_vector_bool_t c_res; - igraph_es_t c_es; - igraph_bool_t c_loops; + igraph_vector_int_t c_types; + igraph_real_t c_res; + igraph_bool_t c_directed; + igraph_bool_t c_normalized; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_bool_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_res); - igraph_vector_int_t c_es_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + Rz_SEXP_to_vector_int_copy(types, &c_types); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_types); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_mutual(&c_graph, &c_res, c_es, c_loops)); + IGRAPH_R_CHECK(igraph_assortativity_nominal(&c_graph, &c_types, &c_res, c_directed, c_normalized)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_bool_to_SEXP(&c_res)); - igraph_vector_bool_destroy(&c_res); + igraph_vector_int_destroy(&c_types); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_es_data); - igraph_es_destroy(&c_es); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -4688,26 +7552,35 @@ SEXP R_igraph_is_mutual(SEXP graph, SEXP es, SEXP loops) { } /*-------------------------------------------/ -/ igraph_has_mutual / +/ igraph_assortativity / /-------------------------------------------*/ -SEXP R_igraph_has_mutual(SEXP graph, SEXP loops) { +SEXP R_igraph_assortativity(SEXP graph, SEXP values, SEXP values_in, SEXP directed, SEXP normalized) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_res; - igraph_bool_t c_loops; + igraph_vector_t c_values; + igraph_vector_t c_values_in; + igraph_real_t c_res; + igraph_bool_t c_directed; + igraph_bool_t c_normalized; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + Rz_SEXP_to_vector(values, &c_values); + if (!Rf_isNull(values_in)) { + Rz_SEXP_to_vector(values_in, &c_values_in); + } + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_has_mutual(&c_graph, &c_res, c_loops)); + IGRAPH_R_CHECK(igraph_assortativity(&c_graph, &c_values, (Rf_isNull(values_in) ? 0 : &c_values_in), &c_res, c_directed, c_normalized)); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -4715,112 +7588,43 @@ SEXP R_igraph_has_mutual(SEXP graph, SEXP loops) { } /*-------------------------------------------/ -/ igraph_maximum_cardinality_search / -/-------------------------------------------*/ -SEXP R_igraph_maximum_cardinality_search(SEXP graph) { - /* Declarations */ - igraph_t c_graph; - igraph_vector_int_t c_alpha; - igraph_vector_int_t c_alpham1; - SEXP alpha; - SEXP alpham1; - - SEXP r_result, r_names; - /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_alpha, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_alpha); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_alpham1, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_alpham1); - /* Call igraph */ - IGRAPH_R_CHECK(igraph_maximum_cardinality_search(&c_graph, &c_alpha, &c_alpham1)); - - /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(alpha=Ry_igraph_vector_int_to_SEXPp1(&c_alpha)); - igraph_vector_int_destroy(&c_alpha); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(alpham1=Ry_igraph_vector_int_to_SEXPp1(&c_alpham1)); - igraph_vector_int_destroy(&c_alpham1); - IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, alpha); - SET_VECTOR_ELT(r_result, 1, alpham1); - SET_STRING_ELT(r_names, 0, Rf_mkChar("alpha")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("alpham1")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); - - UNPROTECT(1); - return(r_result); -} - -/*-------------------------------------------/ -/ igraph_avg_nearest_neighbor_degree / +/ igraph_assortativity_degree / /-------------------------------------------*/ -SEXP R_igraph_avg_nearest_neighbor_degree(SEXP graph, SEXP vids, SEXP mode, SEXP neighbor_degree_mode, SEXP weights) { +SEXP R_igraph_assortativity_degree(SEXP graph, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - igraph_neimode_t c_neighbor_degree_mode; - igraph_vector_t c_knn; - igraph_vector_t c_knnk; - igraph_vector_t c_weights; - SEXP knn; - SEXP knnk; - - SEXP r_result, r_names; - /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - c_neighbor_degree_mode = (igraph_neimode_t) Rf_asInteger(neighbor_degree_mode); - IGRAPH_R_CHECK(igraph_vector_init(&c_knn, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_knn); - IGRAPH_R_CHECK(igraph_vector_init(&c_knnk, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_knnk); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + igraph_real_t c_res; + igraph_bool_t c_directed; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_avg_nearest_neighbor_degree(&c_graph, c_vids, c_mode, c_neighbor_degree_mode, &c_knn, &c_knnk, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_assortativity_degree(&c_graph, &c_res, c_directed)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - PROTECT(knn=Ry_igraph_vector_to_SEXP(&c_knn)); - igraph_vector_destroy(&c_knn); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(knnk=Ry_igraph_vector_to_SEXP(&c_knnk)); - igraph_vector_destroy(&c_knnk); - IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, knn); - SET_VECTOR_ELT(r_result, 1, knnk); - SET_STRING_ELT(r_names, 0, Rf_mkChar("knn")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("knnk")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_degree_correlation_vector / +/ igraph_joint_degree_matrix / /-------------------------------------------*/ -SEXP R_igraph_degree_correlation_vector(SEXP graph, SEXP weights, SEXP from_mode, SEXP to_mode, SEXP directed_neighbors) { +SEXP R_igraph_joint_degree_matrix(SEXP graph, SEXP weights, SEXP max_out_degree, SEXP max_in_degree) { /* Declarations */ igraph_t c_graph; igraph_vector_t c_weights; - igraph_vector_t c_knnk; - igraph_neimode_t c_from_mode; - igraph_neimode_t c_to_mode; - igraph_bool_t c_directed_neighbors; - SEXP knnk; + igraph_matrix_t c_jdm; + igraph_integer_t c_max_out_degree; + igraph_integer_t c_max_in_degree; + SEXP jdm; SEXP r_result; /* Convert input */ @@ -4828,38 +7632,40 @@ SEXP R_igraph_degree_correlation_vector(SEXP graph, SEXP weights, SEXP from_mode if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK(igraph_vector_init(&c_knnk, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_knnk); - c_from_mode = (igraph_neimode_t) Rf_asInteger(from_mode); - c_to_mode = (igraph_neimode_t) Rf_asInteger(to_mode); - IGRAPH_R_CHECK_BOOL(directed_neighbors); - c_directed_neighbors = LOGICAL(directed_neighbors)[0]; + IGRAPH_R_CHECK(igraph_matrix_init(&c_jdm, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_jdm); + IGRAPH_R_CHECK_INT(max_out_degree); + c_max_out_degree = (igraph_integer_t) REAL(max_out_degree)[0]; + IGRAPH_R_CHECK_INT(max_in_degree); + c_max_in_degree = (igraph_integer_t) REAL(max_in_degree)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_degree_correlation_vector(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_knnk, c_from_mode, c_to_mode, c_directed_neighbors)); + IGRAPH_R_CHECK(igraph_joint_degree_matrix(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_jdm, c_max_out_degree, c_max_in_degree)); /* Convert output */ - PROTECT(knnk=Ry_igraph_vector_to_SEXP(&c_knnk)); - igraph_vector_destroy(&c_knnk); + PROTECT(jdm=Ry_igraph_matrix_to_SEXP(&c_jdm)); + igraph_matrix_destroy(&c_jdm); IGRAPH_FINALLY_CLEAN(1); - r_result = knnk; + r_result = jdm; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_rich_club_sequence / +/ igraph_joint_degree_distribution / /-------------------------------------------*/ -SEXP R_igraph_rich_club_sequence(SEXP graph, SEXP weights, SEXP vertex_order, SEXP normalized, SEXP loops, SEXP directed) { +SEXP R_igraph_joint_degree_distribution(SEXP graph, SEXP weights, SEXP from_mode, SEXP to_mode, SEXP directed_neighbors, SEXP normalized, SEXP max_from_degree, SEXP max_to_degree) { /* Declarations */ igraph_t c_graph; igraph_vector_t c_weights; - igraph_vector_t c_res; - igraph_vector_int_t c_vertex_order; + igraph_matrix_t c_p; + igraph_neimode_t c_from_mode; + igraph_neimode_t c_to_mode; + igraph_bool_t c_directed_neighbors; igraph_bool_t c_normalized; - igraph_bool_t c_loops; - igraph_bool_t c_directed; - SEXP res; + igraph_integer_t c_max_from_degree; + igraph_integer_t c_max_to_degree; + SEXP p; SEXP r_result; /* Convert input */ @@ -4867,180 +7673,183 @@ SEXP R_igraph_rich_club_sequence(SEXP graph, SEXP weights, SEXP vertex_order, SE if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - Rz_SEXP_to_vector_int_copy(vertex_order, &c_vertex_order); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_order); + IGRAPH_R_CHECK(igraph_matrix_init(&c_p, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_p); + c_from_mode = (igraph_neimode_t) Rf_asInteger(from_mode); + c_to_mode = (igraph_neimode_t) Rf_asInteger(to_mode); + IGRAPH_R_CHECK_BOOL(directed_neighbors); + c_directed_neighbors = LOGICAL(directed_neighbors)[0]; IGRAPH_R_CHECK_BOOL(normalized); c_normalized = LOGICAL(normalized)[0]; - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_INT(max_from_degree); + c_max_from_degree = (igraph_integer_t) REAL(max_from_degree)[0]; + IGRAPH_R_CHECK_INT(max_to_degree); + c_max_to_degree = (igraph_integer_t) REAL(max_to_degree)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_rich_club_sequence(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, &c_vertex_order, c_normalized, c_loops, c_directed)); + IGRAPH_R_CHECK(igraph_joint_degree_distribution(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_p, c_from_mode, c_to_mode, c_directed_neighbors, c_normalized, c_max_from_degree, c_max_to_degree)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vertex_order); + PROTECT(p=Ry_igraph_matrix_to_SEXP(&c_p)); + igraph_matrix_destroy(&c_p); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + r_result = p; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_strength / +/ igraph_joint_type_distribution / /-------------------------------------------*/ -SEXP R_igraph_strength(SEXP graph, SEXP vids, SEXP mode, SEXP loops, SEXP weights) { +SEXP R_igraph_joint_type_distribution(SEXP graph, SEXP weights, SEXP from_types, SEXP to_types, SEXP directed, SEXP normalized) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - igraph_bool_t c_loops; igraph_vector_t c_weights; - SEXP res; + igraph_matrix_t c_p; + igraph_vector_int_t c_from_types; + igraph_vector_int_t c_to_types; + igraph_bool_t c_directed; + igraph_bool_t c_normalized; + SEXP p; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } + IGRAPH_R_CHECK(igraph_matrix_init(&c_p, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_p); + Rz_SEXP_to_vector_int_copy(from_types, &c_from_types); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_from_types); + if (!Rf_isNull(to_types)) { + Rz_SEXP_to_vector_int_copy(to_types, &c_to_types); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_to_types); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_to_types, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_to_types); + } + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(normalized); + c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_strength(&c_graph, &c_res, c_vids, c_mode, c_loops, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_joint_type_distribution(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_p, &c_from_types, (Rf_isNull(to_types) ? 0 : &c_to_types), c_directed, c_normalized)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + PROTECT(p=Ry_igraph_matrix_to_SEXP(&c_p)); + igraph_matrix_destroy(&c_p); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - r_result = res; + igraph_vector_int_destroy(&c_from_types); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_to_types); + IGRAPH_FINALLY_CLEAN(1); + r_result = p; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_centralization / +/ igraph_contract_vertices / /-------------------------------------------*/ -SEXP R_igraph_centralization(SEXP scores, SEXP theoretical_max, SEXP normalized) { +SEXP R_igraph_contract_vertices(SEXP graph, SEXP mapping, SEXP vertex_attr_comb) { /* Declarations */ - igraph_vector_t c_scores; - igraph_real_t c_theoretical_max; - igraph_bool_t c_normalized; - igraph_real_t c_result; + igraph_t c_graph; + igraph_vector_int_t c_mapping; + igraph_attribute_combination_t c_vertex_attr_comb; + SEXP r_result; /* Convert input */ - Rz_SEXP_to_vector(scores, &c_scores); - IGRAPH_R_CHECK_REAL(theoretical_max); - c_theoretical_max = REAL(theoretical_max)[0]; - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; + Rz_SEXP_to_igraph_copy(graph, &c_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + Rz_SEXP_to_vector_int_copy(mapping, &c_mapping); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_mapping); + Rz_SEXP_to_attr_comb(vertex_attr_comb, &c_vertex_attr_comb); + IGRAPH_FINALLY(igraph_attribute_combination_destroy, &c_vertex_attr_comb); /* Call igraph */ - c_result=igraph_centralization(&c_scores, c_theoretical_max, c_normalized); + IGRAPH_R_CHECK(igraph_contract_vertices(&c_graph, &c_mapping, &c_vertex_attr_comb)); /* Convert output */ - - PROTECT(r_result=NEW_NUMERIC(1)); - REAL(r_result)[0]=c_result; + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_mapping); + IGRAPH_FINALLY_CLEAN(1); + igraph_attribute_combination_destroy(&c_vertex_attr_comb); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_centralization_degree / +/ igraph_eccentricity / /-------------------------------------------*/ -SEXP R_igraph_centralization_degree(SEXP graph, SEXP mode, SEXP loops, SEXP normalized) { +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; - igraph_bool_t c_loops; - igraph_real_t c_centralization; - igraph_real_t c_theoretical_max; - igraph_bool_t c_normalized; SEXP res; - SEXP centralization; - SEXP theoretical_max; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_centralization_degree(&c_graph, &c_res, c_mode, c_loops, &c_centralization, &c_theoretical_max, c_normalized)); + IGRAPH_R_CHECK(igraph_eccentricity(&c_graph, &c_res, c_vids, c_mode)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - PROTECT(centralization=NEW_NUMERIC(1)); - REAL(centralization)[0]=c_centralization; - PROTECT(theoretical_max=NEW_NUMERIC(1)); - REAL(theoretical_max)[0]=c_theoretical_max; - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, centralization); - SET_VECTOR_ELT(r_result, 2, theoretical_max); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("centralization")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("theoretical_max")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_centralization_degree_tmax / +/ igraph_eccentricity_dijkstra / /-------------------------------------------*/ -SEXP R_igraph_centralization_degree_tmax(SEXP graph, SEXP nodes, SEXP mode, SEXP loops) { +SEXP R_igraph_eccentricity_dijkstra(SEXP graph, SEXP weights, SEXP vids, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_nodes; + igraph_vector_t c_weights; + igraph_vector_t c_res; + igraph_vs_t c_vids; igraph_neimode_t c_mode; - igraph_bool_t c_loops; - igraph_real_t c_res; SEXP res; SEXP r_result; /* Convert input */ - if (!Rf_isNull(graph)) { - Rz_SEXP_to_igraph(graph, &c_graph); + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK_INT(nodes); - c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_centralization_degree_tmax((Rf_isNull(graph) ? 0 : &c_graph), c_nodes, c_mode, c_loops, &c_res)); + IGRAPH_R_CHECK(igraph_eccentricity_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, c_vids, c_mode)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; + PROTECT(res=Ry_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); @@ -5048,81 +7857,61 @@ SEXP R_igraph_centralization_degree_tmax(SEXP graph, SEXP nodes, SEXP mode, SEXP } /*-------------------------------------------/ -/ igraph_centralization_betweenness / +/ igraph_graph_center / /-------------------------------------------*/ -SEXP R_igraph_centralization_betweenness(SEXP graph, SEXP directed, SEXP normalized) { +SEXP R_igraph_graph_center(SEXP graph, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_bool_t c_directed; - igraph_real_t c_centralization; - igraph_real_t c_theoretical_max; - igraph_bool_t c_normalized; + igraph_vector_int_t c_res; + igraph_neimode_t c_mode; SEXP res; - SEXP centralization; - SEXP theoretical_max; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_centralization_betweenness(&c_graph, &c_res, c_directed, &c_centralization, &c_theoretical_max, c_normalized)); + IGRAPH_R_CHECK(igraph_graph_center(&c_graph, &c_res, c_mode)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); + igraph_vector_int_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - PROTECT(centralization=NEW_NUMERIC(1)); - REAL(centralization)[0]=c_centralization; - PROTECT(theoretical_max=NEW_NUMERIC(1)); - REAL(theoretical_max)[0]=c_theoretical_max; - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, centralization); - SET_VECTOR_ELT(r_result, 2, theoretical_max); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("centralization")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("theoretical_max")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_centralization_betweenness_tmax / +/ igraph_graph_center_dijkstra / /-------------------------------------------*/ -SEXP R_igraph_centralization_betweenness_tmax(SEXP graph, SEXP nodes, SEXP directed) { +SEXP R_igraph_graph_center_dijkstra(SEXP graph, SEXP weights, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_nodes; - igraph_bool_t c_directed; - igraph_real_t c_res; + igraph_vector_t c_weights; + igraph_vector_int_t c_res; + igraph_neimode_t c_mode; SEXP res; SEXP r_result; /* Convert input */ - if (!Rf_isNull(graph)) { - Rz_SEXP_to_igraph(graph, &c_graph); + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK_INT(nodes); - c_nodes = (igraph_integer_t) REAL(nodes)[0]; - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_centralization_betweenness_tmax((Rf_isNull(graph) ? 0 : &c_graph), c_nodes, c_directed, &c_res)); + IGRAPH_R_CHECK(igraph_graph_center_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, c_mode)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; + PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); + igraph_vector_int_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); r_result = res; UNPROTECT(1); @@ -5130,178 +7919,197 @@ SEXP R_igraph_centralization_betweenness_tmax(SEXP graph, SEXP nodes, SEXP direc } /*-------------------------------------------/ -/ igraph_centralization_closeness / +/ igraph_radius / /-------------------------------------------*/ -SEXP R_igraph_centralization_closeness(SEXP graph, SEXP mode, SEXP normalized) { +SEXP R_igraph_radius(SEXP graph, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; + igraph_real_t c_radius; igraph_neimode_t c_mode; - igraph_real_t c_centralization; - igraph_real_t c_theoretical_max; - igraph_bool_t c_normalized; - SEXP res; - SEXP centralization; - SEXP theoretical_max; + SEXP radius; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_centralization_closeness(&c_graph, &c_res, c_mode, &c_centralization, &c_theoretical_max, c_normalized)); + IGRAPH_R_CHECK(igraph_radius(&c_graph, &c_radius, c_mode)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(centralization=NEW_NUMERIC(1)); - REAL(centralization)[0]=c_centralization; - PROTECT(theoretical_max=NEW_NUMERIC(1)); - REAL(theoretical_max)[0]=c_theoretical_max; - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, centralization); - SET_VECTOR_ELT(r_result, 2, theoretical_max); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("centralization")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("theoretical_max")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + PROTECT(radius=NEW_NUMERIC(1)); + REAL(radius)[0]=c_radius; + r_result = radius; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_centralization_closeness_tmax / +/ igraph_radius_dijkstra / /-------------------------------------------*/ -SEXP R_igraph_centralization_closeness_tmax(SEXP graph, SEXP nodes, SEXP mode) { +SEXP R_igraph_radius_dijkstra(SEXP graph, SEXP weights, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_nodes; + igraph_vector_t c_weights; + igraph_real_t c_radius; igraph_neimode_t c_mode; - igraph_real_t c_res; - SEXP res; + SEXP radius; SEXP r_result; /* Convert input */ - if (!Rf_isNull(graph)) { - Rz_SEXP_to_igraph(graph, &c_graph); + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK_INT(nodes); - c_nodes = (igraph_integer_t) REAL(nodes)[0]; c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_centralization_closeness_tmax((Rf_isNull(graph) ? 0 : &c_graph), c_nodes, c_mode, &c_res)); + IGRAPH_R_CHECK(igraph_radius_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_radius, c_mode)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(radius=NEW_NUMERIC(1)); + REAL(radius)[0]=c_radius; + r_result = radius; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_centralization_eigenvector_centrality / +/ igraph_pseudo_diameter / /-------------------------------------------*/ -SEXP R_igraph_centralization_eigenvector_centrality(SEXP graph, SEXP directed, SEXP scale, SEXP options, SEXP normalized) { +SEXP R_igraph_pseudo_diameter(SEXP graph, SEXP start_vid, SEXP directed, SEXP unconnected) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_vector; - igraph_real_t c_value; + igraph_real_t c_diameter; + igraph_integer_t c_start_vid; + igraph_integer_t c_from; + igraph_integer_t c_to; igraph_bool_t c_directed; - igraph_bool_t c_scale; - igraph_arpack_options_t c_options; - igraph_real_t c_centralization; - igraph_real_t c_theoretical_max; - igraph_bool_t c_normalized; - SEXP vector; - SEXP value; - SEXP centralization; - SEXP theoretical_max; + igraph_bool_t c_unconnected; + SEXP diameter; + SEXP from; + SEXP to; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_vector, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_vector); + c_start_vid = (igraph_integer_t) REAL(start_vid)[0]; + c_from=0; + c_to=0; IGRAPH_R_CHECK_BOOL(directed); c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(scale); - c_scale = LOGICAL(scale)[0]; - Rz_SEXP_to_igraph_arpack_options(options, &c_options); - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; + IGRAPH_R_CHECK_BOOL(unconnected); + c_unconnected = LOGICAL(unconnected)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_centralization_eigenvector_centrality(&c_graph, &c_vector, &c_value, c_directed, c_scale, &c_options, &c_centralization, &c_theoretical_max, c_normalized)); + IGRAPH_R_CHECK(igraph_pseudo_diameter(&c_graph, &c_diameter, c_start_vid, &c_from, &c_to, c_directed, c_unconnected)); /* Convert output */ - PROTECT(r_result=NEW_LIST(5)); - PROTECT(r_names=NEW_CHARACTER(5)); - PROTECT(vector=Ry_igraph_vector_to_SEXP(&c_vector)); - igraph_vector_destroy(&c_vector); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(value=NEW_NUMERIC(1)); - REAL(value)[0]=c_value; - PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); - PROTECT(centralization=NEW_NUMERIC(1)); - REAL(centralization)[0]=c_centralization; - PROTECT(theoretical_max=NEW_NUMERIC(1)); - REAL(theoretical_max)[0]=c_theoretical_max; - SET_VECTOR_ELT(r_result, 0, vector); - SET_VECTOR_ELT(r_result, 1, value); - SET_VECTOR_ELT(r_result, 2, options); - SET_VECTOR_ELT(r_result, 3, centralization); - SET_VECTOR_ELT(r_result, 4, theoretical_max); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vector")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("value")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("options")); - SET_STRING_ELT(r_names, 3, Rf_mkChar("centralization")); - SET_STRING_ELT(r_names, 4, Rf_mkChar("theoretical_max")); + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(diameter=NEW_NUMERIC(1)); + REAL(diameter)[0]=c_diameter; + PROTECT(from=NEW_NUMERIC(1)); + REAL(from)[0]=(double) c_from; + PROTECT(to=NEW_NUMERIC(1)); + REAL(to)[0]=(double) c_to; + SET_VECTOR_ELT(r_result, 0, diameter); + SET_VECTOR_ELT(r_result, 1, from); + SET_VECTOR_ELT(r_result, 2, to); + SET_STRING_ELT(r_names, 0, Rf_mkChar("diameter")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("from")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("to")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_pseudo_diameter_dijkstra / +/-------------------------------------------*/ +SEXP R_igraph_pseudo_diameter_dijkstra(SEXP graph, SEXP weights, SEXP start_vid, SEXP directed, SEXP unconnected) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_weights; + igraph_real_t c_diameter; + igraph_integer_t c_start_vid; + igraph_integer_t c_from; + igraph_integer_t c_to; + igraph_bool_t c_directed; + igraph_bool_t c_unconnected; + SEXP diameter; + SEXP from; + SEXP to; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_start_vid = (igraph_integer_t) REAL(start_vid)[0]; + c_from=0; + c_to=0; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + IGRAPH_R_CHECK_BOOL(unconnected); + c_unconnected = LOGICAL(unconnected)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_pseudo_diameter_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_diameter, c_start_vid, &c_from, &c_to, c_directed, c_unconnected)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(diameter=NEW_NUMERIC(1)); + REAL(diameter)[0]=c_diameter; + PROTECT(from=NEW_NUMERIC(1)); + REAL(from)[0]=(double) c_from; + PROTECT(to=NEW_NUMERIC(1)); + REAL(to)[0]=(double) c_to; + SET_VECTOR_ELT(r_result, 0, diameter); + SET_VECTOR_ELT(r_result, 1, from); + SET_VECTOR_ELT(r_result, 2, to); + SET_STRING_ELT(r_names, 0, Rf_mkChar("diameter")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("from")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("to")); SET_NAMES(r_result, r_names); - UNPROTECT(6); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_centralization_eigenvector_centrality_tmax / +/ igraph_diversity / /-------------------------------------------*/ -SEXP R_igraph_centralization_eigenvector_centrality_tmax(SEXP graph, SEXP nodes, SEXP directed, SEXP scale) { +SEXP R_igraph_diversity(SEXP graph, SEXP weights, SEXP vids) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_nodes; - igraph_bool_t c_directed; - igraph_bool_t c_scale; - igraph_real_t c_res; + igraph_vector_t c_weights; + igraph_vector_t c_res; + igraph_vs_t c_vids; SEXP res; SEXP r_result; /* Convert input */ - if (!Rf_isNull(graph)) { - Rz_SEXP_to_igraph(graph, &c_graph); + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK_INT(nodes); - c_nodes = (igraph_integer_t) REAL(nodes)[0]; - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(scale); - c_scale = LOGICAL(scale)[0]; + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); /* Call igraph */ - IGRAPH_R_CHECK(igraph_centralization_eigenvector_centrality_tmax((Rf_isNull(graph) ? 0 : &c_graph), c_nodes, c_directed, c_scale, &c_res)); + IGRAPH_R_CHECK(igraph_diversity(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, c_vids)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; + PROTECT(res=Ry_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); @@ -5309,93 +8117,120 @@ SEXP R_igraph_centralization_eigenvector_centrality_tmax(SEXP graph, SEXP nodes, } /*-------------------------------------------/ -/ igraph_assortativity_nominal / +/ igraph_random_walk / /-------------------------------------------*/ -SEXP R_igraph_assortativity_nominal(SEXP graph, SEXP types, SEXP directed, SEXP normalized) { +SEXP R_igraph_random_walk(SEXP graph, SEXP weights, SEXP start, SEXP mode, SEXP steps, SEXP stuck) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_types; - igraph_real_t c_res; - igraph_bool_t c_directed; - igraph_bool_t c_normalized; - SEXP res; + igraph_vector_t c_weights; + igraph_vector_int_t c_vertices; + igraph_vector_int_t c_edges; + igraph_integer_t c_start; + igraph_neimode_t c_mode; + igraph_integer_t c_steps; + igraph_random_walk_stuck_t c_stuck; + SEXP vertices; + SEXP edges; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - Rz_SEXP_to_vector_int_copy(types, &c_types); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_types); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + c_start = (igraph_integer_t) REAL(start)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_INT(steps); + c_steps = (igraph_integer_t) REAL(steps)[0]; + c_stuck = (igraph_random_walk_stuck_t) Rf_asInteger(stuck); /* Call igraph */ - IGRAPH_R_CHECK(igraph_assortativity_nominal(&c_graph, &c_types, &c_res, c_directed, c_normalized)); + IGRAPH_R_CHECK(igraph_random_walk(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_vertices, &c_edges, c_start, c_mode, c_steps, c_stuck)); /* Convert output */ - igraph_vector_int_destroy(&c_types); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); + igraph_vector_int_destroy(&c_vertices); IGRAPH_FINALLY_CLEAN(1); - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); + igraph_vector_int_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, vertices); + SET_VECTOR_ELT(r_result, 1, edges); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_assortativity / +/ igraph_random_edge_walk / /-------------------------------------------*/ -SEXP R_igraph_assortativity(SEXP graph, SEXP values, SEXP values_in, SEXP directed, SEXP normalized) { +SEXP R_igraph_random_edge_walk(SEXP graph, SEXP weights, SEXP start, SEXP mode, SEXP steps, SEXP stuck) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_values; - igraph_vector_t c_values_in; - igraph_real_t c_res; - igraph_bool_t c_directed; - igraph_bool_t c_normalized; - SEXP res; + igraph_vector_t c_weights; + igraph_vector_int_t c_edgewalk; + igraph_integer_t c_start; + igraph_neimode_t c_mode; + igraph_integer_t c_steps; + igraph_random_walk_stuck_t c_stuck; + SEXP edgewalk; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - Rz_SEXP_to_vector(values, &c_values); - if (!Rf_isNull(values_in)) { - Rz_SEXP_to_vector(values_in, &c_values_in); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edgewalk, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edgewalk); + c_start = (igraph_integer_t) REAL(start)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_INT(steps); + c_steps = (igraph_integer_t) REAL(steps)[0]; + c_stuck = (igraph_random_walk_stuck_t) Rf_asInteger(stuck); /* Call igraph */ - IGRAPH_R_CHECK(igraph_assortativity(&c_graph, &c_values, (Rf_isNull(values_in) ? 0 : &c_values_in), &c_res, c_directed, c_normalized)); + IGRAPH_R_CHECK(igraph_random_edge_walk(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_edgewalk, c_start, c_mode, c_steps, c_stuck)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(edgewalk=Ry_igraph_vector_int_to_SEXPp1(&c_edgewalk)); + igraph_vector_int_destroy(&c_edgewalk); + IGRAPH_FINALLY_CLEAN(1); + r_result = edgewalk; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_assortativity_degree / +/ igraph_global_efficiency / /-------------------------------------------*/ -SEXP R_igraph_assortativity_degree(SEXP graph, SEXP directed) { +SEXP R_igraph_global_efficiency(SEXP graph, SEXP weights, SEXP directed) { /* Declarations */ igraph_t c_graph; igraph_real_t c_res; + igraph_vector_t c_weights; igraph_bool_t c_directed; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } IGRAPH_R_CHECK_BOOL(directed); c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_assortativity_degree(&c_graph, &c_res, c_directed)); + IGRAPH_R_CHECK(igraph_global_efficiency(&c_graph, &c_res, (Rf_isNull(weights) ? 0 : &c_weights), c_directed)); /* Convert output */ PROTECT(res=NEW_NUMERIC(1)); @@ -5407,57 +8242,57 @@ SEXP R_igraph_assortativity_degree(SEXP graph, SEXP directed) { } /*-------------------------------------------/ -/ igraph_joint_degree_matrix / +/ igraph_local_efficiency / /-------------------------------------------*/ -SEXP R_igraph_joint_degree_matrix(SEXP graph, SEXP weights, SEXP max_out_degree, SEXP max_in_degree) { +SEXP R_igraph_local_efficiency(SEXP graph, SEXP vids, SEXP weights, SEXP directed, SEXP mode) { /* Declarations */ igraph_t c_graph; + igraph_vector_t c_res; + igraph_vs_t c_vids; igraph_vector_t c_weights; - igraph_matrix_t c_jdm; - igraph_integer_t c_max_out_degree; - igraph_integer_t c_max_in_degree; - SEXP jdm; + igraph_bool_t c_directed; + igraph_neimode_t c_mode; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK(igraph_matrix_init(&c_jdm, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_jdm); - IGRAPH_R_CHECK_INT(max_out_degree); - c_max_out_degree = (igraph_integer_t) REAL(max_out_degree)[0]; - IGRAPH_R_CHECK_INT(max_in_degree); - c_max_in_degree = (igraph_integer_t) REAL(max_in_degree)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_joint_degree_matrix(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_jdm, c_max_out_degree, c_max_in_degree)); + IGRAPH_R_CHECK(igraph_local_efficiency(&c_graph, &c_res, c_vids, (Rf_isNull(weights) ? 0 : &c_weights), c_directed, c_mode)); /* Convert output */ - PROTECT(jdm=Ry_igraph_matrix_to_SEXP(&c_jdm)); - igraph_matrix_destroy(&c_jdm); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - r_result = jdm; + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_joint_degree_distribution / +/ igraph_average_local_efficiency / /-------------------------------------------*/ -SEXP R_igraph_joint_degree_distribution(SEXP graph, SEXP weights, SEXP from_mode, SEXP to_mode, SEXP directed_neighbors, SEXP normalized, SEXP max_from_degree, SEXP max_to_degree) { +SEXP R_igraph_average_local_efficiency(SEXP graph, SEXP weights, SEXP directed, SEXP mode) { /* Declarations */ igraph_t c_graph; + igraph_real_t c_res; igraph_vector_t c_weights; - igraph_matrix_t c_p; - igraph_neimode_t c_from_mode; - igraph_neimode_t c_to_mode; - igraph_bool_t c_directed_neighbors; - igraph_bool_t c_normalized; - igraph_integer_t c_max_from_degree; - igraph_integer_t c_max_to_degree; - SEXP p; + igraph_bool_t c_directed; + igraph_neimode_t c_mode; + SEXP res; SEXP r_result; /* Convert input */ @@ -5465,149 +8300,128 @@ SEXP R_igraph_joint_degree_distribution(SEXP graph, SEXP weights, SEXP from_mode if (!Rf_isNull(weights)) { Rz_SEXP_to_vector(weights, &c_weights); } - IGRAPH_R_CHECK(igraph_matrix_init(&c_p, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_p); - c_from_mode = (igraph_neimode_t) Rf_asInteger(from_mode); - c_to_mode = (igraph_neimode_t) Rf_asInteger(to_mode); - IGRAPH_R_CHECK_BOOL(directed_neighbors); - c_directed_neighbors = LOGICAL(directed_neighbors)[0]; - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; - IGRAPH_R_CHECK_INT(max_from_degree); - c_max_from_degree = (igraph_integer_t) REAL(max_from_degree)[0]; - IGRAPH_R_CHECK_INT(max_to_degree); - c_max_to_degree = (igraph_integer_t) REAL(max_to_degree)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_joint_degree_distribution(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_p, c_from_mode, c_to_mode, c_directed_neighbors, c_normalized, c_max_from_degree, c_max_to_degree)); + IGRAPH_R_CHECK(igraph_average_local_efficiency(&c_graph, &c_res, (Rf_isNull(weights) ? 0 : &c_weights), c_directed, c_mode)); /* Convert output */ - PROTECT(p=Ry_igraph_matrix_to_SEXP(&c_p)); - igraph_matrix_destroy(&c_p); - IGRAPH_FINALLY_CLEAN(1); - r_result = p; + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_joint_type_distribution / +/ igraph_transitive_closure_dag / /-------------------------------------------*/ -SEXP R_igraph_joint_type_distribution(SEXP graph, SEXP weights, SEXP from_types, SEXP to_types, SEXP directed, SEXP normalized) { +SEXP R_igraph_transitive_closure_dag(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_weights; - igraph_matrix_t c_p; - igraph_vector_int_t c_from_types; - igraph_vector_int_t c_to_types; - igraph_bool_t c_directed; - igraph_bool_t c_normalized; - SEXP p; + igraph_t c_closure; + SEXP closure; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_transitive_closure_dag(&c_graph, &c_closure)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_closure); + PROTECT(closure=Ry_igraph_to_SEXP(&c_closure)); + IGRAPH_I_DESTROY(&c_closure); + IGRAPH_FINALLY_CLEAN(1); + r_result = closure; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_transitive_closure / +/-------------------------------------------*/ +SEXP R_igraph_transitive_closure(SEXP graph) { + /* Declarations */ + igraph_t c_graph; + igraph_t c_closure; + SEXP closure; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK(igraph_matrix_init(&c_p, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_p); - Rz_SEXP_to_vector_int_copy(from_types, &c_from_types); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_from_types); - if (!Rf_isNull(to_types)) { - Rz_SEXP_to_vector_int_copy(to_types, &c_to_types); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_to_types); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_to_types, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_to_types); - } - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(normalized); - c_normalized = LOGICAL(normalized)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_joint_type_distribution(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_p, &c_from_types, (Rf_isNull(to_types) ? 0 : &c_to_types), c_directed, c_normalized)); + IGRAPH_R_CHECK(igraph_transitive_closure(&c_graph, &c_closure)); /* Convert output */ - PROTECT(p=Ry_igraph_matrix_to_SEXP(&c_p)); - igraph_matrix_destroy(&c_p); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_from_types); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_to_types); + IGRAPH_FINALLY(igraph_destroy, &c_closure); + PROTECT(closure=Ry_igraph_to_SEXP(&c_closure)); + IGRAPH_I_DESTROY(&c_closure); IGRAPH_FINALLY_CLEAN(1); - r_result = p; + r_result = closure; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_contract_vertices / +/ igraph_trussness / /-------------------------------------------*/ -SEXP R_igraph_contract_vertices(SEXP graph, SEXP mapping, SEXP vertex_attr_comb) { +SEXP R_igraph_trussness(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_mapping; - igraph_attribute_combination_t c_vertex_attr_comb; + igraph_vector_int_t c_trussness; + SEXP trussness; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph_copy(graph, &c_graph); - IGRAPH_FINALLY(igraph_destroy, &c_graph); - Rz_SEXP_to_vector_int_copy(mapping, &c_mapping); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_mapping); - Rz_SEXP_to_attr_comb(vertex_attr_comb, &c_vertex_attr_comb); - IGRAPH_FINALLY(igraph_attribute_combination_destroy, &c_vertex_attr_comb); + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_trussness, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_trussness); /* Call igraph */ - IGRAPH_R_CHECK(igraph_contract_vertices(&c_graph, &c_mapping, &c_vertex_attr_comb)); + IGRAPH_R_CHECK(igraph_trussness(&c_graph, &c_trussness)); /* Convert output */ - PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); - IGRAPH_I_DESTROY(&c_graph); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_mapping); - IGRAPH_FINALLY_CLEAN(1); - igraph_attribute_combination_destroy(&c_vertex_attr_comb); + PROTECT(trussness=Ry_igraph_vector_int_to_SEXP(&c_trussness)); + igraph_vector_int_destroy(&c_trussness); IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + r_result = trussness; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_eccentricity_dijkstra / +/ igraph_is_bigraphical / /-------------------------------------------*/ -SEXP R_igraph_eccentricity_dijkstra(SEXP graph, SEXP weights, SEXP vids, SEXP mode) { +SEXP R_igraph_is_bigraphical(SEXP degrees1, SEXP degrees2, SEXP allowed_edge_types) { /* Declarations */ - igraph_t c_graph; - igraph_vector_t c_weights; - igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; + igraph_vector_int_t c_degrees1; + igraph_vector_int_t c_degrees2; + igraph_edge_type_sw_t c_allowed_edge_types; + igraph_bool_t c_res; SEXP res; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(degrees1, &c_degrees1)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_degrees1); + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(degrees2, &c_degrees2)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_degrees2); + c_allowed_edge_types = (igraph_edge_type_sw_t) Rf_asInteger(allowed_edge_types); /* Call igraph */ - IGRAPH_R_CHECK(igraph_eccentricity_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, c_vids, c_mode)); + IGRAPH_R_CHECK(igraph_is_bigraphical(&c_degrees1, &c_degrees2, c_allowed_edge_types, &c_res)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + igraph_vector_int_destroy(&c_degrees1); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); + igraph_vector_int_destroy(&c_degrees2); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -5615,32 +8429,38 @@ SEXP R_igraph_eccentricity_dijkstra(SEXP graph, SEXP weights, SEXP vids, SEXP mo } /*-------------------------------------------/ -/ igraph_graph_center_dijkstra / +/ igraph_is_graphical / /-------------------------------------------*/ -SEXP R_igraph_graph_center_dijkstra(SEXP graph, SEXP weights, SEXP mode) { +SEXP R_igraph_is_graphical(SEXP out_deg, SEXP in_deg, SEXP allowed_edge_types) { /* Declarations */ - igraph_t c_graph; - igraph_vector_t c_weights; - igraph_vector_int_t c_res; - igraph_neimode_t c_mode; + igraph_vector_int_t c_out_deg; + igraph_vector_int_t c_in_deg; + igraph_edge_type_sw_t c_allowed_edge_types; + igraph_bool_t c_res; SEXP res; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(out_deg, &c_out_deg)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_out_deg); + if (!Rf_isNull(in_deg)) { + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(in_deg, &c_in_deg)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_in_deg); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_in_deg, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_in_deg); } - IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_allowed_edge_types = (igraph_edge_type_sw_t) Rf_asInteger(allowed_edge_types); /* Call igraph */ - IGRAPH_R_CHECK(igraph_graph_center_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, c_mode)); + IGRAPH_R_CHECK(igraph_is_graphical(&c_out_deg, (Rf_isNull(in_deg) ? 0 : &c_in_deg), c_allowed_edge_types, &c_res)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); - igraph_vector_int_destroy(&c_res); + igraph_vector_int_destroy(&c_out_deg); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_in_deg); IGRAPH_FINALLY_CLEAN(1); + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -5648,224 +8468,249 @@ SEXP R_igraph_graph_center_dijkstra(SEXP graph, SEXP weights, SEXP mode) { } /*-------------------------------------------/ -/ igraph_radius_dijkstra / +/ igraph_bfs_simple / /-------------------------------------------*/ -SEXP R_igraph_radius_dijkstra(SEXP graph, SEXP weights, SEXP mode) { +SEXP R_igraph_bfs_simple(SEXP graph, SEXP root, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_weights; - igraph_real_t c_radius; + igraph_integer_t c_root; igraph_neimode_t c_mode; - SEXP radius; + igraph_vector_int_t c_order; + igraph_vector_int_t c_layers; + igraph_vector_int_t c_parents; + SEXP order; + SEXP layers; + SEXP parents; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + c_root = (igraph_integer_t) REAL(root)[0]; c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_order, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_order); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_layers, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_layers); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_parents, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_parents); /* Call igraph */ - IGRAPH_R_CHECK(igraph_radius_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_radius, c_mode)); + IGRAPH_R_CHECK(igraph_bfs_simple(&c_graph, c_root, c_mode, &c_order, &c_layers, &c_parents)); /* Convert output */ - PROTECT(radius=NEW_NUMERIC(1)); - REAL(radius)[0]=c_radius; - r_result = radius; + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(order=Ry_igraph_vector_int_to_SEXPp1(&c_order)); + igraph_vector_int_destroy(&c_order); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(layers=Ry_igraph_vector_int_to_SEXP(&c_layers)); + igraph_vector_int_destroy(&c_layers); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(parents=Ry_igraph_vector_int_to_SEXP(&c_parents)); + igraph_vector_int_destroy(&c_parents); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, order); + SET_VECTOR_ELT(r_result, 1, layers); + SET_VECTOR_ELT(r_result, 2, parents); + SET_STRING_ELT(r_names, 0, Rf_mkChar("order")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("layers")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("parents")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_pseudo_diameter / +/ igraph_bipartite_projection_size / /-------------------------------------------*/ -SEXP R_igraph_pseudo_diameter(SEXP graph, SEXP start_vid, SEXP directed, SEXP unconnected) { +SEXP R_igraph_bipartite_projection_size(SEXP graph, SEXP types) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_diameter; - igraph_integer_t c_start_vid; - igraph_integer_t c_from; - igraph_integer_t c_to; - igraph_bool_t c_directed; - igraph_bool_t c_unconnected; - SEXP diameter; - SEXP from; - SEXP to; + igraph_vector_bool_t c_types; + igraph_integer_t c_vcount1; + igraph_integer_t c_ecount1; + igraph_integer_t c_vcount2; + igraph_integer_t c_ecount2; + SEXP vcount1; + SEXP ecount1; + SEXP vcount2; + SEXP ecount2; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_start_vid = (igraph_integer_t) REAL(start_vid)[0]; - c_from=0; - c_to=0; - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(unconnected); - c_unconnected = LOGICAL(unconnected)[0]; + Rz_SEXP_to_vector_bool(types, &c_types); + c_vcount1=0; + c_ecount1=0; + c_vcount2=0; + c_ecount2=0; /* Call igraph */ - IGRAPH_R_CHECK(igraph_pseudo_diameter(&c_graph, &c_diameter, c_start_vid, &c_from, &c_to, c_directed, c_unconnected)); + IGRAPH_R_CHECK(igraph_bipartite_projection_size(&c_graph, &c_types, &c_vcount1, &c_ecount1, &c_vcount2, &c_ecount2)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(diameter=NEW_NUMERIC(1)); - REAL(diameter)[0]=c_diameter; - PROTECT(from=NEW_NUMERIC(1)); - REAL(from)[0]=(double) c_from; - PROTECT(to=NEW_NUMERIC(1)); - REAL(to)[0]=(double) c_to; - SET_VECTOR_ELT(r_result, 0, diameter); - SET_VECTOR_ELT(r_result, 1, from); - SET_VECTOR_ELT(r_result, 2, to); - SET_STRING_ELT(r_names, 0, Rf_mkChar("diameter")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("from")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("to")); + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(vcount1=NEW_NUMERIC(1)); + REAL(vcount1)[0]=(double) c_vcount1; + PROTECT(ecount1=NEW_NUMERIC(1)); + REAL(ecount1)[0]=(double) c_ecount1; + PROTECT(vcount2=NEW_NUMERIC(1)); + REAL(vcount2)[0]=(double) c_vcount2; + PROTECT(ecount2=NEW_NUMERIC(1)); + REAL(ecount2)[0]=(double) c_ecount2; + SET_VECTOR_ELT(r_result, 0, vcount1); + SET_VECTOR_ELT(r_result, 1, ecount1); + SET_VECTOR_ELT(r_result, 2, vcount2); + SET_VECTOR_ELT(r_result, 3, ecount2); + SET_STRING_ELT(r_names, 0, Rf_mkChar("vcount1")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("ecount1")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("vcount2")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("ecount2")); SET_NAMES(r_result, r_names); - UNPROTECT(4); + UNPROTECT(5); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_pseudo_diameter_dijkstra / +/ igraph_bipartite_projection / /-------------------------------------------*/ -SEXP R_igraph_pseudo_diameter_dijkstra(SEXP graph, SEXP weights, SEXP start_vid, SEXP directed, SEXP unconnected) { +SEXP R_igraph_bipartite_projection(SEXP graph, SEXP types, SEXP probe1) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_weights; - igraph_real_t c_diameter; - igraph_integer_t c_start_vid; - igraph_integer_t c_from; - igraph_integer_t c_to; - igraph_bool_t c_directed; - igraph_bool_t c_unconnected; - SEXP diameter; - SEXP from; - SEXP to; + igraph_vector_bool_t c_types; + igraph_t c_proj1; + igraph_t c_proj2; + igraph_vector_int_t c_multiplicity1; + igraph_vector_int_t c_multiplicity2; + igraph_integer_t c_probe1; + SEXP proj1; + SEXP proj2; + SEXP multiplicity1; + SEXP multiplicity2; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - c_start_vid = (igraph_integer_t) REAL(start_vid)[0]; - c_from=0; - c_to=0; - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - IGRAPH_R_CHECK_BOOL(unconnected); - c_unconnected = LOGICAL(unconnected)[0]; + Rz_SEXP_to_vector_bool(types, &c_types); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_multiplicity1, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_multiplicity1); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_multiplicity2, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_multiplicity2); + IGRAPH_R_CHECK_INT(probe1); + c_probe1 = (igraph_integer_t) REAL(probe1)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_pseudo_diameter_dijkstra(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_diameter, c_start_vid, &c_from, &c_to, c_directed, c_unconnected)); + IGRAPH_R_CHECK(igraph_bipartite_projection(&c_graph, &c_types, &c_proj1, &c_proj2, &c_multiplicity1, &c_multiplicity2, c_probe1)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(diameter=NEW_NUMERIC(1)); - REAL(diameter)[0]=c_diameter; - PROTECT(from=NEW_NUMERIC(1)); - REAL(from)[0]=(double) c_from; - PROTECT(to=NEW_NUMERIC(1)); - REAL(to)[0]=(double) c_to; - SET_VECTOR_ELT(r_result, 0, diameter); - SET_VECTOR_ELT(r_result, 1, from); - SET_VECTOR_ELT(r_result, 2, to); - SET_STRING_ELT(r_names, 0, Rf_mkChar("diameter")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("from")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("to")); + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + IGRAPH_FINALLY(igraph_destroy, &c_proj1); + PROTECT(proj1=Ry_igraph_to_SEXP(&c_proj1)); + IGRAPH_I_DESTROY(&c_proj1); + IGRAPH_FINALLY_CLEAN(1); + IGRAPH_FINALLY(igraph_destroy, &c_proj2); + PROTECT(proj2=Ry_igraph_to_SEXP(&c_proj2)); + IGRAPH_I_DESTROY(&c_proj2); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(multiplicity1=Ry_igraph_vector_int_to_SEXP(&c_multiplicity1)); + igraph_vector_int_destroy(&c_multiplicity1); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(multiplicity2=Ry_igraph_vector_int_to_SEXP(&c_multiplicity2)); + igraph_vector_int_destroy(&c_multiplicity2); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, proj1); + SET_VECTOR_ELT(r_result, 1, proj2); + SET_VECTOR_ELT(r_result, 2, multiplicity1); + SET_VECTOR_ELT(r_result, 3, multiplicity2); + SET_STRING_ELT(r_names, 0, Rf_mkChar("proj1")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("proj2")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("multiplicity1")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("multiplicity2")); SET_NAMES(r_result, r_names); - UNPROTECT(4); + UNPROTECT(5); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_diversity / +/ igraph_create_bipartite / /-------------------------------------------*/ -SEXP R_igraph_diversity(SEXP graph, SEXP weights, SEXP vids) { +SEXP R_igraph_create_bipartite(SEXP types, SEXP edges, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_weights; - igraph_vector_t c_res; - igraph_vs_t c_vids; - SEXP res; + igraph_vector_bool_t c_types; + igraph_vector_int_t c_edges; + igraph_bool_t c_directed; + SEXP graph; SEXP r_result; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + Rz_SEXP_to_vector_bool(types, &c_types); + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(edges, &c_edges)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_diversity(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_res, c_vids)); + IGRAPH_R_CHECK(igraph_create_bipartite(&c_graph, &c_types, &c_edges, c_directed)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - r_result = res; + igraph_vector_int_destroy(&c_edges); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_random_walk / +/ igraph_biadjacency / /-------------------------------------------*/ -SEXP R_igraph_random_walk(SEXP graph, SEXP weights, SEXP start, SEXP mode, SEXP steps, SEXP stuck) { +SEXP R_igraph_biadjacency(SEXP incidence, SEXP directed, SEXP mode, SEXP multiple) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_weights; - igraph_vector_int_t c_vertices; - igraph_vector_int_t c_edges; - igraph_integer_t c_start; + igraph_vector_bool_t c_types; + igraph_matrix_t c_incidence; + igraph_bool_t c_directed; igraph_neimode_t c_mode; - igraph_integer_t c_steps; - igraph_random_walk_stuck_t c_stuck; - SEXP vertices; - SEXP edges; + igraph_bool_t c_multiple; + SEXP graph; + SEXP types; SEXP r_result, r_names; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertices, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertices); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); - c_start = (igraph_integer_t) REAL(start)[0]; + IGRAPH_R_CHECK(igraph_vector_bool_init(&c_types, 0)); + IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_types); + Rz_SEXP_to_matrix(incidence, &c_incidence); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_INT(steps); - c_steps = (igraph_integer_t) REAL(steps)[0]; - c_stuck = (igraph_random_walk_stuck_t) Rf_asInteger(stuck); + IGRAPH_R_CHECK_BOOL(multiple); + c_multiple = LOGICAL(multiple)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_random_walk(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_vertices, &c_edges, c_start, c_mode, c_steps, c_stuck)); + IGRAPH_R_CHECK(igraph_biadjacency(&c_graph, &c_types, &c_incidence, c_directed, c_mode, c_multiple)); /* Convert output */ PROTECT(r_result=NEW_LIST(2)); PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(vertices=Ry_igraph_vector_int_to_SEXPp1(&c_vertices)); - igraph_vector_int_destroy(&c_vertices); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - PROTECT(edges=Ry_igraph_vector_int_to_SEXPp1(&c_edges)); - igraph_vector_int_destroy(&c_edges); + PROTECT(types=Ry_igraph_vector_bool_to_SEXP(&c_types)); + igraph_vector_bool_destroy(&c_types); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, vertices); - SET_VECTOR_ELT(r_result, 1, edges); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vertices")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("edges")); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, types); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("types")); SET_NAMES(r_result, r_names); UNPROTECT(3); @@ -5874,275 +8719,369 @@ SEXP R_igraph_random_walk(SEXP graph, SEXP weights, SEXP start, SEXP mode, SEXP } /*-------------------------------------------/ -/ igraph_global_efficiency / +/ igraph_get_biadjacency / /-------------------------------------------*/ -SEXP R_igraph_global_efficiency(SEXP graph, SEXP weights, SEXP directed) { +SEXP R_igraph_get_biadjacency(SEXP graph, SEXP types) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_res; - igraph_vector_t c_weights; - igraph_bool_t c_directed; + igraph_vector_bool_t c_types; + igraph_matrix_t c_res; + igraph_vector_int_t c_row_ids; + igraph_vector_int_t c_col_ids; SEXP res; + SEXP row_ids; + SEXP col_ids; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; + Rz_SEXP_to_vector_bool(types, &c_types); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_row_ids, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_row_ids); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_col_ids, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_col_ids); /* Call igraph */ - IGRAPH_R_CHECK(igraph_global_efficiency(&c_graph, &c_res, (Rf_isNull(weights) ? 0 : &c_weights), c_directed)); + IGRAPH_R_CHECK(igraph_get_biadjacency(&c_graph, &c_types, &c_res, &c_row_ids, &c_col_ids)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(row_ids=Ry_igraph_vector_int_to_SEXPp1(&c_row_ids)); + igraph_vector_int_destroy(&c_row_ids); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(col_ids=Ry_igraph_vector_int_to_SEXPp1(&c_col_ids)); + igraph_vector_int_destroy(&c_col_ids); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, row_ids); + SET_VECTOR_ELT(r_result, 2, col_ids); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("row_ids")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("col_ids")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_local_efficiency / +/ igraph_is_bipartite / /-------------------------------------------*/ -SEXP R_igraph_local_efficiency(SEXP graph, SEXP vids, SEXP weights, SEXP directed, SEXP mode) { +SEXP R_igraph_is_bipartite(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vs_t c_vids; - igraph_vector_t c_weights; - igraph_bool_t c_directed; - igraph_neimode_t c_mode; + igraph_bool_t c_res; + igraph_vector_bool_t c_type; SEXP res; + SEXP type; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_bool_init(&c_type, 0)); + IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_type); /* Call igraph */ - IGRAPH_R_CHECK(igraph_local_efficiency(&c_graph, &c_res, c_vids, (Rf_isNull(weights) ? 0 : &c_weights), c_directed, c_mode)); + IGRAPH_R_CHECK(igraph_is_bipartite(&c_graph, &c_res, &c_type)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + PROTECT(type=Ry_igraph_vector_bool_to_SEXP(&c_type)); + igraph_vector_bool_destroy(&c_type); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - r_result = res; + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, type); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("type")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_average_local_efficiency / +/ igraph_bipartite_game_gnp / /-------------------------------------------*/ -SEXP R_igraph_average_local_efficiency(SEXP graph, SEXP weights, SEXP directed, SEXP mode) { +SEXP R_igraph_bipartite_game_gnp(SEXP n1, SEXP n2, SEXP p, SEXP directed, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_real_t c_res; - igraph_vector_t c_weights; + igraph_vector_bool_t c_types; + igraph_integer_t c_n1; + igraph_integer_t c_n2; + igraph_real_t c_p; igraph_bool_t c_directed; igraph_neimode_t c_mode; - SEXP res; + SEXP graph; + SEXP types; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + IGRAPH_R_CHECK(igraph_vector_bool_init(&c_types, 0)); + IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_types); + IGRAPH_R_CHECK_INT(n1); + c_n1 = (igraph_integer_t) REAL(n1)[0]; + IGRAPH_R_CHECK_INT(n2); + c_n2 = (igraph_integer_t) REAL(n2)[0]; + IGRAPH_R_CHECK_REAL(p); + c_p = REAL(p)[0]; IGRAPH_R_CHECK_BOOL(directed); c_directed = LOGICAL(directed)[0]; c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_average_local_efficiency(&c_graph, &c_res, (Rf_isNull(weights) ? 0 : &c_weights), c_directed, c_mode)); + IGRAPH_R_CHECK(igraph_bipartite_game_gnp(&c_graph, &c_types, c_n1, c_n2, c_p, c_directed, c_mode)); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(types=Ry_igraph_vector_bool_to_SEXP(&c_types)); + igraph_vector_bool_destroy(&c_types); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, types); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("types")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_transitive_closure_dag / +/ igraph_bipartite_game_gnm / /-------------------------------------------*/ -SEXP R_igraph_transitive_closure_dag(SEXP graph) { +SEXP R_igraph_bipartite_game_gnm(SEXP n1, SEXP n2, SEXP m, SEXP directed, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_t c_closure; - SEXP closure; + igraph_vector_bool_t c_types; + igraph_integer_t c_n1; + igraph_integer_t c_n2; + igraph_integer_t c_m; + igraph_bool_t c_directed; + igraph_neimode_t c_mode; + SEXP graph; + SEXP types; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_bool_init(&c_types, 0)); + IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_types); + IGRAPH_R_CHECK_INT(n1); + c_n1 = (igraph_integer_t) REAL(n1)[0]; + IGRAPH_R_CHECK_INT(n2); + c_n2 = (igraph_integer_t) REAL(n2)[0]; + IGRAPH_R_CHECK_INT(m); + c_m = (igraph_integer_t) REAL(m)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_transitive_closure_dag(&c_graph, &c_closure)); + IGRAPH_R_CHECK(igraph_bipartite_game_gnm(&c_graph, &c_types, c_n1, c_n2, c_m, c_directed, c_mode)); /* Convert output */ - IGRAPH_FINALLY(igraph_destroy, &c_closure); - PROTECT(closure=Ry_igraph_to_SEXP(&c_closure)); - IGRAPH_I_DESTROY(&c_closure); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = closure; + PROTECT(types=Ry_igraph_vector_bool_to_SEXP(&c_types)); + igraph_vector_bool_destroy(&c_types); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, types); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("types")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_transitive_closure / +/ igraph_bipartite_game / /-------------------------------------------*/ -SEXP R_igraph_transitive_closure(SEXP graph) { +SEXP R_igraph_bipartite_game(SEXP type, SEXP n1, SEXP n2, SEXP p, SEXP m, SEXP directed, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_t c_closure; - SEXP closure; + igraph_vector_bool_t c_types; + igraph_erdos_renyi_t c_type; + igraph_integer_t c_n1; + igraph_integer_t c_n2; + igraph_real_t c_p; + igraph_integer_t c_m; + igraph_bool_t c_directed; + igraph_neimode_t c_mode; + SEXP graph; + SEXP types; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_bool_init(&c_types, 0)); + IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_types); + c_type = (igraph_erdos_renyi_t) Rf_asInteger(type); + IGRAPH_R_CHECK_INT(n1); + c_n1 = (igraph_integer_t) REAL(n1)[0]; + IGRAPH_R_CHECK_INT(n2); + c_n2 = (igraph_integer_t) REAL(n2)[0]; + IGRAPH_R_CHECK_REAL(p); + c_p = REAL(p)[0]; + IGRAPH_R_CHECK_INT(m); + c_m = (igraph_integer_t) REAL(m)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + c_mode = (igraph_neimode_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_transitive_closure(&c_graph, &c_closure)); + IGRAPH_R_CHECK(igraph_bipartite_game(&c_graph, &c_types, c_type, c_n1, c_n2, c_p, c_m, c_directed, c_mode)); /* Convert output */ - IGRAPH_FINALLY(igraph_destroy, &c_closure); - PROTECT(closure=Ry_igraph_to_SEXP(&c_closure)); - IGRAPH_I_DESTROY(&c_closure); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = closure; + PROTECT(types=Ry_igraph_vector_bool_to_SEXP(&c_types)); + igraph_vector_bool_destroy(&c_types); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, types); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("types")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_trussness / +/ igraph_get_laplacian / /-------------------------------------------*/ -SEXP R_igraph_trussness(SEXP graph) { +SEXP R_igraph_get_laplacian(SEXP graph, SEXP mode, SEXP normalization, SEXP weights) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_trussness; - SEXP trussness; + igraph_matrix_t c_res; + igraph_neimode_t c_mode; + igraph_laplacian_normalization_t c_normalization; + igraph_vector_t c_weights; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_trussness, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_trussness); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_normalization = (igraph_laplacian_normalization_t) Rf_asInteger(normalization); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_trussness(&c_graph, &c_trussness)); + IGRAPH_R_CHECK(igraph_get_laplacian(&c_graph, &c_res, c_mode, c_normalization, (Rf_isNull(weights) ? 0 : &c_weights))); /* Convert output */ - PROTECT(trussness=Ry_igraph_vector_int_to_SEXP(&c_trussness)); - igraph_vector_int_destroy(&c_trussness); + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - r_result = trussness; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_graphical / +/ igraph_get_laplacian_sparse / /-------------------------------------------*/ -SEXP R_igraph_is_graphical(SEXP out_deg, SEXP in_deg, SEXP allowed_edge_types) { +SEXP R_igraph_get_laplacian_sparse(SEXP graph, SEXP mode, SEXP normalization, SEXP weights) { /* Declarations */ - igraph_vector_int_t c_out_deg; - igraph_vector_int_t c_in_deg; - igraph_edge_type_sw_t c_allowed_edge_types; - igraph_bool_t c_res; - SEXP res; + igraph_t c_graph; + igraph_sparsemat_t c_sparseres; + igraph_neimode_t c_mode; + igraph_laplacian_normalization_t c_normalization; + igraph_vector_t c_weights; + SEXP sparseres; SEXP r_result; /* Convert input */ - IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(out_deg, &c_out_deg)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_out_deg); - if (!Rf_isNull(in_deg)) { - IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(in_deg, &c_in_deg)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_in_deg); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_in_deg, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_in_deg); + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_sparsemat_init(&c_sparseres, 0, 0, 0)); + IGRAPH_FINALLY(igraph_sparsemat_destroy, &c_sparseres); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_normalization = (igraph_laplacian_normalization_t) Rf_asInteger(normalization); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); } - c_allowed_edge_types = (igraph_edge_type_sw_t) Rf_asInteger(allowed_edge_types); /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_graphical(&c_out_deg, (Rf_isNull(in_deg) ? 0 : &c_in_deg), c_allowed_edge_types, &c_res)); + IGRAPH_R_CHECK(igraph_get_laplacian_sparse(&c_graph, &c_sparseres, c_mode, c_normalization, (Rf_isNull(weights) ? 0 : &c_weights))); /* Convert output */ - igraph_vector_int_destroy(&c_out_deg); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_in_deg); + PROTECT(sparseres=Ry_igraph_sparsemat_to_SEXP(&c_sparseres)); + igraph_sparsemat_destroy(&c_sparseres); IGRAPH_FINALLY_CLEAN(1); - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; - r_result = res; + r_result = sparseres; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_bfs_simple / +/ igraph_connected_components / /-------------------------------------------*/ -SEXP R_igraph_bfs_simple(SEXP graph, SEXP root, SEXP mode) { +SEXP R_igraph_connected_components(SEXP graph, SEXP mode) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_root; - igraph_neimode_t c_mode; - igraph_vector_int_t c_order; - igraph_vector_int_t c_layers; - igraph_vector_int_t c_parents; - SEXP order; - SEXP layers; - SEXP parents; + igraph_vector_int_t c_membership; + igraph_vector_int_t c_csize; + igraph_integer_t c_no; + igraph_connectedness_t c_mode; + SEXP membership; + SEXP csize; + SEXP no; SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_root = (igraph_integer_t) REAL(root)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_order, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_order); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_layers, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_layers); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_parents, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_parents); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_csize, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_csize); + c_no=0; + c_mode = (igraph_connectedness_t) Rf_asInteger(mode); /* Call igraph */ - IGRAPH_R_CHECK(igraph_bfs_simple(&c_graph, c_root, c_mode, &c_order, &c_layers, &c_parents)); + IGRAPH_R_CHECK(igraph_connected_components(&c_graph, &c_membership, &c_csize, &c_no, c_mode)); /* Convert output */ PROTECT(r_result=NEW_LIST(3)); PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(order=Ry_igraph_vector_int_to_SEXPp1(&c_order)); - igraph_vector_int_destroy(&c_order); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(layers=Ry_igraph_vector_int_to_SEXP(&c_layers)); - igraph_vector_int_destroy(&c_layers); + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); IGRAPH_FINALLY_CLEAN(1); - PROTECT(parents=Ry_igraph_vector_int_to_SEXP(&c_parents)); - igraph_vector_int_destroy(&c_parents); + PROTECT(csize=Ry_igraph_vector_int_to_SEXP(&c_csize)); + igraph_vector_int_destroy(&c_csize); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, order); - SET_VECTOR_ELT(r_result, 1, layers); - SET_VECTOR_ELT(r_result, 2, parents); - SET_STRING_ELT(r_names, 0, Rf_mkChar("order")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("layers")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("parents")); + PROTECT(no=NEW_NUMERIC(1)); + REAL(no)[0]=(double) c_no; + SET_VECTOR_ELT(r_result, 0, membership); + SET_VECTOR_ELT(r_result, 1, csize); + SET_VECTOR_ELT(r_result, 2, no); + SET_STRING_ELT(r_names, 0, Rf_mkChar("membership")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("csize")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("no")); SET_NAMES(r_result, r_names); UNPROTECT(4); @@ -6151,275 +9090,283 @@ SEXP R_igraph_bfs_simple(SEXP graph, SEXP root, SEXP mode) { } /*-------------------------------------------/ -/ igraph_bipartite_projection_size / +/ igraph_is_connected / +/-------------------------------------------*/ +SEXP R_igraph_is_connected(SEXP graph, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_bool_t c_res; + igraph_connectedness_t c_mode; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_mode = (igraph_connectedness_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_is_connected(&c_graph, &c_res, c_mode)); + + /* Convert output */ + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_decompose / /-------------------------------------------*/ -SEXP R_igraph_bipartite_projection_size(SEXP graph, SEXP types) { +SEXP R_igraph_decompose(SEXP graph, SEXP mode, SEXP maxcompno, SEXP minelements) { /* Declarations */ igraph_t c_graph; - igraph_vector_bool_t c_types; - igraph_integer_t c_vcount1; - igraph_integer_t c_ecount1; - igraph_integer_t c_vcount2; - igraph_integer_t c_ecount2; - SEXP vcount1; - SEXP ecount1; - SEXP vcount2; - SEXP ecount2; + igraph_graph_list_t c_components; + igraph_connectedness_t c_mode; + igraph_integer_t c_maxcompno; + igraph_integer_t c_minelements; + SEXP components; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - Rz_SEXP_to_vector_bool(types, &c_types); - c_vcount1=0; - c_ecount1=0; - c_vcount2=0; - c_ecount2=0; + IGRAPH_R_CHECK(igraph_graph_list_init(&c_components, 0)); + IGRAPH_FINALLY(igraph_graph_list_destroy, &c_components); + c_mode = (igraph_connectedness_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_INT(maxcompno); + c_maxcompno = (igraph_integer_t) REAL(maxcompno)[0]; + IGRAPH_R_CHECK_INT(minelements); + c_minelements = (igraph_integer_t) REAL(minelements)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_bipartite_projection_size(&c_graph, &c_types, &c_vcount1, &c_ecount1, &c_vcount2, &c_ecount2)); + IGRAPH_R_CHECK(igraph_decompose(&c_graph, &c_components, c_mode, c_maxcompno, c_minelements)); /* Convert output */ - PROTECT(r_result=NEW_LIST(4)); - PROTECT(r_names=NEW_CHARACTER(4)); - PROTECT(vcount1=NEW_NUMERIC(1)); - REAL(vcount1)[0]=(double) c_vcount1; - PROTECT(ecount1=NEW_NUMERIC(1)); - REAL(ecount1)[0]=(double) c_ecount1; - PROTECT(vcount2=NEW_NUMERIC(1)); - REAL(vcount2)[0]=(double) c_vcount2; - PROTECT(ecount2=NEW_NUMERIC(1)); - REAL(ecount2)[0]=(double) c_ecount2; - SET_VECTOR_ELT(r_result, 0, vcount1); - SET_VECTOR_ELT(r_result, 1, ecount1); - SET_VECTOR_ELT(r_result, 2, vcount2); - SET_VECTOR_ELT(r_result, 3, ecount2); - SET_STRING_ELT(r_names, 0, Rf_mkChar("vcount1")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("ecount1")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("vcount2")); - SET_STRING_ELT(r_names, 3, Rf_mkChar("ecount2")); - SET_NAMES(r_result, r_names); - UNPROTECT(5); + PROTECT(components=Ry_igraph_graphlist_to_SEXP(&c_components)); + IGRAPH_FREE(c_components.stor_begin); + IGRAPH_FINALLY_CLEAN(1); + r_result = components; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_create_bipartite / +/ igraph_articulation_points / /-------------------------------------------*/ -SEXP R_igraph_create_bipartite(SEXP types, SEXP edges, SEXP directed) { +SEXP R_igraph_articulation_points(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_bool_t c_types; - igraph_vector_int_t c_edges; - igraph_bool_t c_directed; - SEXP graph; + igraph_vector_int_t c_res; + SEXP res; SEXP r_result; /* Convert input */ - Rz_SEXP_to_vector_bool(types, &c_types); - IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(edges, &c_edges)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); /* Call igraph */ - IGRAPH_R_CHECK(igraph_create_bipartite(&c_graph, &c_types, &c_edges, c_directed)); + IGRAPH_R_CHECK(igraph_articulation_points(&c_graph, &c_res)); /* Convert output */ - IGRAPH_FINALLY(igraph_destroy, &c_graph); - PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); - IGRAPH_I_DESTROY(&c_graph); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_edges); + PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); + igraph_vector_int_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_biadjacency / +/ igraph_biconnected_components / /-------------------------------------------*/ -SEXP R_igraph_biadjacency(SEXP incidence, SEXP directed, SEXP mode, SEXP multiple) { +SEXP R_igraph_biconnected_components(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_bool_t c_types; - igraph_matrix_t c_incidence; - igraph_bool_t c_directed; - igraph_neimode_t c_mode; - igraph_bool_t c_multiple; - SEXP graph; - SEXP types; + igraph_integer_t c_no; + igraph_vector_int_list_t c_tree_edges; + igraph_vector_int_list_t c_component_edges; + igraph_vector_int_list_t c_components; + igraph_vector_int_t c_articulation_points; + SEXP no; + SEXP tree_edges; + SEXP component_edges; + SEXP components; + SEXP articulation_points; SEXP r_result, r_names; /* Convert input */ - IGRAPH_R_CHECK(igraph_vector_bool_init(&c_types, 0)); - IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_types); - Rz_SEXP_to_matrix(incidence, &c_incidence); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(multiple); - c_multiple = LOGICAL(multiple)[0]; + Rz_SEXP_to_igraph(graph, &c_graph); + c_no=0; + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_tree_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_tree_edges); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_component_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_component_edges); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_components, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_components); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_articulation_points, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_articulation_points); /* Call igraph */ - IGRAPH_R_CHECK(igraph_biadjacency(&c_graph, &c_types, &c_incidence, c_directed, c_mode, c_multiple)); + IGRAPH_R_CHECK(igraph_biconnected_components(&c_graph, &c_no, &c_tree_edges, &c_component_edges, &c_components, &c_articulation_points)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - IGRAPH_FINALLY(igraph_destroy, &c_graph); - PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); - IGRAPH_I_DESTROY(&c_graph); + PROTECT(r_result=NEW_LIST(5)); + PROTECT(r_names=NEW_CHARACTER(5)); + PROTECT(no=NEW_NUMERIC(1)); + REAL(no)[0]=(double) c_no; + PROTECT(tree_edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_tree_edges)); + igraph_vector_int_list_destroy(&c_tree_edges); IGRAPH_FINALLY_CLEAN(1); - PROTECT(types=Ry_igraph_vector_bool_to_SEXP(&c_types)); - igraph_vector_bool_destroy(&c_types); + PROTECT(component_edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_component_edges)); + igraph_vector_int_list_destroy(&c_component_edges); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, graph); - SET_VECTOR_ELT(r_result, 1, types); - SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("types")); + PROTECT(components=Ry_igraph_vector_int_list_to_SEXPp1(&c_components)); + igraph_vector_int_list_destroy(&c_components); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(articulation_points=Ry_igraph_vector_int_to_SEXPp1(&c_articulation_points)); + igraph_vector_int_destroy(&c_articulation_points); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, no); + SET_VECTOR_ELT(r_result, 1, tree_edges); + SET_VECTOR_ELT(r_result, 2, component_edges); + SET_VECTOR_ELT(r_result, 3, components); + SET_VECTOR_ELT(r_result, 4, articulation_points); + SET_STRING_ELT(r_names, 0, Rf_mkChar("no")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("tree_edges")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("component_edges")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("components")); + SET_STRING_ELT(r_names, 4, Rf_mkChar("articulation_points")); SET_NAMES(r_result, r_names); - UNPROTECT(3); + UNPROTECT(6); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_get_biadjacency / +/ igraph_bridges / /-------------------------------------------*/ -SEXP R_igraph_get_biadjacency(SEXP graph, SEXP types) { +SEXP R_igraph_bridges(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_bool_t c_types; - igraph_matrix_t c_res; - igraph_vector_int_t c_row_ids; - igraph_vector_int_t c_col_ids; + igraph_vector_int_t c_res; SEXP res; - SEXP row_ids; - SEXP col_ids; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - Rz_SEXP_to_vector_bool(types, &c_types); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_row_ids, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_row_ids); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_col_ids, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_col_ids); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_biadjacency(&c_graph, &c_types, &c_res, &c_row_ids, &c_col_ids)); + IGRAPH_R_CHECK(igraph_bridges(&c_graph, &c_res)); /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(row_ids=Ry_igraph_vector_int_to_SEXPp1(&c_row_ids)); - igraph_vector_int_destroy(&c_row_ids); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(col_ids=Ry_igraph_vector_int_to_SEXPp1(&c_col_ids)); - igraph_vector_int_destroy(&c_col_ids); + PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); + igraph_vector_int_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, row_ids); - SET_VECTOR_ELT(r_result, 2, col_ids); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("row_ids")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("col_ids")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_bipartite / +/ igraph_is_biconnected / /-------------------------------------------*/ -SEXP R_igraph_is_bipartite(SEXP graph) { +SEXP R_igraph_is_biconnected(SEXP graph) { /* Declarations */ igraph_t c_graph; igraph_bool_t c_res; - igraph_vector_bool_t c_type; SEXP res; - SEXP type; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_bool_init(&c_type, 0)); - IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_type); /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_bipartite(&c_graph, &c_res, &c_type)); + IGRAPH_R_CHECK(igraph_is_biconnected(&c_graph, &c_res)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); PROTECT(res=NEW_LOGICAL(1)); LOGICAL(res)[0]=c_res; - PROTECT(type=Ry_igraph_vector_bool_to_SEXP(&c_type)); - igraph_vector_bool_destroy(&c_type); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_count_reachable / +/-------------------------------------------*/ +SEXP R_igraph_count_reachable(SEXP graph, SEXP mode) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_counts; + igraph_neimode_t c_mode; + SEXP counts; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_counts, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_counts); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_count_reachable(&c_graph, &c_counts, c_mode)); + + /* Convert output */ + PROTECT(counts=Ry_igraph_vector_int_to_SEXP(&c_counts)); + igraph_vector_int_destroy(&c_counts); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, res); - SET_VECTOR_ELT(r_result, 1, type); - SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("type")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + r_result = counts; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_bipartite_game_gnp / +/ igraph_bond_percolation / /-------------------------------------------*/ -SEXP R_igraph_bipartite_game_gnp(SEXP n1, SEXP n2, SEXP p, SEXP directed, SEXP mode) { +SEXP R_igraph_bond_percolation(SEXP graph, SEXP edge_order) { /* Declarations */ igraph_t c_graph; - igraph_vector_bool_t c_types; - igraph_integer_t c_n1; - igraph_integer_t c_n2; - igraph_real_t c_p; - igraph_bool_t c_directed; - igraph_neimode_t c_mode; - SEXP graph; - SEXP types; + igraph_vector_int_t c_giant_size; + igraph_vector_int_t c_vetex_count; + igraph_vector_int_t c_edge_order; + SEXP giant_size; + SEXP vetex_count; SEXP r_result, r_names; /* Convert input */ - IGRAPH_R_CHECK(igraph_vector_bool_init(&c_types, 0)); - IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_types); - IGRAPH_R_CHECK_INT(n1); - c_n1 = (igraph_integer_t) REAL(n1)[0]; - IGRAPH_R_CHECK_INT(n2); - c_n2 = (igraph_integer_t) REAL(n2)[0]; - IGRAPH_R_CHECK_REAL(p); - c_p = REAL(p)[0]; - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_giant_size, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_giant_size); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vetex_count, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vetex_count); + if (!Rf_isNull(edge_order)) { + Rz_SEXP_to_vector_int_copy(edge_order, &c_edge_order); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_order); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edge_order, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_order); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_bipartite_game_gnp(&c_graph, &c_types, c_n1, c_n2, c_p, c_directed, c_mode)); + IGRAPH_R_CHECK(igraph_bond_percolation(&c_graph, &c_giant_size, &c_vetex_count, (Rf_isNull(edge_order) ? 0 : &c_edge_order))); /* Convert output */ PROTECT(r_result=NEW_LIST(2)); PROTECT(r_names=NEW_CHARACTER(2)); - IGRAPH_FINALLY(igraph_destroy, &c_graph); - PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); - IGRAPH_I_DESTROY(&c_graph); + PROTECT(giant_size=Ry_igraph_vector_int_to_SEXP(&c_giant_size)); + igraph_vector_int_destroy(&c_giant_size); IGRAPH_FINALLY_CLEAN(1); - PROTECT(types=Ry_igraph_vector_bool_to_SEXP(&c_types)); - igraph_vector_bool_destroy(&c_types); + PROTECT(vetex_count=Ry_igraph_vector_int_to_SEXP(&c_vetex_count)); + igraph_vector_int_destroy(&c_vetex_count); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, graph); - SET_VECTOR_ELT(r_result, 1, types); - SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("types")); + igraph_vector_int_destroy(&c_edge_order); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, giant_size); + SET_VECTOR_ELT(r_result, 1, vetex_count); + SET_STRING_ELT(r_names, 0, Rf_mkChar("giant_size")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("vetex_count")); SET_NAMES(r_result, r_names); UNPROTECT(3); @@ -6428,50 +9375,49 @@ SEXP R_igraph_bipartite_game_gnp(SEXP n1, SEXP n2, SEXP p, SEXP directed, SEXP m } /*-------------------------------------------/ -/ igraph_bipartite_game_gnm / +/ igraph_site_percolation / /-------------------------------------------*/ -SEXP R_igraph_bipartite_game_gnm(SEXP n1, SEXP n2, SEXP m, SEXP directed, SEXP mode) { +SEXP R_igraph_site_percolation(SEXP graph, SEXP vertex_order) { /* Declarations */ igraph_t c_graph; - igraph_vector_bool_t c_types; - igraph_integer_t c_n1; - igraph_integer_t c_n2; - igraph_integer_t c_m; - igraph_bool_t c_directed; - igraph_neimode_t c_mode; - SEXP graph; - SEXP types; + igraph_vector_int_t c_giant_size; + igraph_vector_int_t c_edge_count; + igraph_vector_int_t c_vertex_order; + SEXP giant_size; + SEXP edge_count; SEXP r_result, r_names; /* Convert input */ - IGRAPH_R_CHECK(igraph_vector_bool_init(&c_types, 0)); - IGRAPH_FINALLY(igraph_vector_bool_destroy, &c_types); - IGRAPH_R_CHECK_INT(n1); - c_n1 = (igraph_integer_t) REAL(n1)[0]; - IGRAPH_R_CHECK_INT(n2); - c_n2 = (igraph_integer_t) REAL(n2)[0]; - IGRAPH_R_CHECK_INT(m); - c_m = (igraph_integer_t) REAL(m)[0]; - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_giant_size, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_giant_size); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_edge_count, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_count); + if (!Rf_isNull(vertex_order)) { + Rz_SEXP_to_vector_int_copy(vertex_order, &c_vertex_order); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_order); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_order, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_order); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_bipartite_game_gnm(&c_graph, &c_types, c_n1, c_n2, c_m, c_directed, c_mode)); + IGRAPH_R_CHECK(igraph_site_percolation(&c_graph, &c_giant_size, &c_edge_count, (Rf_isNull(vertex_order) ? 0 : &c_vertex_order))); /* Convert output */ PROTECT(r_result=NEW_LIST(2)); PROTECT(r_names=NEW_CHARACTER(2)); - IGRAPH_FINALLY(igraph_destroy, &c_graph); - PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); - IGRAPH_I_DESTROY(&c_graph); + PROTECT(giant_size=Ry_igraph_vector_int_to_SEXP(&c_giant_size)); + igraph_vector_int_destroy(&c_giant_size); IGRAPH_FINALLY_CLEAN(1); - PROTECT(types=Ry_igraph_vector_bool_to_SEXP(&c_types)); - igraph_vector_bool_destroy(&c_types); + PROTECT(edge_count=Ry_igraph_vector_int_to_SEXP(&c_edge_count)); + igraph_vector_int_destroy(&c_edge_count); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, graph); - SET_VECTOR_ELT(r_result, 1, types); - SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("types")); + igraph_vector_int_destroy(&c_vertex_order); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, giant_size); + SET_VECTOR_ELT(r_result, 1, edge_count); + SET_STRING_ELT(r_names, 0, Rf_mkChar("giant_size")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edge_count")); SET_NAMES(r_result, r_names); UNPROTECT(3); @@ -6480,171 +9426,167 @@ SEXP R_igraph_bipartite_game_gnm(SEXP n1, SEXP n2, SEXP m, SEXP directed, SEXP m } /*-------------------------------------------/ -/ igraph_get_laplacian / +/ igraph_edgelist_percolation / /-------------------------------------------*/ -SEXP R_igraph_get_laplacian(SEXP graph, SEXP mode, SEXP normalization, SEXP weights) { +SEXP R_igraph_edgelist_percolation(SEXP edges) { /* Declarations */ - igraph_t c_graph; - igraph_matrix_t c_res; - igraph_neimode_t c_mode; - igraph_laplacian_normalization_t c_normalization; - igraph_vector_t c_weights; - SEXP res; + igraph_vector_int_t c_edges; + igraph_vector_int_t c_giant_size; + igraph_vector_int_t c_vertex_count; + SEXP giant_size; + SEXP vertex_count; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - c_normalization = (igraph_laplacian_normalization_t) Rf_asInteger(normalization); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + Rz_SEXP_to_vector_int_copy(edges, &c_edges); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_giant_size, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_giant_size); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_count, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_count); /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_laplacian(&c_graph, &c_res, c_mode, c_normalization, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_edgelist_percolation(&c_edges, &c_giant_size, &c_vertex_count)); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + igraph_vector_int_destroy(&c_edges); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + PROTECT(giant_size=Ry_igraph_vector_int_to_SEXP(&c_giant_size)); + igraph_vector_int_destroy(&c_giant_size); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(vertex_count=Ry_igraph_vector_int_to_SEXP(&c_vertex_count)); + igraph_vector_int_destroy(&c_vertex_count); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, giant_size); + SET_VECTOR_ELT(r_result, 1, vertex_count); + SET_STRING_ELT(r_names, 0, Rf_mkChar("giant_size")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("vertex_count")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_get_laplacian_sparse / +/ igraph_is_clique / /-------------------------------------------*/ -SEXP R_igraph_get_laplacian_sparse(SEXP graph, SEXP mode, SEXP normalization, SEXP weights) { +SEXP R_igraph_is_clique(SEXP graph, SEXP candidate, SEXP directed) { /* Declarations */ igraph_t c_graph; - igraph_sparsemat_t c_sparseres; - igraph_neimode_t c_mode; - igraph_laplacian_normalization_t c_normalization; - igraph_vector_t c_weights; - SEXP sparseres; + igraph_vs_t c_candidate; + igraph_bool_t c_directed; + igraph_bool_t c_res; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_sparsemat_init(&c_sparseres, 0, 0, 0)); - IGRAPH_FINALLY(igraph_sparsemat_destroy, &c_sparseres); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - c_normalization = (igraph_laplacian_normalization_t) Rf_asInteger(normalization); - if (!Rf_isNull(weights)) { - Rz_SEXP_to_vector(weights, &c_weights); - } + igraph_vector_int_t c_candidate_data; + Rz_SEXP_to_igraph_vs(candidate, &c_graph, &c_candidate, &c_candidate_data); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_get_laplacian_sparse(&c_graph, &c_sparseres, c_mode, c_normalization, (Rf_isNull(weights) ? 0 : &c_weights))); + IGRAPH_R_CHECK(igraph_is_clique(&c_graph, c_candidate, c_directed, &c_res)); /* Convert output */ - PROTECT(sparseres=Ry_igraph_sparsemat_to_SEXP(&c_sparseres)); - igraph_sparsemat_destroy(&c_sparseres); - IGRAPH_FINALLY_CLEAN(1); - r_result = sparseres; + igraph_vector_int_destroy(&c_candidate_data); + igraph_vs_destroy(&c_candidate); + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_connected_components / +/ igraph_cliques / /-------------------------------------------*/ -SEXP R_igraph_connected_components(SEXP graph, SEXP mode) { +SEXP R_igraph_cliques(SEXP graph, SEXP min_size, SEXP max_size) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_membership; - igraph_vector_int_t c_csize; - igraph_integer_t c_no; - igraph_connectedness_t c_mode; - SEXP membership; - SEXP csize; - SEXP no; + igraph_vector_int_list_t c_res; + igraph_integer_t c_min_size; + igraph_integer_t c_max_size; + SEXP res; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_csize, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_csize); - c_no=0; - c_mode = (igraph_connectedness_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + IGRAPH_R_CHECK_INT(min_size); + c_min_size = (igraph_integer_t) REAL(min_size)[0]; + IGRAPH_R_CHECK_INT(max_size); + c_max_size = (igraph_integer_t) REAL(max_size)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_connected_components(&c_graph, &c_membership, &c_csize, &c_no, c_mode)); - - /* Convert output */ - PROTECT(r_result=NEW_LIST(3)); - PROTECT(r_names=NEW_CHARACTER(3)); - PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); - igraph_vector_int_destroy(&c_membership); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(csize=Ry_igraph_vector_int_to_SEXP(&c_csize)); - igraph_vector_int_destroy(&c_csize); + IGRAPH_R_CHECK(igraph_cliques(&c_graph, &c_res, c_min_size, c_max_size)); + + /* Convert output */ + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - PROTECT(no=NEW_NUMERIC(1)); - REAL(no)[0]=(double) c_no; - SET_VECTOR_ELT(r_result, 0, membership); - SET_VECTOR_ELT(r_result, 1, csize); - SET_VECTOR_ELT(r_result, 2, no); - SET_STRING_ELT(r_names, 0, Rf_mkChar("membership")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("csize")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("no")); - SET_NAMES(r_result, r_names); - UNPROTECT(4); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_connected / +/ igraph_clique_size_hist / /-------------------------------------------*/ -SEXP R_igraph_is_connected(SEXP graph, SEXP mode) { +SEXP R_igraph_clique_size_hist(SEXP graph, SEXP min_size, SEXP max_size) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_res; - igraph_connectedness_t c_mode; - SEXP res; + igraph_vector_t c_hist; + igraph_integer_t c_min_size; + igraph_integer_t c_max_size; + SEXP hist; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_mode = (igraph_connectedness_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_init(&c_hist, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_hist); + IGRAPH_R_CHECK_INT(min_size); + c_min_size = (igraph_integer_t) REAL(min_size)[0]; + IGRAPH_R_CHECK_INT(max_size); + c_max_size = (igraph_integer_t) REAL(max_size)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_connected(&c_graph, &c_res, c_mode)); + IGRAPH_R_CHECK(igraph_clique_size_hist(&c_graph, &c_hist, c_min_size, c_max_size)); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; - r_result = res; + PROTECT(hist=Ry_igraph_vector_to_SEXP(&c_hist)); + igraph_vector_destroy(&c_hist); + IGRAPH_FINALLY_CLEAN(1); + r_result = hist; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_articulation_points / +/ igraph_largest_cliques / /-------------------------------------------*/ -SEXP R_igraph_articulation_points(SEXP graph) { +SEXP R_igraph_largest_cliques(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_res; + igraph_vector_int_list_t c_res; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); /* Call igraph */ - IGRAPH_R_CHECK(igraph_articulation_points(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_largest_cliques(&c_graph, &c_res)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); - igraph_vector_int_destroy(&c_res); + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); r_result = res; @@ -6653,323 +9595,275 @@ SEXP R_igraph_articulation_points(SEXP graph) { } /*-------------------------------------------/ -/ igraph_biconnected_components / +/ igraph_maximal_cliques / /-------------------------------------------*/ -SEXP R_igraph_biconnected_components(SEXP graph) { +SEXP R_igraph_maximal_cliques(SEXP graph, SEXP min_size, SEXP max_size) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_no; - igraph_vector_int_list_t c_tree_edges; - igraph_vector_int_list_t c_component_edges; - igraph_vector_int_list_t c_components; - igraph_vector_int_t c_articulation_points; - SEXP no; - SEXP tree_edges; - SEXP component_edges; - SEXP components; - SEXP articulation_points; + igraph_vector_int_list_t c_res; + igraph_integer_t c_min_size; + igraph_integer_t c_max_size; + SEXP res; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_no=0; - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_tree_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_tree_edges); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_component_edges, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_component_edges); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_components, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_components); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_articulation_points, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_articulation_points); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + IGRAPH_R_CHECK_INT(min_size); + c_min_size = (igraph_integer_t) REAL(min_size)[0]; + IGRAPH_R_CHECK_INT(max_size); + c_max_size = (igraph_integer_t) REAL(max_size)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_biconnected_components(&c_graph, &c_no, &c_tree_edges, &c_component_edges, &c_components, &c_articulation_points)); + IGRAPH_R_CHECK(igraph_maximal_cliques(&c_graph, &c_res, c_min_size, c_max_size)); /* Convert output */ - PROTECT(r_result=NEW_LIST(5)); - PROTECT(r_names=NEW_CHARACTER(5)); - PROTECT(no=NEW_NUMERIC(1)); - REAL(no)[0]=(double) c_no; - PROTECT(tree_edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_tree_edges)); - igraph_vector_int_list_destroy(&c_tree_edges); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(component_edges=Ry_igraph_vector_int_list_to_SEXPp1(&c_component_edges)); - igraph_vector_int_list_destroy(&c_component_edges); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(components=Ry_igraph_vector_int_list_to_SEXPp1(&c_components)); - igraph_vector_int_list_destroy(&c_components); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(articulation_points=Ry_igraph_vector_int_to_SEXPp1(&c_articulation_points)); - igraph_vector_int_destroy(&c_articulation_points); + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, no); - SET_VECTOR_ELT(r_result, 1, tree_edges); - SET_VECTOR_ELT(r_result, 2, component_edges); - SET_VECTOR_ELT(r_result, 3, components); - SET_VECTOR_ELT(r_result, 4, articulation_points); - SET_STRING_ELT(r_names, 0, Rf_mkChar("no")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("tree_edges")); - SET_STRING_ELT(r_names, 2, Rf_mkChar("component_edges")); - SET_STRING_ELT(r_names, 3, Rf_mkChar("components")); - SET_STRING_ELT(r_names, 4, Rf_mkChar("articulation_points")); - SET_NAMES(r_result, r_names); - UNPROTECT(6); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_bridges / +/ igraph_maximal_cliques_subset / /-------------------------------------------*/ -SEXP R_igraph_bridges(SEXP graph) { +SEXP R_igraph_maximal_cliques_subset(SEXP graph, SEXP subset, SEXP outfile, SEXP min_size, SEXP max_size) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_res; + igraph_vector_int_t c_subset; + igraph_vector_int_list_t c_res; + igraph_integer_t c_no; + FILE* c_outfile; + igraph_integer_t c_min_size; + igraph_integer_t c_max_size; SEXP res; + SEXP no; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + Rz_SEXP_to_vector_int_copy(subset, &c_subset); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_subset); + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + c_no=0; + if (!Rf_isNull(outfile)) { + c_outfile = Ry_igraph_fopen_write(outfile); + IGRAPH_FINALLY(fclose, c_outfile); + } + IGRAPH_R_CHECK_INT(min_size); + c_min_size = (igraph_integer_t) REAL(min_size)[0]; + IGRAPH_R_CHECK_INT(max_size); + c_max_size = (igraph_integer_t) REAL(max_size)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_bridges(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_maximal_cliques_subset(&c_graph, &c_subset, &c_res, &c_no, (Rf_isNull(outfile) ? 0 : c_outfile), c_min_size, c_max_size)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_to_SEXPp1(&c_res)); - igraph_vector_int_destroy(&c_res); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + igraph_vector_int_destroy(&c_subset); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(no=NEW_NUMERIC(1)); + REAL(no)[0]=(double) c_no; + SET_VECTOR_ELT(r_result, 0, res); + SET_VECTOR_ELT(r_result, 1, no); + SET_STRING_ELT(r_names, 0, Rf_mkChar("res")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("no")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_biconnected / +/ igraph_maximal_cliques_count / /-------------------------------------------*/ -SEXP R_igraph_is_biconnected(SEXP graph) { +SEXP R_igraph_maximal_cliques_count(SEXP graph, SEXP min_size, SEXP max_size) { /* Declarations */ igraph_t c_graph; - igraph_bool_t c_res; - SEXP res; + igraph_integer_t c_no; + igraph_integer_t c_min_size; + igraph_integer_t c_max_size; + SEXP no; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); + c_no=0; + IGRAPH_R_CHECK_INT(min_size); + c_min_size = (igraph_integer_t) REAL(min_size)[0]; + IGRAPH_R_CHECK_INT(max_size); + c_max_size = (igraph_integer_t) REAL(max_size)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_biconnected(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_maximal_cliques_count(&c_graph, &c_no, c_min_size, c_max_size)); /* Convert output */ - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; - r_result = res; + PROTECT(no=NEW_NUMERIC(1)); + REAL(no)[0]=(double) c_no; + r_result = no; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_count_reachable / +/ igraph_maximal_cliques_file / /-------------------------------------------*/ -SEXP R_igraph_count_reachable(SEXP graph, SEXP mode) { +SEXP R_igraph_maximal_cliques_file(SEXP graph, SEXP res, SEXP min_size, SEXP max_size) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_counts; - igraph_neimode_t c_mode; - SEXP counts; + FILE* c_res; + igraph_integer_t c_min_size; + igraph_integer_t c_max_size; - SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_counts, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_counts); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + c_res = Ry_igraph_fopen_write(res); + IGRAPH_FINALLY(fclose, c_res); + IGRAPH_R_CHECK_INT(min_size); + c_min_size = (igraph_integer_t) REAL(min_size)[0]; + IGRAPH_R_CHECK_INT(max_size); + c_max_size = (igraph_integer_t) REAL(max_size)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_count_reachable(&c_graph, &c_counts, c_mode)); + IGRAPH_R_CHECK(igraph_maximal_cliques_file(&c_graph, c_res, c_min_size, c_max_size)); /* Convert output */ - PROTECT(counts=Ry_igraph_vector_int_to_SEXP(&c_counts)); - igraph_vector_int_destroy(&c_counts); - IGRAPH_FINALLY_CLEAN(1); - r_result = counts; - UNPROTECT(1); - return(r_result); + + + return(R_NilValue); } /*-------------------------------------------/ -/ igraph_bond_percolation / +/ igraph_maximal_cliques_hist / /-------------------------------------------*/ -SEXP R_igraph_bond_percolation(SEXP graph, SEXP edge_order) { +SEXP R_igraph_maximal_cliques_hist(SEXP graph, SEXP min_size, SEXP max_size) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_giant_size; - igraph_vector_int_t c_vetex_count; - igraph_vector_int_t c_edge_order; - SEXP giant_size; - SEXP vetex_count; + igraph_vector_t c_hist; + igraph_integer_t c_min_size; + igraph_integer_t c_max_size; + SEXP hist; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_giant_size, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_giant_size); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vetex_count, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vetex_count); - if (!Rf_isNull(edge_order)) { - Rz_SEXP_to_vector_int_copy(edge_order, &c_edge_order); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_order); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edge_order, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_order); - } + IGRAPH_R_CHECK(igraph_vector_init(&c_hist, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_hist); + IGRAPH_R_CHECK_INT(min_size); + c_min_size = (igraph_integer_t) REAL(min_size)[0]; + IGRAPH_R_CHECK_INT(max_size); + c_max_size = (igraph_integer_t) REAL(max_size)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_bond_percolation(&c_graph, &c_giant_size, &c_vetex_count, (Rf_isNull(edge_order) ? 0 : &c_edge_order))); + IGRAPH_R_CHECK(igraph_maximal_cliques_hist(&c_graph, &c_hist, c_min_size, c_max_size)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(giant_size=Ry_igraph_vector_int_to_SEXP(&c_giant_size)); - igraph_vector_int_destroy(&c_giant_size); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(vetex_count=Ry_igraph_vector_int_to_SEXP(&c_vetex_count)); - igraph_vector_int_destroy(&c_vetex_count); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_edge_order); - IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, giant_size); - SET_VECTOR_ELT(r_result, 1, vetex_count); - SET_STRING_ELT(r_names, 0, Rf_mkChar("giant_size")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("vetex_count")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + PROTECT(hist=Ry_igraph_vector_to_SEXP(&c_hist)); + igraph_vector_destroy(&c_hist); + IGRAPH_FINALLY_CLEAN(1); + r_result = hist; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_site_percolation / +/ igraph_clique_number / /-------------------------------------------*/ -SEXP R_igraph_site_percolation(SEXP graph, SEXP vertex_order) { +SEXP R_igraph_clique_number(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_t c_giant_size; - igraph_vector_int_t c_edge_count; - igraph_vector_int_t c_vertex_order; - SEXP giant_size; - SEXP edge_count; + igraph_integer_t c_no; + SEXP no; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_giant_size, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_giant_size); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_edge_count, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edge_count); - if (!Rf_isNull(vertex_order)) { - Rz_SEXP_to_vector_int_copy(vertex_order, &c_vertex_order); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_order); - } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_order, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_order); - } + c_no=0; /* Call igraph */ - IGRAPH_R_CHECK(igraph_site_percolation(&c_graph, &c_giant_size, &c_edge_count, (Rf_isNull(vertex_order) ? 0 : &c_vertex_order))); + IGRAPH_R_CHECK(igraph_clique_number(&c_graph, &c_no)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - PROTECT(giant_size=Ry_igraph_vector_int_to_SEXP(&c_giant_size)); - igraph_vector_int_destroy(&c_giant_size); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(edge_count=Ry_igraph_vector_int_to_SEXP(&c_edge_count)); - igraph_vector_int_destroy(&c_edge_count); - IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vertex_order); - IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, giant_size); - SET_VECTOR_ELT(r_result, 1, edge_count); - SET_STRING_ELT(r_names, 0, Rf_mkChar("giant_size")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("edge_count")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + PROTECT(no=NEW_NUMERIC(1)); + REAL(no)[0]=(double) c_no; + r_result = no; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_edgelist_percolation / +/ igraph_weighted_cliques / /-------------------------------------------*/ -SEXP R_igraph_edgelist_percolation(SEXP edges) { +SEXP R_igraph_weighted_cliques(SEXP graph, SEXP vertex_weights, SEXP min_weight, SEXP max_weight, SEXP maximal) { /* Declarations */ - igraph_vector_int_t c_edges; - igraph_vector_int_t c_giant_size; - igraph_vector_int_t c_vertex_count; - SEXP giant_size; - SEXP vertex_count; + igraph_t c_graph; + igraph_vector_t c_vertex_weights; + igraph_vector_int_list_t c_res; + igraph_real_t c_min_weight; + igraph_real_t c_max_weight; + igraph_bool_t c_maximal; + SEXP res; - SEXP r_result, r_names; + SEXP r_result; /* Convert input */ - Rz_SEXP_to_vector_int_copy(edges, &c_edges); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_giant_size, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_giant_size); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_vertex_count, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_vertex_count); + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(vertex_weights)) { + Rz_SEXP_to_vector(vertex_weights, &c_vertex_weights); + } + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + IGRAPH_R_CHECK_REAL(min_weight); + c_min_weight = REAL(min_weight)[0]; + IGRAPH_R_CHECK_REAL(max_weight); + c_max_weight = REAL(max_weight)[0]; + IGRAPH_R_CHECK_BOOL(maximal); + c_maximal = LOGICAL(maximal)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_edgelist_percolation(&c_edges, &c_giant_size, &c_vertex_count)); + IGRAPH_R_CHECK(igraph_weighted_cliques(&c_graph, (Rf_isNull(vertex_weights) ? 0 : &c_vertex_weights), &c_res, c_min_weight, c_max_weight, c_maximal)); /* Convert output */ - PROTECT(r_result=NEW_LIST(2)); - PROTECT(r_names=NEW_CHARACTER(2)); - igraph_vector_int_destroy(&c_edges); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(giant_size=Ry_igraph_vector_int_to_SEXP(&c_giant_size)); - igraph_vector_int_destroy(&c_giant_size); - IGRAPH_FINALLY_CLEAN(1); - PROTECT(vertex_count=Ry_igraph_vector_int_to_SEXP(&c_vertex_count)); - igraph_vector_int_destroy(&c_vertex_count); + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - SET_VECTOR_ELT(r_result, 0, giant_size); - SET_VECTOR_ELT(r_result, 1, vertex_count); - SET_STRING_ELT(r_names, 0, Rf_mkChar("giant_size")); - SET_STRING_ELT(r_names, 1, Rf_mkChar("vertex_count")); - SET_NAMES(r_result, r_names); - UNPROTECT(3); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_is_clique / +/ igraph_largest_weighted_cliques / /-------------------------------------------*/ -SEXP R_igraph_is_clique(SEXP graph, SEXP candidate, SEXP directed) { +SEXP R_igraph_largest_weighted_cliques(SEXP graph, SEXP vertex_weights) { /* Declarations */ igraph_t c_graph; - igraph_vs_t c_candidate; - igraph_bool_t c_directed; - igraph_bool_t c_res; + igraph_vector_t c_vertex_weights; + igraph_vector_int_list_t c_res; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - igraph_vector_int_t c_candidate_data; - Rz_SEXP_to_igraph_vs(candidate, &c_graph, &c_candidate, &c_candidate_data); - IGRAPH_R_CHECK_BOOL(directed); - c_directed = LOGICAL(directed)[0]; + if (!Rf_isNull(vertex_weights)) { + Rz_SEXP_to_vector(vertex_weights, &c_vertex_weights); + } + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_clique(&c_graph, c_candidate, c_directed, &c_res)); + IGRAPH_R_CHECK(igraph_largest_weighted_cliques(&c_graph, (Rf_isNull(vertex_weights) ? 0 : &c_vertex_weights), &c_res)); /* Convert output */ - igraph_vector_int_destroy(&c_candidate_data); - igraph_vs_destroy(&c_candidate); - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); r_result = res; UNPROTECT(1); @@ -6977,32 +9871,27 @@ SEXP R_igraph_is_clique(SEXP graph, SEXP candidate, SEXP directed) { } /*-------------------------------------------/ -/ igraph_cliques / +/ igraph_weighted_clique_number / /-------------------------------------------*/ -SEXP R_igraph_cliques(SEXP graph, SEXP min_size, SEXP max_size) { +SEXP R_igraph_weighted_clique_number(SEXP graph, SEXP vertex_weights) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_list_t c_res; - igraph_integer_t c_min_size; - igraph_integer_t c_max_size; + igraph_vector_t c_vertex_weights; + igraph_real_t c_res; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); - IGRAPH_R_CHECK_INT(min_size); - c_min_size = (igraph_integer_t) REAL(min_size)[0]; - IGRAPH_R_CHECK_INT(max_size); - c_max_size = (igraph_integer_t) REAL(max_size)[0]; + if (!Rf_isNull(vertex_weights)) { + Rz_SEXP_to_vector(vertex_weights, &c_vertex_weights); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_cliques(&c_graph, &c_res, c_min_size, c_max_size)); + IGRAPH_R_CHECK(igraph_weighted_clique_number(&c_graph, (Rf_isNull(vertex_weights) ? 0 : &c_vertex_weights), &c_res)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); - igraph_vector_int_list_destroy(&c_res); - IGRAPH_FINALLY_CLEAN(1); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -7010,45 +9899,43 @@ SEXP R_igraph_cliques(SEXP graph, SEXP min_size, SEXP max_size) { } /*-------------------------------------------/ -/ igraph_clique_size_hist / +/ igraph_is_independent_vertex_set / /-------------------------------------------*/ -SEXP R_igraph_clique_size_hist(SEXP graph, SEXP min_size, SEXP max_size) { +SEXP R_igraph_is_independent_vertex_set(SEXP graph, SEXP candidate) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_hist; - igraph_integer_t c_min_size; - igraph_integer_t c_max_size; - SEXP hist; + igraph_vs_t c_candidate; + igraph_bool_t c_res; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_hist, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_hist); - IGRAPH_R_CHECK_INT(min_size); - c_min_size = (igraph_integer_t) REAL(min_size)[0]; - IGRAPH_R_CHECK_INT(max_size); - c_max_size = (igraph_integer_t) REAL(max_size)[0]; + igraph_vector_int_t c_candidate_data; + Rz_SEXP_to_igraph_vs(candidate, &c_graph, &c_candidate, &c_candidate_data); /* Call igraph */ - IGRAPH_R_CHECK(igraph_clique_size_hist(&c_graph, &c_hist, c_min_size, c_max_size)); + IGRAPH_R_CHECK(igraph_is_independent_vertex_set(&c_graph, c_candidate, &c_res)); /* Convert output */ - PROTECT(hist=Ry_igraph_vector_to_SEXP(&c_hist)); - igraph_vector_destroy(&c_hist); - IGRAPH_FINALLY_CLEAN(1); - r_result = hist; + igraph_vector_int_destroy(&c_candidate_data); + igraph_vs_destroy(&c_candidate); + PROTECT(res=NEW_LOGICAL(1)); + LOGICAL(res)[0]=c_res; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_largest_cliques / +/ igraph_independent_vertex_sets / /-------------------------------------------*/ -SEXP R_igraph_largest_cliques(SEXP graph) { +SEXP R_igraph_independent_vertex_sets(SEXP graph, SEXP min_size, SEXP max_size) { /* Declarations */ igraph_t c_graph; igraph_vector_int_list_t c_res; + igraph_integer_t c_min_size; + igraph_integer_t c_max_size; SEXP res; SEXP r_result; @@ -7056,8 +9943,12 @@ SEXP R_igraph_largest_cliques(SEXP graph) { Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + IGRAPH_R_CHECK_INT(min_size); + c_min_size = (igraph_integer_t) REAL(min_size)[0]; + IGRAPH_R_CHECK_INT(max_size); + c_max_size = (igraph_integer_t) REAL(max_size)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_largest_cliques(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_independent_vertex_sets(&c_graph, &c_res, c_min_size, c_max_size)); /* Convert output */ PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); @@ -7070,73 +9961,63 @@ SEXP R_igraph_largest_cliques(SEXP graph) { } /*-------------------------------------------/ -/ igraph_maximal_cliques_count / +/ igraph_largest_independent_vertex_sets / /-------------------------------------------*/ -SEXP R_igraph_maximal_cliques_count(SEXP graph, SEXP min_size, SEXP max_size) { +SEXP R_igraph_largest_independent_vertex_sets(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_no; - igraph_integer_t c_min_size; - igraph_integer_t c_max_size; - SEXP no; + igraph_vector_int_list_t c_res; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_no=0; - IGRAPH_R_CHECK_INT(min_size); - c_min_size = (igraph_integer_t) REAL(min_size)[0]; - IGRAPH_R_CHECK_INT(max_size); - c_max_size = (igraph_integer_t) REAL(max_size)[0]; + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); /* Call igraph */ - IGRAPH_R_CHECK(igraph_maximal_cliques_count(&c_graph, &c_no, c_min_size, c_max_size)); + IGRAPH_R_CHECK(igraph_largest_independent_vertex_sets(&c_graph, &c_res)); /* Convert output */ - PROTECT(no=NEW_NUMERIC(1)); - REAL(no)[0]=(double) c_no; - r_result = no; + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_maximal_cliques_hist / +/ igraph_maximal_independent_vertex_sets / /-------------------------------------------*/ -SEXP R_igraph_maximal_cliques_hist(SEXP graph, SEXP min_size, SEXP max_size) { +SEXP R_igraph_maximal_independent_vertex_sets(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_hist; - igraph_integer_t c_min_size; - igraph_integer_t c_max_size; - SEXP hist; + igraph_vector_int_list_t c_res; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_hist, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_hist); - IGRAPH_R_CHECK_INT(min_size); - c_min_size = (igraph_integer_t) REAL(min_size)[0]; - IGRAPH_R_CHECK_INT(max_size); - c_max_size = (igraph_integer_t) REAL(max_size)[0]; + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); /* Call igraph */ - IGRAPH_R_CHECK(igraph_maximal_cliques_hist(&c_graph, &c_hist, c_min_size, c_max_size)); + IGRAPH_R_CHECK(igraph_maximal_independent_vertex_sets(&c_graph, &c_res)); /* Convert output */ - PROTECT(hist=Ry_igraph_vector_to_SEXP(&c_hist)); - igraph_vector_destroy(&c_hist); + PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); + igraph_vector_int_list_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - r_result = hist; + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_clique_number / +/ igraph_independence_number / /-------------------------------------------*/ -SEXP R_igraph_clique_number(SEXP graph) { +SEXP R_igraph_independence_number(SEXP graph) { /* Declarations */ igraph_t c_graph; igraph_integer_t c_no; @@ -7147,7 +10028,7 @@ SEXP R_igraph_clique_number(SEXP graph) { Rz_SEXP_to_igraph(graph, &c_graph); c_no=0; /* Call igraph */ - IGRAPH_R_CHECK(igraph_clique_number(&c_graph, &c_no)); + IGRAPH_R_CHECK(igraph_independence_number(&c_graph, &c_no)); /* Convert output */ PROTECT(no=NEW_NUMERIC(1)); @@ -7159,38 +10040,25 @@ SEXP R_igraph_clique_number(SEXP graph) { } /*-------------------------------------------/ -/ igraph_weighted_cliques / +/ igraph_layout_random / /-------------------------------------------*/ -SEXP R_igraph_weighted_cliques(SEXP graph, SEXP vertex_weights, SEXP min_weight, SEXP max_weight, SEXP maximal) { +SEXP R_igraph_layout_random(SEXP graph) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_vertex_weights; - igraph_vector_int_list_t c_res; - igraph_real_t c_min_weight; - igraph_real_t c_max_weight; - igraph_bool_t c_maximal; + igraph_matrix_t c_res; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(vertex_weights)) { - Rz_SEXP_to_vector(vertex_weights, &c_vertex_weights); - } - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); - IGRAPH_R_CHECK_REAL(min_weight); - c_min_weight = REAL(min_weight)[0]; - IGRAPH_R_CHECK_REAL(max_weight); - c_max_weight = REAL(max_weight)[0]; - IGRAPH_R_CHECK_BOOL(maximal); - c_maximal = LOGICAL(maximal)[0]; + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); /* Call igraph */ - IGRAPH_R_CHECK(igraph_weighted_cliques(&c_graph, (Rf_isNull(vertex_weights) ? 0 : &c_vertex_weights), &c_res, c_min_weight, c_max_weight, c_maximal)); + IGRAPH_R_CHECK(igraph_layout_random(&c_graph, &c_res)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); - igraph_vector_int_list_destroy(&c_res); + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); r_result = res; @@ -7199,30 +10067,31 @@ SEXP R_igraph_weighted_cliques(SEXP graph, SEXP vertex_weights, SEXP min_weight, } /*-------------------------------------------/ -/ igraph_largest_weighted_cliques / +/ igraph_layout_circle / /-------------------------------------------*/ -SEXP R_igraph_largest_weighted_cliques(SEXP graph, SEXP vertex_weights) { +SEXP R_igraph_layout_circle(SEXP graph, SEXP order) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_vertex_weights; - igraph_vector_int_list_t c_res; + igraph_matrix_t c_res; + igraph_vs_t c_order; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(vertex_weights)) { - Rz_SEXP_to_vector(vertex_weights, &c_vertex_weights); - } - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_order_data; + Rz_SEXP_to_igraph_vs(order, &c_graph, &c_order, &c_order_data); /* Call igraph */ - IGRAPH_R_CHECK(igraph_largest_weighted_cliques(&c_graph, (Rf_isNull(vertex_weights) ? 0 : &c_vertex_weights), &c_res)); + IGRAPH_R_CHECK(igraph_layout_circle(&c_graph, &c_res, c_order)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); - igraph_vector_int_list_destroy(&c_res); + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_order_data); + igraph_vs_destroy(&c_order); r_result = res; UNPROTECT(1); @@ -7230,27 +10099,38 @@ SEXP R_igraph_largest_weighted_cliques(SEXP graph, SEXP vertex_weights) { } /*-------------------------------------------/ -/ igraph_weighted_clique_number / +/ igraph_layout_star / /-------------------------------------------*/ -SEXP R_igraph_weighted_clique_number(SEXP graph, SEXP vertex_weights) { +SEXP R_igraph_layout_star(SEXP graph, SEXP center, SEXP order) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_vertex_weights; - igraph_real_t c_res; + igraph_matrix_t c_res; + igraph_integer_t c_center; + igraph_vector_int_t c_order; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - if (!Rf_isNull(vertex_weights)) { - Rz_SEXP_to_vector(vertex_weights, &c_vertex_weights); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + c_center = (igraph_integer_t) REAL(center)[0]; + if (!Rf_isNull(order)) { + Rz_SEXP_to_vector_int_copy(order, &c_order); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_order); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_order, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_order); } /* Call igraph */ - IGRAPH_R_CHECK(igraph_weighted_clique_number(&c_graph, (Rf_isNull(vertex_weights) ? 0 : &c_vertex_weights), &c_res)); + IGRAPH_R_CHECK(igraph_layout_star(&c_graph, &c_res, c_center, (Rf_isNull(order) ? 0 : &c_order))); /* Convert output */ - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_order); + IGRAPH_FINALLY_CLEAN(1); r_result = res; UNPROTECT(1); @@ -7258,28 +10138,29 @@ SEXP R_igraph_weighted_clique_number(SEXP graph, SEXP vertex_weights) { } /*-------------------------------------------/ -/ igraph_is_independent_vertex_set / +/ igraph_layout_grid / /-------------------------------------------*/ -SEXP R_igraph_is_independent_vertex_set(SEXP graph, SEXP candidate) { +SEXP R_igraph_layout_grid(SEXP graph, SEXP width) { /* Declarations */ igraph_t c_graph; - igraph_vs_t c_candidate; - igraph_bool_t c_res; + igraph_matrix_t c_res; + igraph_integer_t c_width; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - igraph_vector_int_t c_candidate_data; - Rz_SEXP_to_igraph_vs(candidate, &c_graph, &c_candidate, &c_candidate_data); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK_INT(width); + c_width = (igraph_integer_t) REAL(width)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_is_independent_vertex_set(&c_graph, c_candidate, &c_res)); + IGRAPH_R_CHECK(igraph_layout_grid(&c_graph, &c_res, c_width)); /* Convert output */ - igraph_vector_int_destroy(&c_candidate_data); - igraph_vs_destroy(&c_candidate); - PROTECT(res=NEW_LOGICAL(1)); - LOGICAL(res)[0]=c_res; + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); r_result = res; UNPROTECT(1); @@ -7287,25 +10168,31 @@ SEXP R_igraph_is_independent_vertex_set(SEXP graph, SEXP candidate) { } /*-------------------------------------------/ -/ igraph_largest_independent_vertex_sets / +/ igraph_layout_grid_3d / /-------------------------------------------*/ -SEXP R_igraph_largest_independent_vertex_sets(SEXP graph) { +SEXP R_igraph_layout_grid_3d(SEXP graph, SEXP width, SEXP height) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_list_t c_res; + igraph_matrix_t c_res; + igraph_integer_t c_width; + igraph_integer_t c_height; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK_INT(width); + c_width = (igraph_integer_t) REAL(width)[0]; + IGRAPH_R_CHECK_INT(height); + c_height = (igraph_integer_t) REAL(height)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_largest_independent_vertex_sets(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_layout_grid_3d(&c_graph, &c_res, c_width, c_height)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); - igraph_vector_int_list_destroy(&c_res); + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); r_result = res; @@ -7314,64 +10201,140 @@ SEXP R_igraph_largest_independent_vertex_sets(SEXP graph) { } /*-------------------------------------------/ -/ igraph_maximal_independent_vertex_sets / +/ igraph_layout_fruchterman_reingold / /-------------------------------------------*/ -SEXP R_igraph_maximal_independent_vertex_sets(SEXP graph) { +SEXP R_igraph_layout_fruchterman_reingold(SEXP graph, SEXP coords, SEXP use_seed, SEXP niter, SEXP start_temp, SEXP grid, SEXP weights, SEXP minx, SEXP maxx, SEXP miny, SEXP maxy) { /* Declarations */ igraph_t c_graph; - igraph_vector_int_list_t c_res; - SEXP res; + igraph_matrix_t c_coords; + igraph_bool_t c_use_seed; + igraph_integer_t c_niter; + igraph_real_t c_start_temp; + igraph_layout_grid_t c_grid; + igraph_vector_t c_weights; + igraph_vector_t c_minx; + igraph_vector_t c_maxx; + igraph_vector_t c_miny; + igraph_vector_t c_maxy; + + + + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_res); + if (!Rf_isNull(coords)) { + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(coords, &c_coords)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_coords); + } + IGRAPH_R_CHECK_BOOL(use_seed); + c_use_seed = LOGICAL(use_seed)[0]; + IGRAPH_R_CHECK_INT(niter); + c_niter = (igraph_integer_t) REAL(niter)[0]; + IGRAPH_R_CHECK_REAL(start_temp); + c_start_temp = REAL(start_temp)[0]; + c_grid = (igraph_layout_grid_t) Rf_asInteger(grid); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + if (!Rf_isNull(minx)) { + Rz_SEXP_to_vector(minx, &c_minx); + } + if (!Rf_isNull(maxx)) { + Rz_SEXP_to_vector(maxx, &c_maxx); + } + if (!Rf_isNull(miny)) { + Rz_SEXP_to_vector(miny, &c_miny); + } + if (!Rf_isNull(maxy)) { + Rz_SEXP_to_vector(maxy, &c_maxy); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_maximal_independent_vertex_sets(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_layout_fruchterman_reingold(&c_graph, &c_coords, c_use_seed, c_niter, c_start_temp, c_grid, (Rf_isNull(weights) ? 0 : &c_weights), (Rf_isNull(minx) ? 0 : &c_minx), (Rf_isNull(maxx) ? 0 : &c_maxx), (Rf_isNull(miny) ? 0 : &c_miny), (Rf_isNull(maxy) ? 0 : &c_maxy))); /* Convert output */ - PROTECT(res=Ry_igraph_vector_int_list_to_SEXPp1(&c_res)); - igraph_vector_int_list_destroy(&c_res); + PROTECT(coords=Ry_igraph_matrix_to_SEXP(&c_coords)); + igraph_matrix_destroy(&c_coords); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + r_result = coords; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_independence_number / +/ igraph_layout_kamada_kawai / /-------------------------------------------*/ -SEXP R_igraph_independence_number(SEXP graph) { +SEXP R_igraph_layout_kamada_kawai(SEXP graph, SEXP coords, SEXP use_seed, SEXP maxiter, SEXP epsilon, SEXP kkconst, SEXP weights, SEXP minx, SEXP maxx, SEXP miny, SEXP maxy) { /* Declarations */ igraph_t c_graph; - igraph_integer_t c_no; - SEXP no; + igraph_matrix_t c_coords; + igraph_bool_t c_use_seed; + igraph_integer_t c_maxiter; + igraph_real_t c_epsilon; + igraph_real_t c_kkconst; + igraph_vector_t c_weights; + igraph_vector_t c_minx; + igraph_vector_t c_maxx; + igraph_vector_t c_miny; + igraph_vector_t c_maxy; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_no=0; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(coords, &c_coords)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_coords); + IGRAPH_R_CHECK_BOOL(use_seed); + c_use_seed = LOGICAL(use_seed)[0]; + IGRAPH_R_CHECK_INT(maxiter); + c_maxiter = (igraph_integer_t) REAL(maxiter)[0]; + IGRAPH_R_CHECK_REAL(epsilon); + c_epsilon = REAL(epsilon)[0]; + IGRAPH_R_CHECK_REAL(kkconst); + c_kkconst = REAL(kkconst)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + if (!Rf_isNull(minx)) { + Rz_SEXP_to_vector(minx, &c_minx); + } + if (!Rf_isNull(maxx)) { + Rz_SEXP_to_vector(maxx, &c_maxx); + } + if (!Rf_isNull(miny)) { + Rz_SEXP_to_vector(miny, &c_miny); + } + if (!Rf_isNull(maxy)) { + Rz_SEXP_to_vector(maxy, &c_maxy); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_independence_number(&c_graph, &c_no)); + IGRAPH_R_CHECK(igraph_layout_kamada_kawai(&c_graph, &c_coords, c_use_seed, c_maxiter, c_epsilon, c_kkconst, (Rf_isNull(weights) ? 0 : &c_weights), (Rf_isNull(minx) ? 0 : &c_minx), (Rf_isNull(maxx) ? 0 : &c_maxx), (Rf_isNull(miny) ? 0 : &c_miny), (Rf_isNull(maxy) ? 0 : &c_maxy))); /* Convert output */ - PROTECT(no=NEW_NUMERIC(1)); - REAL(no)[0]=(double) c_no; - r_result = no; + PROTECT(coords=Ry_igraph_matrix_to_SEXP(&c_coords)); + igraph_matrix_destroy(&c_coords); + IGRAPH_FINALLY_CLEAN(1); + r_result = coords; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_layout_random / +/ igraph_layout_lgl / /-------------------------------------------*/ -SEXP R_igraph_layout_random(SEXP graph) { +SEXP R_igraph_layout_lgl(SEXP graph, SEXP maxiter, SEXP maxdelta, SEXP area, SEXP coolexp, SEXP repulserad, SEXP cellsize, SEXP root) { /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; + igraph_integer_t c_maxiter; + igraph_real_t c_maxdelta; + igraph_real_t c_area; + igraph_real_t c_coolexp; + igraph_real_t c_repulserad; + igraph_real_t c_cellsize; + igraph_integer_t c_root; SEXP res; SEXP r_result; @@ -7379,8 +10342,22 @@ SEXP R_igraph_layout_random(SEXP graph) { Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK_INT(maxiter); + c_maxiter = (igraph_integer_t) REAL(maxiter)[0]; + IGRAPH_R_CHECK_REAL(maxdelta); + c_maxdelta = REAL(maxdelta)[0]; + IGRAPH_R_CHECK_REAL(area); + c_area = REAL(area)[0]; + IGRAPH_R_CHECK_REAL(coolexp); + c_coolexp = REAL(coolexp)[0]; + IGRAPH_R_CHECK_REAL(repulserad); + c_repulserad = REAL(repulserad)[0]; + IGRAPH_R_CHECK_REAL(cellsize); + c_cellsize = REAL(cellsize)[0]; + IGRAPH_R_CHECK_INT(root); + c_root = (igraph_integer_t) REAL(root)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_random(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_layout_lgl(&c_graph, &c_res, c_maxiter, c_maxdelta, c_area, c_coolexp, c_repulserad, c_cellsize, c_root)); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); @@ -7393,13 +10370,15 @@ SEXP R_igraph_layout_random(SEXP graph) { } /*-------------------------------------------/ -/ igraph_layout_circle / +/ igraph_layout_reingold_tilford / /-------------------------------------------*/ -SEXP R_igraph_layout_circle(SEXP graph, SEXP order) { +SEXP R_igraph_layout_reingold_tilford(SEXP graph, SEXP mode, SEXP roots, SEXP rootlevel) { /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; - igraph_vs_t c_order; + igraph_neimode_t c_mode; + igraph_vector_int_t c_roots; + igraph_vector_int_t c_rootlevel; SEXP res; SEXP r_result; @@ -7407,17 +10386,32 @@ SEXP R_igraph_layout_circle(SEXP graph, SEXP order) { Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - igraph_vector_int_t c_order_data; - Rz_SEXP_to_igraph_vs(order, &c_graph, &c_order, &c_order_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + if (!Rf_isNull(roots)) { + Rz_SEXP_to_vector_int_copy(roots, &c_roots); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_roots); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_roots, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_roots); + } + if (!Rf_isNull(rootlevel)) { + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(rootlevel, &c_rootlevel)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_rootlevel); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_rootlevel, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_rootlevel); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_circle(&c_graph, &c_res, c_order)); + IGRAPH_R_CHECK(igraph_layout_reingold_tilford(&c_graph, &c_res, c_mode, (Rf_isNull(roots) ? 0 : &c_roots), (Rf_isNull(rootlevel) ? 0 : &c_rootlevel))); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); igraph_matrix_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_order_data); - igraph_vs_destroy(&c_order); + igraph_vector_int_destroy(&c_roots); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_rootlevel); + IGRAPH_FINALLY_CLEAN(1); r_result = res; UNPROTECT(1); @@ -7425,14 +10419,15 @@ SEXP R_igraph_layout_circle(SEXP graph, SEXP order) { } /*-------------------------------------------/ -/ igraph_layout_star / +/ igraph_layout_reingold_tilford_circular / /-------------------------------------------*/ -SEXP R_igraph_layout_star(SEXP graph, SEXP center, SEXP order) { +SEXP R_igraph_layout_reingold_tilford_circular(SEXP graph, SEXP mode, SEXP roots, SEXP rootlevel) { /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; - igraph_integer_t c_center; - igraph_vector_int_t c_order; + igraph_neimode_t c_mode; + igraph_vector_int_t c_roots; + igraph_vector_int_t c_rootlevel; SEXP res; SEXP r_result; @@ -7440,37 +10435,76 @@ SEXP R_igraph_layout_star(SEXP graph, SEXP center, SEXP order) { Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - c_center = (igraph_integer_t) REAL(center)[0]; - if (!Rf_isNull(order)) { - Rz_SEXP_to_vector_int_copy(order, &c_order); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_order); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + if (!Rf_isNull(roots)) { + Rz_SEXP_to_vector_int_copy(roots, &c_roots); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_roots); } else { - IGRAPH_R_CHECK(igraph_vector_int_init(&c_order, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_order); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_roots, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_roots); + } + if (!Rf_isNull(rootlevel)) { + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(rootlevel, &c_rootlevel)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_rootlevel); + } else { + IGRAPH_R_CHECK(igraph_vector_int_init(&c_rootlevel, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_rootlevel); } /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_star(&c_graph, &c_res, c_center, (Rf_isNull(order) ? 0 : &c_order))); + IGRAPH_R_CHECK(igraph_layout_reingold_tilford_circular(&c_graph, &c_res, c_mode, (Rf_isNull(roots) ? 0 : &c_roots), (Rf_isNull(rootlevel) ? 0 : &c_rootlevel))); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); igraph_matrix_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_order); + igraph_vector_int_destroy(&c_roots); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_rootlevel); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_roots_for_tree_layout / +/-------------------------------------------*/ +SEXP R_igraph_roots_for_tree_layout(SEXP graph, SEXP mode, SEXP heuristic) { + /* Declarations */ + igraph_t c_graph; + igraph_neimode_t c_mode; + igraph_vector_int_t c_roots; + igraph_root_choice_t c_heuristic; + SEXP roots; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_roots, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_roots); + c_heuristic = (igraph_root_choice_t) Rf_asInteger(heuristic); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_roots_for_tree_layout(&c_graph, c_mode, &c_roots, c_heuristic)); + + /* Convert output */ + PROTECT(roots=Ry_igraph_vector_int_to_SEXPp1(&c_roots)); + igraph_vector_int_destroy(&c_roots); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + r_result = roots; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_layout_grid / +/ igraph_layout_random_3d / /-------------------------------------------*/ -SEXP R_igraph_layout_grid(SEXP graph, SEXP width) { +SEXP R_igraph_layout_random_3d(SEXP graph) { /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; - igraph_integer_t c_width; SEXP res; SEXP r_result; @@ -7478,10 +10512,8 @@ SEXP R_igraph_layout_grid(SEXP graph, SEXP width) { Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - IGRAPH_R_CHECK_INT(width); - c_width = (igraph_integer_t) REAL(width)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_grid(&c_graph, &c_res, c_width)); + IGRAPH_R_CHECK(igraph_layout_random_3d(&c_graph, &c_res)); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); @@ -7494,14 +10526,12 @@ SEXP R_igraph_layout_grid(SEXP graph, SEXP width) { } /*-------------------------------------------/ -/ igraph_layout_grid_3d / +/ igraph_layout_sphere / /-------------------------------------------*/ -SEXP R_igraph_layout_grid_3d(SEXP graph, SEXP width, SEXP height) { +SEXP R_igraph_layout_sphere(SEXP graph) { /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; - igraph_integer_t c_width; - igraph_integer_t c_height; SEXP res; SEXP r_result; @@ -7509,12 +10539,8 @@ SEXP R_igraph_layout_grid_3d(SEXP graph, SEXP width, SEXP height) { Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - IGRAPH_R_CHECK_INT(width); - c_width = (igraph_integer_t) REAL(width)[0]; - IGRAPH_R_CHECK_INT(height); - c_height = (igraph_integer_t) REAL(height)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_grid_3d(&c_graph, &c_res, c_width, c_height)); + IGRAPH_R_CHECK(igraph_layout_sphere(&c_graph, &c_res)); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); @@ -7527,79 +10553,176 @@ SEXP R_igraph_layout_grid_3d(SEXP graph, SEXP width, SEXP height) { } /*-------------------------------------------/ -/ igraph_roots_for_tree_layout / +/ igraph_layout_fruchterman_reingold_3d / /-------------------------------------------*/ -SEXP R_igraph_roots_for_tree_layout(SEXP graph, SEXP mode, SEXP heuristic) { +SEXP R_igraph_layout_fruchterman_reingold_3d(SEXP graph, SEXP coords, SEXP use_seed, SEXP niter, SEXP start_temp, SEXP weights, SEXP minx, SEXP maxx, SEXP miny, SEXP maxy, SEXP minz, SEXP maxz) { /* Declarations */ igraph_t c_graph; - igraph_neimode_t c_mode; - igraph_vector_int_t c_roots; - igraph_root_choice_t c_heuristic; - SEXP roots; + igraph_matrix_t c_coords; + igraph_bool_t c_use_seed; + igraph_integer_t c_niter; + igraph_real_t c_start_temp; + igraph_vector_t c_weights; + igraph_vector_t c_minx; + igraph_vector_t c_maxx; + igraph_vector_t c_miny; + igraph_vector_t c_maxy; + igraph_vector_t c_minz; + igraph_vector_t c_maxz; + + + + SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK(igraph_vector_int_init(&c_roots, 0)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_roots); - c_heuristic = (igraph_root_choice_t) Rf_asInteger(heuristic); + if (!Rf_isNull(coords)) { + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(coords, &c_coords)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_coords); + } + IGRAPH_R_CHECK_BOOL(use_seed); + c_use_seed = LOGICAL(use_seed)[0]; + IGRAPH_R_CHECK_INT(niter); + c_niter = (igraph_integer_t) REAL(niter)[0]; + IGRAPH_R_CHECK_REAL(start_temp); + c_start_temp = REAL(start_temp)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + if (!Rf_isNull(minx)) { + Rz_SEXP_to_vector(minx, &c_minx); + } + if (!Rf_isNull(maxx)) { + Rz_SEXP_to_vector(maxx, &c_maxx); + } + if (!Rf_isNull(miny)) { + Rz_SEXP_to_vector(miny, &c_miny); + } + if (!Rf_isNull(maxy)) { + Rz_SEXP_to_vector(maxy, &c_maxy); + } + if (!Rf_isNull(minz)) { + Rz_SEXP_to_vector(minz, &c_minz); + } + if (!Rf_isNull(maxz)) { + Rz_SEXP_to_vector(maxz, &c_maxz); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_roots_for_tree_layout(&c_graph, c_mode, &c_roots, c_heuristic)); + IGRAPH_R_CHECK(igraph_layout_fruchterman_reingold_3d(&c_graph, &c_coords, c_use_seed, c_niter, c_start_temp, (Rf_isNull(weights) ? 0 : &c_weights), (Rf_isNull(minx) ? 0 : &c_minx), (Rf_isNull(maxx) ? 0 : &c_maxx), (Rf_isNull(miny) ? 0 : &c_miny), (Rf_isNull(maxy) ? 0 : &c_maxy), (Rf_isNull(minz) ? 0 : &c_minz), (Rf_isNull(maxz) ? 0 : &c_maxz))); /* Convert output */ - PROTECT(roots=Ry_igraph_vector_int_to_SEXPp1(&c_roots)); - igraph_vector_int_destroy(&c_roots); + PROTECT(coords=Ry_igraph_matrix_to_SEXP(&c_coords)); + igraph_matrix_destroy(&c_coords); IGRAPH_FINALLY_CLEAN(1); - r_result = roots; + r_result = coords; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_layout_random_3d / +/ igraph_layout_kamada_kawai_3d / /-------------------------------------------*/ -SEXP R_igraph_layout_random_3d(SEXP graph) { +SEXP R_igraph_layout_kamada_kawai_3d(SEXP graph, SEXP coords, SEXP use_seed, SEXP maxiter, SEXP epsilon, SEXP kkconst, SEXP weights, SEXP minx, SEXP maxx, SEXP miny, SEXP maxy, SEXP minz, SEXP maxz) { /* Declarations */ igraph_t c_graph; - igraph_matrix_t c_res; - SEXP res; + igraph_matrix_t c_coords; + igraph_bool_t c_use_seed; + igraph_integer_t c_maxiter; + igraph_real_t c_epsilon; + igraph_real_t c_kkconst; + igraph_vector_t c_weights; + igraph_vector_t c_minx; + igraph_vector_t c_maxx; + igraph_vector_t c_miny; + igraph_vector_t c_maxy; + igraph_vector_t c_minz; + igraph_vector_t c_maxz; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(coords, &c_coords)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_coords); + IGRAPH_R_CHECK_BOOL(use_seed); + c_use_seed = LOGICAL(use_seed)[0]; + IGRAPH_R_CHECK_INT(maxiter); + c_maxiter = (igraph_integer_t) REAL(maxiter)[0]; + IGRAPH_R_CHECK_REAL(epsilon); + c_epsilon = REAL(epsilon)[0]; + IGRAPH_R_CHECK_REAL(kkconst); + c_kkconst = REAL(kkconst)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + if (!Rf_isNull(minx)) { + Rz_SEXP_to_vector(minx, &c_minx); + } + if (!Rf_isNull(maxx)) { + Rz_SEXP_to_vector(maxx, &c_maxx); + } + if (!Rf_isNull(miny)) { + Rz_SEXP_to_vector(miny, &c_miny); + } + if (!Rf_isNull(maxy)) { + Rz_SEXP_to_vector(maxy, &c_maxy); + } + if (!Rf_isNull(minz)) { + Rz_SEXP_to_vector(minz, &c_minz); + } + if (!Rf_isNull(maxz)) { + Rz_SEXP_to_vector(maxz, &c_maxz); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_random_3d(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_layout_kamada_kawai_3d(&c_graph, &c_coords, c_use_seed, c_maxiter, c_epsilon, c_kkconst, (Rf_isNull(weights) ? 0 : &c_weights), (Rf_isNull(minx) ? 0 : &c_minx), (Rf_isNull(maxx) ? 0 : &c_maxx), (Rf_isNull(miny) ? 0 : &c_miny), (Rf_isNull(maxy) ? 0 : &c_maxy), (Rf_isNull(minz) ? 0 : &c_minz), (Rf_isNull(maxz) ? 0 : &c_maxz))); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + PROTECT(coords=Ry_igraph_matrix_to_SEXP(&c_coords)); + igraph_matrix_destroy(&c_coords); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + r_result = coords; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_layout_sphere / +/ igraph_layout_graphopt / /-------------------------------------------*/ -SEXP R_igraph_layout_sphere(SEXP graph) { +SEXP R_igraph_layout_graphopt(SEXP graph, SEXP res, SEXP niter, SEXP node_charge, SEXP node_mass, SEXP spring_length, SEXP spring_constant, SEXP max_sa_movement, SEXP use_seed) { /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; - SEXP res; + igraph_integer_t c_niter; + igraph_real_t c_node_charge; + igraph_real_t c_node_mass; + igraph_real_t c_spring_length; + igraph_real_t c_spring_constant; + igraph_real_t c_max_sa_movement; + igraph_bool_t c_use_seed; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(res, &c_res)); IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK_INT(niter); + c_niter = (igraph_integer_t) REAL(niter)[0]; + IGRAPH_R_CHECK_REAL(node_charge); + c_node_charge = REAL(node_charge)[0]; + IGRAPH_R_CHECK_REAL(node_mass); + c_node_mass = REAL(node_mass)[0]; + IGRAPH_R_CHECK_REAL(spring_length); + c_spring_length = REAL(spring_length)[0]; + IGRAPH_R_CHECK_REAL(spring_constant); + c_spring_constant = REAL(spring_constant)[0]; + IGRAPH_R_CHECK_REAL(max_sa_movement); + c_max_sa_movement = REAL(max_sa_movement)[0]; + IGRAPH_R_CHECK_BOOL(use_seed); + c_use_seed = LOGICAL(use_seed)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_sphere(&c_graph, &c_res)); + IGRAPH_R_CHECK(igraph_layout_graphopt(&c_graph, &c_res, c_niter, c_node_charge, c_node_mass, c_spring_length, c_spring_constant, c_max_sa_movement, c_use_seed)); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); @@ -7968,35 +11091,190 @@ SEXP R_igraph_layout_umap_3d(SEXP graph, SEXP res, SEXP use_seed, SEXP distances /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; - igraph_bool_t c_use_seed; - igraph_vector_t c_distances; - igraph_real_t c_min_dist; - igraph_integer_t c_epochs; - igraph_bool_t c_distances_are_weights; + igraph_bool_t c_use_seed; + igraph_vector_t c_distances; + igraph_real_t c_min_dist; + igraph_integer_t c_epochs; + igraph_bool_t c_distances_are_weights; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(res, &c_res)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + IGRAPH_R_CHECK_BOOL(use_seed); + c_use_seed = LOGICAL(use_seed)[0]; + if (!Rf_isNull(distances)) { + Rz_SEXP_to_vector(distances, &c_distances); + } + IGRAPH_R_CHECK_REAL(min_dist); + c_min_dist = REAL(min_dist)[0]; + IGRAPH_R_CHECK_INT(epochs); + c_epochs = (igraph_integer_t) REAL(epochs)[0]; + IGRAPH_R_CHECK_BOOL(distances_are_weights); + c_distances_are_weights = LOGICAL(distances_are_weights)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_layout_umap_3d(&c_graph, &c_res, c_use_seed, (Rf_isNull(distances) ? 0 : &c_distances), c_min_dist, c_epochs, c_distances_are_weights)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_layout_umap_compute_weights / +/-------------------------------------------*/ +SEXP R_igraph_layout_umap_compute_weights(SEXP graph, SEXP distances, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_distances; + igraph_vector_t c_weights; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + Rz_SEXP_to_vector(distances, &c_distances); + IGRAPH_R_CHECK(Rz_SEXP_to_vector_copy(weights, &c_weights)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_weights); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_layout_umap_compute_weights(&c_graph, &c_distances, &c_weights)); + + /* Convert output */ + PROTECT(weights=Ry_igraph_vector_to_SEXP(&c_weights)); + igraph_vector_destroy(&c_weights); + IGRAPH_FINALLY_CLEAN(1); + r_result = weights; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_layout_align / +/-------------------------------------------*/ +SEXP R_igraph_layout_align(SEXP graph, SEXP layout) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_layout; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(layout, &c_layout)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_layout); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_layout_align(&c_graph, &c_layout)); + + /* Convert output */ + PROTECT(layout=Ry_igraph_matrix_to_SEXP(&c_layout)); + igraph_matrix_destroy(&c_layout); + IGRAPH_FINALLY_CLEAN(1); + r_result = layout; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_cocitation / +/-------------------------------------------*/ +SEXP R_igraph_cocitation(SEXP graph, SEXP vids) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_vids; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_cocitation(&c_graph, &c_res, c_vids)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_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_bibcoupling / +/-------------------------------------------*/ +SEXP R_igraph_bibcoupling(SEXP graph, SEXP vids) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_vids; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_bibcoupling(&c_graph, &c_res, c_vids)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_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_similarity_dice / +/-------------------------------------------*/ +SEXP R_igraph_similarity_dice(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_bool_t c_loops; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(res, &c_res)); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - IGRAPH_R_CHECK_BOOL(use_seed); - c_use_seed = LOGICAL(use_seed)[0]; - if (!Rf_isNull(distances)) { - Rz_SEXP_to_vector(distances, &c_distances); - } - IGRAPH_R_CHECK_REAL(min_dist); - c_min_dist = REAL(min_dist)[0]; - IGRAPH_R_CHECK_INT(epochs); - c_epochs = (igraph_integer_t) REAL(epochs)[0]; - IGRAPH_R_CHECK_BOOL(distances_are_weights); - c_distances_are_weights = LOGICAL(distances_are_weights)[0]; + igraph_vector_int_t c_vids_data; + Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_umap_3d(&c_graph, &c_res, c_use_seed, (Rf_isNull(distances) ? 0 : &c_distances), c_min_dist, c_epochs, c_distances_are_weights)); + IGRAPH_R_CHECK(igraph_similarity_dice(&c_graph, &c_res, c_vids, c_mode, c_loops)); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); igraph_matrix_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_vids_data); + igraph_vs_destroy(&c_vids); r_result = res; UNPROTECT(1); @@ -8004,67 +11282,88 @@ SEXP R_igraph_layout_umap_3d(SEXP graph, SEXP res, SEXP use_seed, SEXP distances } /*-------------------------------------------/ -/ igraph_layout_umap_compute_weights / +/ igraph_similarity_dice_es / /-------------------------------------------*/ -SEXP R_igraph_layout_umap_compute_weights(SEXP graph, SEXP distances, SEXP weights) { +SEXP R_igraph_similarity_dice_es(SEXP graph, SEXP es, SEXP mode, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_distances; - igraph_vector_t c_weights; + igraph_vector_t c_res; + igraph_es_t c_es; + igraph_neimode_t c_mode; + igraph_bool_t c_loops; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - Rz_SEXP_to_vector(distances, &c_distances); - IGRAPH_R_CHECK(Rz_SEXP_to_vector_copy(weights, &c_weights)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_weights); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_es_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_umap_compute_weights(&c_graph, &c_distances, &c_weights)); + IGRAPH_R_CHECK(igraph_similarity_dice_es(&c_graph, &c_res, c_es, c_mode, c_loops)); /* Convert output */ - PROTECT(weights=Ry_igraph_vector_to_SEXP(&c_weights)); - igraph_vector_destroy(&c_weights); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - r_result = weights; + igraph_vector_int_destroy(&c_es_data); + igraph_es_destroy(&c_es); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_layout_align / +/ igraph_similarity_dice_pairs / /-------------------------------------------*/ -SEXP R_igraph_layout_align(SEXP graph, SEXP layout) { +SEXP R_igraph_similarity_dice_pairs(SEXP graph, SEXP pairs, SEXP mode, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_matrix_t c_layout; + igraph_vector_t c_res; + igraph_vector_int_t c_pairs; + igraph_neimode_t c_mode; + igraph_bool_t c_loops; + SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_matrix_copy(layout, &c_layout)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_layout); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + Rz_SEXP_to_vector_int_copy(pairs, &c_pairs); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_pairs); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_layout_align(&c_graph, &c_layout)); + IGRAPH_R_CHECK(igraph_similarity_dice_pairs(&c_graph, &c_res, &c_pairs, c_mode, c_loops)); /* Convert output */ - PROTECT(layout=Ry_igraph_matrix_to_SEXP(&c_layout)); - igraph_matrix_destroy(&c_layout); + PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); + igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - r_result = layout; + igraph_vector_int_destroy(&c_pairs); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_cocitation / +/ igraph_similarity_inverse_log_weighted / /-------------------------------------------*/ -SEXP R_igraph_cocitation(SEXP graph, SEXP vids) { +SEXP R_igraph_similarity_inverse_log_weighted(SEXP graph, SEXP vids, SEXP mode) { /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; igraph_vs_t c_vids; + igraph_neimode_t c_mode; SEXP res; SEXP r_result; @@ -8074,8 +11373,9 @@ SEXP R_igraph_cocitation(SEXP graph, SEXP vids) { IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); igraph_vector_int_t c_vids_data; Rz_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_cocitation(&c_graph, &c_res, c_vids)); + IGRAPH_R_CHECK(igraph_similarity_inverse_log_weighted(&c_graph, &c_res, c_vids, c_mode)); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); @@ -8090,13 +11390,15 @@ SEXP R_igraph_cocitation(SEXP graph, SEXP vids) { } /*-------------------------------------------/ -/ igraph_bibcoupling / +/ igraph_similarity_jaccard / /-------------------------------------------*/ -SEXP R_igraph_bibcoupling(SEXP graph, SEXP vids) { +SEXP R_igraph_similarity_jaccard(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { /* Declarations */ igraph_t c_graph; igraph_matrix_t c_res; igraph_vs_t c_vids; + igraph_neimode_t c_mode; + igraph_bool_t c_loops; SEXP res; SEXP r_result; @@ -8106,8 +11408,11 @@ SEXP R_igraph_bibcoupling(SEXP graph, SEXP vids) { IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); igraph_vector_int_t c_vids_data; Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK_BOOL(loops); + c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_bibcoupling(&c_graph, &c_res, c_vids)); + IGRAPH_R_CHECK(igraph_similarity_jaccard(&c_graph, &c_res, c_vids, c_mode, c_loops)); /* Convert output */ PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); @@ -8122,13 +11427,13 @@ SEXP R_igraph_bibcoupling(SEXP graph, SEXP vids) { } /*-------------------------------------------/ -/ igraph_similarity_dice / +/ igraph_similarity_jaccard_es / /-------------------------------------------*/ -SEXP R_igraph_similarity_dice(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { +SEXP R_igraph_similarity_jaccard_es(SEXP graph, SEXP es, SEXP mode, SEXP loops) { /* Declarations */ igraph_t c_graph; - igraph_matrix_t c_res; - igraph_vs_t c_vids; + igraph_vector_t c_res; + igraph_es_t c_es; igraph_neimode_t c_mode; igraph_bool_t c_loops; SEXP res; @@ -8136,22 +11441,22 @@ SEXP R_igraph_similarity_dice(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); + IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_res); + igraph_vector_int_t c_es_data; + IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); c_mode = (igraph_neimode_t) Rf_asInteger(mode); IGRAPH_R_CHECK_BOOL(loops); c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_similarity_dice(&c_graph, &c_res, c_vids, c_mode, c_loops)); + IGRAPH_R_CHECK(igraph_similarity_jaccard_es(&c_graph, &c_res, c_es, c_mode, c_loops)); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + PROTECT(res=Ry_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); + igraph_vector_int_destroy(&c_es_data); + igraph_es_destroy(&c_es); r_result = res; UNPROTECT(1); @@ -8159,13 +11464,13 @@ SEXP R_igraph_similarity_dice(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { } /*-------------------------------------------/ -/ igraph_similarity_dice_es / +/ igraph_similarity_jaccard_pairs / /-------------------------------------------*/ -SEXP R_igraph_similarity_dice_es(SEXP graph, SEXP es, SEXP mode, SEXP loops) { +SEXP R_igraph_similarity_jaccard_pairs(SEXP graph, SEXP pairs, SEXP mode, SEXP loops) { /* Declarations */ igraph_t c_graph; igraph_vector_t c_res; - igraph_es_t c_es; + igraph_vector_int_t c_pairs; igraph_neimode_t c_mode; igraph_bool_t c_loops; SEXP res; @@ -8175,20 +11480,54 @@ SEXP R_igraph_similarity_dice_es(SEXP graph, SEXP es, SEXP mode, SEXP loops) { Rz_SEXP_to_igraph(graph, &c_graph); IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_es_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); + Rz_SEXP_to_vector_int_copy(pairs, &c_pairs); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_pairs); c_mode = (igraph_neimode_t) Rf_asInteger(mode); IGRAPH_R_CHECK_BOOL(loops); c_loops = LOGICAL(loops)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_similarity_dice_es(&c_graph, &c_res, c_es, c_mode, c_loops)); + IGRAPH_R_CHECK(igraph_similarity_jaccard_pairs(&c_graph, &c_res, &c_pairs, c_mode, c_loops)); /* Convert output */ PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); igraph_vector_destroy(&c_res); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_es_data); - igraph_es_destroy(&c_es); + igraph_vector_int_destroy(&c_pairs); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_compare_communities / +/-------------------------------------------*/ +SEXP R_igraph_compare_communities(SEXP comm1, SEXP comm2, SEXP method) { + /* Declarations */ + igraph_vector_int_t c_comm1; + igraph_vector_int_t c_comm2; + igraph_real_t c_res; + igraph_community_comparison_t c_method; + SEXP res; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(comm1, &c_comm1)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_comm1); + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(comm2, &c_comm2)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_comm2); + c_method = (igraph_community_comparison_t) Rf_asInteger(method); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_compare_communities(&c_comm1, &c_comm2, &c_res, c_method)); + + /* Convert output */ + igraph_vector_int_destroy(&c_comm1); + IGRAPH_FINALLY_CLEAN(1); + igraph_vector_int_destroy(&c_comm2); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; r_result = res; UNPROTECT(1); @@ -8196,216 +11535,517 @@ SEXP R_igraph_similarity_dice_es(SEXP graph, SEXP es, SEXP mode, SEXP loops) { } /*-------------------------------------------/ -/ igraph_similarity_dice_pairs / +/ igraph_community_spinglass / +/-------------------------------------------*/ +SEXP R_igraph_community_spinglass(SEXP graph, SEXP weights, SEXP spins, SEXP parupdate, SEXP starttemp, SEXP stoptemp, SEXP coolfact, SEXP update_rule, SEXP gamma, SEXP implementation, SEXP lambda) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_weights; + igraph_real_t c_modularity; + igraph_real_t c_temperature; + igraph_vector_int_t c_membership; + igraph_vector_int_t c_csize; + igraph_integer_t c_spins; + igraph_bool_t c_parupdate; + igraph_real_t c_starttemp; + igraph_real_t c_stoptemp; + igraph_real_t c_coolfact; + igraph_spincomm_update_t c_update_rule; + igraph_real_t c_gamma; + igraph_spinglass_implementation_t c_implementation; + igraph_real_t c_lambda; + SEXP modularity; + SEXP temperature; + SEXP membership; + SEXP csize; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_csize, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_csize); + IGRAPH_R_CHECK_INT(spins); + c_spins = (igraph_integer_t) REAL(spins)[0]; + IGRAPH_R_CHECK_BOOL(parupdate); + c_parupdate = LOGICAL(parupdate)[0]; + IGRAPH_R_CHECK_REAL(starttemp); + c_starttemp = REAL(starttemp)[0]; + IGRAPH_R_CHECK_REAL(stoptemp); + c_stoptemp = REAL(stoptemp)[0]; + IGRAPH_R_CHECK_REAL(coolfact); + c_coolfact = REAL(coolfact)[0]; + c_update_rule = (igraph_spincomm_update_t) Rf_asInteger(update_rule); + IGRAPH_R_CHECK_REAL(gamma); + c_gamma = REAL(gamma)[0]; + c_implementation = (igraph_spinglass_implementation_t) Rf_asInteger(implementation); + IGRAPH_R_CHECK_REAL(lambda); + c_lambda = REAL(lambda)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_community_spinglass(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_modularity, &c_temperature, &c_membership, &c_csize, c_spins, c_parupdate, c_starttemp, c_stoptemp, c_coolfact, c_update_rule, c_gamma, c_implementation, c_lambda)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(modularity=NEW_NUMERIC(1)); + REAL(modularity)[0]=c_modularity; + PROTECT(temperature=NEW_NUMERIC(1)); + REAL(temperature)[0]=c_temperature; + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(csize=Ry_igraph_vector_int_to_SEXP(&c_csize)); + igraph_vector_int_destroy(&c_csize); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, modularity); + SET_VECTOR_ELT(r_result, 1, temperature); + SET_VECTOR_ELT(r_result, 2, membership); + SET_VECTOR_ELT(r_result, 3, csize); + SET_STRING_ELT(r_names, 0, Rf_mkChar("modularity")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("temperature")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("membership")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("csize")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_community_spinglass_single / +/-------------------------------------------*/ +SEXP R_igraph_community_spinglass_single(SEXP graph, SEXP weights, SEXP vertex, SEXP spins, SEXP update_rule, SEXP gamma) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_weights; + igraph_integer_t c_vertex; + igraph_vector_int_t c_community; + igraph_real_t c_cohesion; + igraph_real_t c_adhesion; + igraph_integer_t c_inner_links; + igraph_integer_t c_outer_links; + igraph_integer_t c_spins; + igraph_spincomm_update_t c_update_rule; + igraph_real_t c_gamma; + SEXP community; + SEXP cohesion; + SEXP adhesion; + SEXP inner_links; + SEXP outer_links; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK_INT(vertex); + c_vertex = (igraph_integer_t) REAL(vertex)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_community, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_community); + c_inner_links=0; + c_outer_links=0; + IGRAPH_R_CHECK_INT(spins); + c_spins = (igraph_integer_t) REAL(spins)[0]; + c_update_rule = (igraph_spincomm_update_t) Rf_asInteger(update_rule); + IGRAPH_R_CHECK_REAL(gamma); + c_gamma = REAL(gamma)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_community_spinglass_single(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), c_vertex, &c_community, &c_cohesion, &c_adhesion, &c_inner_links, &c_outer_links, c_spins, c_update_rule, c_gamma)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(5)); + PROTECT(r_names=NEW_CHARACTER(5)); + PROTECT(community=Ry_igraph_vector_int_to_SEXP(&c_community)); + igraph_vector_int_destroy(&c_community); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(cohesion=NEW_NUMERIC(1)); + REAL(cohesion)[0]=c_cohesion; + PROTECT(adhesion=NEW_NUMERIC(1)); + REAL(adhesion)[0]=c_adhesion; + PROTECT(inner_links=NEW_NUMERIC(1)); + REAL(inner_links)[0]=(double) c_inner_links; + PROTECT(outer_links=NEW_NUMERIC(1)); + REAL(outer_links)[0]=(double) c_outer_links; + SET_VECTOR_ELT(r_result, 0, community); + SET_VECTOR_ELT(r_result, 1, cohesion); + SET_VECTOR_ELT(r_result, 2, adhesion); + SET_VECTOR_ELT(r_result, 3, inner_links); + SET_VECTOR_ELT(r_result, 4, outer_links); + SET_STRING_ELT(r_names, 0, Rf_mkChar("community")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("cohesion")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("adhesion")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("inner_links")); + SET_STRING_ELT(r_names, 4, Rf_mkChar("outer_links")); + SET_NAMES(r_result, r_names); + UNPROTECT(6); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_community_walktrap / /-------------------------------------------*/ -SEXP R_igraph_similarity_dice_pairs(SEXP graph, SEXP pairs, SEXP mode, SEXP loops) { +SEXP R_igraph_community_walktrap(SEXP graph, SEXP weights, SEXP steps) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_vector_int_t c_pairs; - igraph_neimode_t c_mode; - igraph_bool_t c_loops; - SEXP res; + igraph_vector_t c_weights; + igraph_integer_t c_steps; + igraph_matrix_int_t c_merges; + igraph_vector_t c_modularity; + igraph_vector_int_t c_membership; + SEXP merges; + SEXP modularity; + SEXP membership; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - Rz_SEXP_to_vector_int_copy(pairs, &c_pairs); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_pairs); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK_INT(steps); + c_steps = (igraph_integer_t) REAL(steps)[0]; + IGRAPH_R_CHECK(igraph_matrix_int_init(&c_merges, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_int_destroy, &c_merges); + IGRAPH_R_CHECK(igraph_vector_init(&c_modularity, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_modularity); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); /* Call igraph */ - IGRAPH_R_CHECK(igraph_similarity_dice_pairs(&c_graph, &c_res, &c_pairs, c_mode, c_loops)); + IGRAPH_R_CHECK(igraph_community_walktrap(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), c_steps, &c_merges, &c_modularity, &c_membership)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(merges=Ry_igraph_matrix_int_to_SEXP(&c_merges)); + igraph_matrix_int_destroy(&c_merges); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_pairs); + PROTECT(modularity=Ry_igraph_vector_to_SEXP(&c_modularity)); + igraph_vector_destroy(&c_modularity); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, merges); + SET_VECTOR_ELT(r_result, 1, modularity); + SET_VECTOR_ELT(r_result, 2, membership); + SET_STRING_ELT(r_names, 0, Rf_mkChar("merges")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("modularity")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("membership")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_similarity_inverse_log_weighted / +/ igraph_community_edge_betweenness / /-------------------------------------------*/ -SEXP R_igraph_similarity_inverse_log_weighted(SEXP graph, SEXP vids, SEXP mode) { +SEXP R_igraph_community_edge_betweenness(SEXP graph, SEXP directed, SEXP weights) { /* Declarations */ igraph_t c_graph; - igraph_matrix_t c_res; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - SEXP res; + igraph_vector_int_t c_removed_edges; + igraph_vector_t c_edge_betweenness; + igraph_matrix_int_t c_merges; + igraph_vector_int_t c_bridges; + igraph_vector_t c_modularity; + igraph_vector_int_t c_membership; + igraph_bool_t c_directed; + igraph_vector_t c_weights; + SEXP removed_edges; + SEXP edge_betweenness; + SEXP merges; + SEXP bridges; + SEXP modularity; + SEXP membership; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_removed_edges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_removed_edges); + IGRAPH_R_CHECK(igraph_vector_init(&c_edge_betweenness, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_edge_betweenness); + IGRAPH_R_CHECK(igraph_matrix_int_init(&c_merges, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_int_destroy, &c_merges); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_bridges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_bridges); + IGRAPH_R_CHECK(igraph_vector_init(&c_modularity, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_modularity); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } /* Call igraph */ - IGRAPH_R_CHECK(igraph_similarity_inverse_log_weighted(&c_graph, &c_res, c_vids, c_mode)); + IGRAPH_R_CHECK(igraph_community_edge_betweenness(&c_graph, &c_removed_edges, &c_edge_betweenness, &c_merges, &c_bridges, &c_modularity, &c_membership, c_directed, (Rf_isNull(weights) ? 0 : &c_weights))); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + PROTECT(r_result=NEW_LIST(6)); + PROTECT(r_names=NEW_CHARACTER(6)); + PROTECT(removed_edges=Ry_igraph_vector_int_to_SEXP(&c_removed_edges)); + igraph_vector_int_destroy(&c_removed_edges); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - r_result = res; + PROTECT(edge_betweenness=Ry_igraph_vector_to_SEXP(&c_edge_betweenness)); + igraph_vector_destroy(&c_edge_betweenness); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(merges=Ry_igraph_matrix_int_to_SEXP(&c_merges)); + igraph_matrix_int_destroy(&c_merges); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(bridges=Ry_igraph_vector_int_to_SEXPp1(&c_bridges)); + igraph_vector_int_destroy(&c_bridges); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(modularity=Ry_igraph_vector_to_SEXP(&c_modularity)); + igraph_vector_destroy(&c_modularity); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, removed_edges); + SET_VECTOR_ELT(r_result, 1, edge_betweenness); + SET_VECTOR_ELT(r_result, 2, merges); + SET_VECTOR_ELT(r_result, 3, bridges); + SET_VECTOR_ELT(r_result, 4, modularity); + SET_VECTOR_ELT(r_result, 5, membership); + SET_STRING_ELT(r_names, 0, Rf_mkChar("removed_edges")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("edge_betweenness")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("merges")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("bridges")); + SET_STRING_ELT(r_names, 4, Rf_mkChar("modularity")); + SET_STRING_ELT(r_names, 5, Rf_mkChar("membership")); + SET_NAMES(r_result, r_names); + UNPROTECT(7); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_similarity_jaccard / +/ igraph_community_eb_get_merges / /-------------------------------------------*/ -SEXP R_igraph_similarity_jaccard(SEXP graph, SEXP vids, SEXP mode, SEXP loops) { +SEXP R_igraph_community_eb_get_merges(SEXP graph, SEXP directed, SEXP edges, SEXP weights) { /* Declarations */ igraph_t c_graph; - igraph_matrix_t c_res; - igraph_vs_t c_vids; - igraph_neimode_t c_mode; - igraph_bool_t c_loops; - SEXP res; + igraph_bool_t c_directed; + igraph_vector_int_t c_edges; + igraph_vector_t c_weights; + igraph_matrix_int_t c_merges; + igraph_vector_int_t c_bridges; + igraph_vector_t c_modularity; + igraph_vector_int_t c_membership; + SEXP merges; + SEXP bridges; + SEXP modularity; + SEXP membership; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); - IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); - igraph_vector_int_t c_vids_data; - Rz_SEXP_to_igraph_vs(vids, &c_graph, &c_vids, &c_vids_data); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + Rz_SEXP_to_vector_int_copy(edges, &c_edges); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_edges); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK(igraph_matrix_int_init(&c_merges, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_int_destroy, &c_merges); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_bridges, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_bridges); + IGRAPH_R_CHECK(igraph_vector_init(&c_modularity, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_modularity); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); /* Call igraph */ - IGRAPH_R_CHECK(igraph_similarity_jaccard(&c_graph, &c_res, c_vids, c_mode, c_loops)); + IGRAPH_R_CHECK(igraph_community_eb_get_merges(&c_graph, c_directed, &c_edges, (Rf_isNull(weights) ? 0 : &c_weights), &c_merges, &c_bridges, &c_modularity, &c_membership)); /* Convert output */ - PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); - igraph_matrix_destroy(&c_res); + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + igraph_vector_int_destroy(&c_edges); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_vids_data); - igraph_vs_destroy(&c_vids); - r_result = res; + PROTECT(merges=Ry_igraph_matrix_int_to_SEXP(&c_merges)); + igraph_matrix_int_destroy(&c_merges); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(bridges=Ry_igraph_vector_int_to_SEXPp1(&c_bridges)); + igraph_vector_int_destroy(&c_bridges); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(modularity=Ry_igraph_vector_to_SEXP(&c_modularity)); + igraph_vector_destroy(&c_modularity); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, merges); + SET_VECTOR_ELT(r_result, 1, bridges); + SET_VECTOR_ELT(r_result, 2, modularity); + SET_VECTOR_ELT(r_result, 3, membership); + SET_STRING_ELT(r_names, 0, Rf_mkChar("merges")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("bridges")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("modularity")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("membership")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_similarity_jaccard_es / +/ igraph_community_fastgreedy / /-------------------------------------------*/ -SEXP R_igraph_similarity_jaccard_es(SEXP graph, SEXP es, SEXP mode, SEXP loops) { +SEXP R_igraph_community_fastgreedy(SEXP graph, SEXP weights) { /* Declarations */ igraph_t c_graph; - igraph_vector_t c_res; - igraph_es_t c_es; - igraph_neimode_t c_mode; - igraph_bool_t c_loops; - SEXP res; + igraph_vector_t c_weights; + igraph_matrix_int_t c_merges; + igraph_vector_t c_modularity; + igraph_vector_int_t c_membership; + SEXP merges; + SEXP modularity; + SEXP membership; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - igraph_vector_int_t c_es_data; - IGRAPH_R_CHECK(Rz_SEXP_to_igraph_es(es, &c_graph, &c_es, &c_es_data)); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK(igraph_matrix_int_init(&c_merges, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_int_destroy, &c_merges); + IGRAPH_R_CHECK(igraph_vector_init(&c_modularity, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_modularity); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); /* Call igraph */ - IGRAPH_R_CHECK(igraph_similarity_jaccard_es(&c_graph, &c_res, c_es, c_mode, c_loops)); + IGRAPH_R_CHECK(igraph_community_fastgreedy(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_merges, &c_modularity, &c_membership)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(merges=Ry_igraph_matrix_int_to_SEXP(&c_merges)); + igraph_matrix_int_destroy(&c_merges); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_es_data); - igraph_es_destroy(&c_es); - r_result = res; + PROTECT(modularity=Ry_igraph_vector_to_SEXP(&c_modularity)); + igraph_vector_destroy(&c_modularity); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, merges); + SET_VECTOR_ELT(r_result, 1, modularity); + SET_VECTOR_ELT(r_result, 2, membership); + SET_STRING_ELT(r_names, 0, Rf_mkChar("merges")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("modularity")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("membership")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_similarity_jaccard_pairs / +/ igraph_community_to_membership / /-------------------------------------------*/ -SEXP R_igraph_similarity_jaccard_pairs(SEXP graph, SEXP pairs, SEXP mode, SEXP loops) { +SEXP R_igraph_community_to_membership(SEXP merges, SEXP nodes, SEXP steps) { /* Declarations */ - igraph_t c_graph; - igraph_vector_t c_res; - igraph_vector_int_t c_pairs; - igraph_neimode_t c_mode; - igraph_bool_t c_loops; - SEXP res; + igraph_matrix_int_t c_merges; + igraph_integer_t c_nodes; + igraph_integer_t c_steps; + igraph_vector_int_t c_membership; + igraph_vector_int_t c_csize; + SEXP membership; + SEXP csize; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - Rz_SEXP_to_igraph(graph, &c_graph); - IGRAPH_R_CHECK(igraph_vector_init(&c_res, 0)); - IGRAPH_FINALLY(igraph_vector_destroy, &c_res); - Rz_SEXP_to_vector_int_copy(pairs, &c_pairs); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_pairs); - c_mode = (igraph_neimode_t) Rf_asInteger(mode); - IGRAPH_R_CHECK_BOOL(loops); - c_loops = LOGICAL(loops)[0]; + Rz_SEXP_to_matrix_int(merges, &c_merges); + IGRAPH_FINALLY(igraph_matrix_int_destroy, &c_merges); + IGRAPH_R_CHECK_INT(nodes); + c_nodes = (igraph_integer_t) REAL(nodes)[0]; + IGRAPH_R_CHECK_INT(steps); + c_steps = (igraph_integer_t) REAL(steps)[0]; + IGRAPH_R_CHECK(igraph_vector_int_init(&c_membership, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_csize, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_csize); /* Call igraph */ - IGRAPH_R_CHECK(igraph_similarity_jaccard_pairs(&c_graph, &c_res, &c_pairs, c_mode, c_loops)); + IGRAPH_R_CHECK(igraph_community_to_membership(&c_merges, c_nodes, c_steps, &c_membership, &c_csize)); /* Convert output */ - PROTECT(res=Ry_igraph_vector_to_SEXP(&c_res)); - igraph_vector_destroy(&c_res); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + igraph_matrix_int_destroy(&c_merges); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_pairs); + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); IGRAPH_FINALLY_CLEAN(1); - r_result = res; + PROTECT(csize=Ry_igraph_vector_int_to_SEXP(&c_csize)); + igraph_vector_int_destroy(&c_csize); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, membership); + SET_VECTOR_ELT(r_result, 1, csize); + SET_STRING_ELT(r_names, 0, Rf_mkChar("membership")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("csize")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); } /*-------------------------------------------/ -/ igraph_compare_communities / +/ igraph_le_community_to_membership / /-------------------------------------------*/ -SEXP R_igraph_compare_communities(SEXP comm1, SEXP comm2, SEXP method) { +SEXP R_igraph_le_community_to_membership(SEXP merges, SEXP steps, SEXP membership) { /* Declarations */ - igraph_vector_int_t c_comm1; - igraph_vector_int_t c_comm2; - igraph_real_t c_res; - igraph_community_comparison_t c_method; - SEXP res; + igraph_matrix_int_t c_merges; + igraph_integer_t c_steps; + igraph_vector_int_t c_membership; + igraph_vector_int_t c_csize; + SEXP csize; - SEXP r_result; + SEXP r_result, r_names; /* Convert input */ - IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(comm1, &c_comm1)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_comm1); - IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(comm2, &c_comm2)); - IGRAPH_FINALLY(igraph_vector_int_destroy, &c_comm2); - c_method = (igraph_community_comparison_t) Rf_asInteger(method); + Rz_SEXP_to_matrix_int(merges, &c_merges); + IGRAPH_FINALLY(igraph_matrix_int_destroy, &c_merges); + IGRAPH_R_CHECK_INT(steps); + c_steps = (igraph_integer_t) REAL(steps)[0]; + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(membership, &c_membership)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_csize, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_csize); /* Call igraph */ - IGRAPH_R_CHECK(igraph_compare_communities(&c_comm1, &c_comm2, &c_res, c_method)); + IGRAPH_R_CHECK(igraph_le_community_to_membership(&c_merges, c_steps, &c_membership, &c_csize)); /* Convert output */ - igraph_vector_int_destroy(&c_comm1); + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + igraph_matrix_int_destroy(&c_merges); IGRAPH_FINALLY_CLEAN(1); - igraph_vector_int_destroy(&c_comm2); + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); IGRAPH_FINALLY_CLEAN(1); - PROTECT(res=NEW_NUMERIC(1)); - REAL(res)[0]=c_res; - r_result = res; + PROTECT(csize=Ry_igraph_vector_int_to_SEXP(&c_csize)); + igraph_vector_int_destroy(&c_csize); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, membership); + SET_VECTOR_ELT(r_result, 1, csize); + SET_STRING_ELT(r_names, 0, Rf_mkChar("membership")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("csize")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); UNPROTECT(1); return(r_result); @@ -8487,6 +12127,51 @@ SEXP R_igraph_modularity_matrix(SEXP graph, SEXP weights, SEXP resolution, SEXP return(r_result); } +/*-------------------------------------------/ +/ igraph_reindex_membership / +/-------------------------------------------*/ +SEXP R_igraph_reindex_membership(SEXP membership) { + /* Declarations */ + igraph_vector_int_t c_membership; + igraph_vector_int_t c_new_to_old; + igraph_integer_t c_nb_clusters; + SEXP new_to_old; + SEXP nb_clusters; + + SEXP r_result, r_names; + /* Convert input */ + IGRAPH_R_CHECK(Rz_SEXP_to_vector_int_copy(membership, &c_membership)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_membership); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_new_to_old, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_new_to_old); + c_nb_clusters=0; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_reindex_membership(&c_membership, &c_new_to_old, &c_nb_clusters)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(membership=Ry_igraph_vector_int_to_SEXP(&c_membership)); + igraph_vector_int_destroy(&c_membership); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(new_to_old=Ry_igraph_vector_int_to_SEXPp1(&c_new_to_old)); + igraph_vector_int_destroy(&c_new_to_old); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(nb_clusters=NEW_NUMERIC(1)); + REAL(nb_clusters)[0]=(double) c_nb_clusters; + SET_VECTOR_ELT(r_result, 0, membership); + SET_VECTOR_ELT(r_result, 1, new_to_old); + SET_VECTOR_ELT(r_result, 2, nb_clusters); + SET_STRING_ELT(r_names, 0, Rf_mkChar("membership")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("new_to_old")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("nb_clusters")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_community_fluid_communities / /-------------------------------------------*/ @@ -8826,6 +12511,54 @@ SEXP R_igraph_community_infomap(SEXP graph, SEXP e_weights, SEXP v_weights, SEXP return(r_result); } +/*-------------------------------------------/ +/ igraph_graphlets / +/-------------------------------------------*/ +SEXP R_igraph_graphlets(SEXP graph, SEXP weights, SEXP niter) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_weights; + igraph_vector_int_list_t c_cliques; + igraph_vector_t c_Mu; + igraph_integer_t c_niter; + SEXP cliques; + SEXP Mu; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + IGRAPH_R_CHECK(igraph_vector_int_list_init(&c_cliques, 0)); + IGRAPH_FINALLY(igraph_vector_int_list_destroy, &c_cliques); + IGRAPH_R_CHECK(igraph_vector_init(&c_Mu, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_Mu); + IGRAPH_R_CHECK_INT(niter); + c_niter = (igraph_integer_t) REAL(niter)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_graphlets(&c_graph, (Rf_isNull(weights) ? 0 : &c_weights), &c_cliques, &c_Mu, c_niter)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(cliques=Ry_igraph_vector_int_list_to_SEXPp1(&c_cliques)); + igraph_vector_int_list_destroy(&c_cliques); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(Mu=Ry_igraph_vector_to_SEXP(&c_Mu)); + igraph_vector_destroy(&c_Mu); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, cliques); + SET_VECTOR_ELT(r_result, 1, Mu); + SET_STRING_ELT(r_names, 0, Rf_mkChar("cliques")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("Mu")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_graphlets_candidate_basis / /-------------------------------------------*/ @@ -9271,6 +13004,41 @@ SEXP R_igraph_from_hrg_dendrogram(SEXP hrg) { return(r_result); } +/*-------------------------------------------/ +/ igraph_get_adjacency / +/-------------------------------------------*/ +SEXP R_igraph_get_adjacency(SEXP graph, SEXP type, SEXP weights, SEXP loops) { + /* Declarations */ + igraph_t c_graph; + igraph_matrix_t c_res; + igraph_get_adjacency_t c_type; + igraph_vector_t c_weights; + igraph_loops_t c_loops; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_matrix_init(&c_res, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_res); + c_type = (igraph_get_adjacency_t) Rf_asInteger(type); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_loops = (igraph_loops_t) Rf_asInteger(loops); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_get_adjacency(&c_graph, &c_res, c_type, (Rf_isNull(weights) ? 0 : &c_weights), c_loops)); + + /* Convert output */ + PROTECT(res=Ry_igraph_matrix_to_SEXP(&c_res)); + igraph_matrix_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_get_adjacency_sparse / /-------------------------------------------*/ @@ -9461,6 +13229,113 @@ SEXP R_igraph_to_undirected(SEXP graph, SEXP mode, SEXP edge_attr_comb) { return(r_result); } +/*-------------------------------------------/ +/ igraph_read_graph_edgelist / +/-------------------------------------------*/ +SEXP R_igraph_read_graph_edgelist(SEXP instream, SEXP n, SEXP directed) { + /* Declarations */ + igraph_t c_graph; + FILE* c_instream; + igraph_integer_t c_n; + igraph_bool_t c_directed; + SEXP graph; + + SEXP r_result; + /* Convert input */ + c_instream = Ry_igraph_fopen_read(instream); + IGRAPH_FINALLY(fclose, c_instream); + IGRAPH_R_CHECK_INT(n); + c_n = (igraph_integer_t) REAL(n)[0]; + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_read_graph_edgelist(&c_graph, c_instream, c_n, c_directed)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_read_graph_ncol / +/-------------------------------------------*/ +SEXP R_igraph_read_graph_ncol(SEXP instream, SEXP predefnames, SEXP names, SEXP weights, SEXP directed) { + /* Declarations */ + igraph_t c_graph; + FILE* c_instream; + igraph_strvector_t c_predefnames; + igraph_bool_t c_names; + igraph_add_weights_t c_weights; + igraph_bool_t c_directed; + SEXP graph; + + SEXP r_result; + /* Convert input */ + c_instream = Ry_igraph_fopen_read(instream); + IGRAPH_FINALLY(fclose, c_instream); + if (!Rf_isNull(predefnames)) { + Rx_igraph_SEXP_to_strvector(predefnames, &c_predefnames); + } + IGRAPH_R_CHECK_BOOL(names); + c_names = LOGICAL(names)[0]; + c_weights = (igraph_add_weights_t) Rf_asInteger(weights); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_read_graph_ncol(&c_graph, c_instream, (Rf_isNull(predefnames) ? 0 : &c_predefnames), c_names, c_weights, c_directed)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_read_graph_lgl / +/-------------------------------------------*/ +SEXP R_igraph_read_graph_lgl(SEXP instream, SEXP names, SEXP weights, SEXP directed) { + /* Declarations */ + igraph_t c_graph; + FILE* c_instream; + igraph_bool_t c_names; + igraph_add_weights_t c_weights; + igraph_bool_t c_directed; + SEXP graph; + + SEXP r_result; + /* Convert input */ + c_instream = Ry_igraph_fopen_read(instream); + IGRAPH_FINALLY(fclose, c_instream); + IGRAPH_R_CHECK_BOOL(names); + c_names = LOGICAL(names)[0]; + c_weights = (igraph_add_weights_t) Rf_asInteger(weights); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_read_graph_lgl(&c_graph, c_instream, c_names, c_weights, c_directed)); + + /* Convert output */ + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_read_graph_pajek / /-------------------------------------------*/ @@ -9512,7 +13387,83 @@ SEXP R_igraph_read_graph_graphml(SEXP instream, SEXP index) { PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); IGRAPH_I_DESTROY(&c_graph); IGRAPH_FINALLY_CLEAN(1); - r_result = graph; + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_read_graph_dimacs_flow / +/-------------------------------------------*/ +SEXP R_igraph_read_graph_dimacs_flow(SEXP instream, SEXP directed) { + /* Declarations */ + igraph_t c_graph; + FILE* c_instream; + igraph_strvector_t c_problem; + igraph_vector_int_t c_label; + igraph_integer_t c_source; + igraph_integer_t c_target; + igraph_vector_t c_capacity; + igraph_bool_t c_directed; + SEXP graph; + SEXP problem; + SEXP label; + SEXP source; + SEXP target; + SEXP capacity; + + SEXP r_result, r_names; + /* Convert input */ + c_instream = Ry_igraph_fopen_read(instream); + IGRAPH_FINALLY(fclose, c_instream); + IGRAPH_R_CHECK(igraph_strvector_init(&c_problem, 0)); + IGRAPH_FINALLY(igraph_strvector_destroy, &c_problem); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_label, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_label); + c_source=0; + c_target=0; + IGRAPH_R_CHECK(igraph_vector_init(&c_capacity, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_capacity); + IGRAPH_R_CHECK_BOOL(directed); + c_directed = LOGICAL(directed)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_read_graph_dimacs_flow(&c_graph, c_instream, &c_problem, &c_label, &c_source, &c_target, &c_capacity, c_directed)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(6)); + PROTECT(r_names=NEW_CHARACTER(6)); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(problem=Rx_igraph_strvector_to_SEXP(&c_problem)); + igraph_strvector_destroy(&c_problem); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(label=Ry_igraph_vector_int_to_SEXP(&c_label)); + igraph_vector_int_destroy(&c_label); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(source=NEW_NUMERIC(1)); + REAL(source)[0]=(double) c_source; + PROTECT(target=NEW_NUMERIC(1)); + REAL(target)[0]=(double) c_target; + PROTECT(capacity=Ry_igraph_vector_to_SEXP(&c_capacity)); + igraph_vector_destroy(&c_capacity); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, graph); + SET_VECTOR_ELT(r_result, 1, problem); + SET_VECTOR_ELT(r_result, 2, label); + SET_VECTOR_ELT(r_result, 3, source); + SET_VECTOR_ELT(r_result, 4, target); + SET_VECTOR_ELT(r_result, 5, capacity); + SET_STRING_ELT(r_names, 0, Rf_mkChar("graph")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("problem")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("label")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("source")); + SET_STRING_ELT(r_names, 4, Rf_mkChar("target")); + SET_STRING_ELT(r_names, 5, Rf_mkChar("capacity")); + SET_NAMES(r_result, r_names); + UNPROTECT(7); UNPROTECT(1); return(r_result); @@ -9624,6 +13575,61 @@ SEXP R_igraph_write_graph_edgelist(SEXP graph, SEXP outstream) { + return(R_NilValue); +} + +/*-------------------------------------------/ +/ igraph_write_graph_ncol / +/-------------------------------------------*/ +SEXP R_igraph_write_graph_ncol(SEXP graph, SEXP outstream, SEXP names, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + FILE* c_outstream; + const char* c_names; + const char* c_weights; + + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_outstream = Ry_igraph_fopen_write(outstream); + IGRAPH_FINALLY(fclose, c_outstream); + c_names = Rf_translateCharUTF8(STRING_ELT(names, 0)); + c_weights = Rf_translateCharUTF8(STRING_ELT(weights, 0)); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_write_graph_ncol(&c_graph, c_outstream, c_names, c_weights)); + + /* Convert output */ + + + + return(R_NilValue); +} + +/*-------------------------------------------/ +/ igraph_write_graph_lgl / +/-------------------------------------------*/ +SEXP R_igraph_write_graph_lgl(SEXP graph, SEXP outstream, SEXP names, SEXP weights, SEXP isolates) { + /* Declarations */ + igraph_t c_graph; + FILE* c_outstream; + const char* c_names; + const char* c_weights; + igraph_bool_t c_isolates; + + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_outstream = Ry_igraph_fopen_write(outstream); + IGRAPH_FINALLY(fclose, c_outstream); + c_names = Rf_translateCharUTF8(STRING_ELT(names, 0)); + c_weights = Rf_translateCharUTF8(STRING_ELT(weights, 0)); + IGRAPH_R_CHECK_BOOL(isolates); + c_isolates = LOGICAL(isolates)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_write_graph_lgl(&c_graph, c_outstream, c_names, c_weights, c_isolates)); + + /* Convert output */ + + + return(R_NilValue); } @@ -9700,6 +13706,39 @@ SEXP R_igraph_write_graph_pajek(SEXP graph, SEXP outstream) { return(R_NilValue); } +/*-------------------------------------------/ +/ igraph_write_graph_dimacs_flow / +/-------------------------------------------*/ +SEXP R_igraph_write_graph_dimacs_flow(SEXP graph, SEXP outstream, SEXP source, SEXP target, SEXP capacity) { + /* Declarations */ + igraph_t c_graph; + FILE* c_outstream; + igraph_integer_t c_source; + igraph_integer_t c_target; + igraph_vector_t c_capacity; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph_copy(graph, &c_graph); + IGRAPH_FINALLY(igraph_destroy, &c_graph); + c_outstream = Ry_igraph_fopen_write(outstream); + IGRAPH_FINALLY(fclose, c_outstream); + c_source = (igraph_integer_t) REAL(source)[0]; + c_target = (igraph_integer_t) REAL(target)[0]; + Rz_SEXP_to_vector(capacity, &c_capacity); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_write_graph_dimacs_flow(&c_graph, c_outstream, c_source, c_target, &c_capacity)); + + /* Convert output */ + PROTECT(graph=Ry_igraph_to_SEXP(&c_graph)); + IGRAPH_I_DESTROY(&c_graph); + IGRAPH_FINALLY_CLEAN(1); + r_result = graph; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_write_graph_gml / /-------------------------------------------*/ @@ -10829,6 +14868,48 @@ SEXP R_igraph_maxflow(SEXP graph, SEXP source, SEXP target, SEXP capacity) { return(r_result); } +/*-------------------------------------------/ +/ igraph_maxflow_value / +/-------------------------------------------*/ +SEXP R_igraph_maxflow_value(SEXP graph, SEXP source, SEXP target, SEXP capacity) { + /* Declarations */ + igraph_t c_graph; + igraph_real_t c_value; + igraph_integer_t c_source; + igraph_integer_t c_target; + igraph_vector_t c_capacity; + igraph_maxflow_stats_t c_stats; + SEXP value; + SEXP stats; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_source = (igraph_integer_t) REAL(source)[0]; + c_target = (igraph_integer_t) REAL(target)[0]; + if (!Rf_isNull(capacity)) { + Rz_SEXP_to_vector(capacity, &c_capacity); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_maxflow_value(&c_graph, &c_value, c_source, c_target, (Rf_isNull(capacity) ? 0 : &c_capacity), &c_stats)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(2)); + PROTECT(r_names=NEW_CHARACTER(2)); + PROTECT(value=NEW_NUMERIC(1)); + REAL(value)[0]=c_value; + PROTECT(stats=Ry_igraph_maxflow_stats_to_SEXP(&c_stats)); + SET_VECTOR_ELT(r_result, 0, value); + SET_VECTOR_ELT(r_result, 1, stats); + SET_STRING_ELT(r_names, 0, Rf_mkChar("value")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("stats")); + SET_NAMES(r_result, r_names); + UNPROTECT(3); + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_mincut / /-------------------------------------------*/ @@ -11056,6 +15137,69 @@ SEXP R_igraph_st_mincut(SEXP graph, SEXP source, SEXP target, SEXP capacity) { return(r_result); } +/*-------------------------------------------/ +/ igraph_st_mincut_value / +/-------------------------------------------*/ +SEXP R_igraph_st_mincut_value(SEXP graph, SEXP source, SEXP target, SEXP capacity) { + /* Declarations */ + igraph_t c_graph; + igraph_real_t c_res; + igraph_integer_t c_source; + igraph_integer_t c_target; + igraph_vector_t c_capacity; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_source = (igraph_integer_t) REAL(source)[0]; + c_target = (igraph_integer_t) REAL(target)[0]; + if (!Rf_isNull(capacity)) { + Rz_SEXP_to_vector(capacity, &c_capacity); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_st_mincut_value(&c_graph, &c_res, c_source, c_target, (Rf_isNull(capacity) ? 0 : &c_capacity))); + + /* Convert output */ + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_st_vertex_connectivity / +/-------------------------------------------*/ +SEXP R_igraph_st_vertex_connectivity(SEXP graph, SEXP source, SEXP target, SEXP neighbors) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_res; + igraph_integer_t c_source; + igraph_integer_t c_target; + igraph_vconn_nei_t c_neighbors; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_res=0; + c_source = (igraph_integer_t) REAL(source)[0]; + c_target = (igraph_integer_t) REAL(target)[0]; + c_neighbors = (igraph_vconn_nei_t) Rf_asInteger(neighbors); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_st_vertex_connectivity(&c_graph, &c_res, c_source, c_target, c_neighbors)); + + /* Convert output */ + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=(double) c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_vertex_connectivity / /-------------------------------------------*/ @@ -11070,10 +15214,96 @@ SEXP R_igraph_vertex_connectivity(SEXP graph, SEXP checks) { /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); c_res=0; - IGRAPH_R_CHECK_BOOL(checks); - c_checks = LOGICAL(checks)[0]; + IGRAPH_R_CHECK_BOOL(checks); + c_checks = LOGICAL(checks)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_vertex_connectivity(&c_graph, &c_res, c_checks)); + + /* Convert output */ + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=(double) c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_st_edge_connectivity / +/-------------------------------------------*/ +SEXP R_igraph_st_edge_connectivity(SEXP graph, SEXP source, SEXP target) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_res; + igraph_integer_t c_source; + igraph_integer_t c_target; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_res=0; + c_source = (igraph_integer_t) REAL(source)[0]; + c_target = (igraph_integer_t) REAL(target)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_st_edge_connectivity(&c_graph, &c_res, c_source, c_target)); + + /* Convert output */ + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=(double) c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_edge_connectivity / +/-------------------------------------------*/ +SEXP R_igraph_edge_connectivity(SEXP graph, SEXP checks) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_res; + igraph_bool_t c_checks; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_res=0; + IGRAPH_R_CHECK_BOOL(checks); + c_checks = LOGICAL(checks)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_edge_connectivity(&c_graph, &c_res, c_checks)); + + /* Convert output */ + PROTECT(res=NEW_NUMERIC(1)); + REAL(res)[0]=(double) c_res; + r_result = res; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_edge_disjoint_paths / +/-------------------------------------------*/ +SEXP R_igraph_edge_disjoint_paths(SEXP graph, SEXP source, SEXP target) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_res; + igraph_integer_t c_source; + igraph_integer_t c_target; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + c_res=0; + c_source = (igraph_integer_t) REAL(source)[0]; + c_target = (igraph_integer_t) REAL(target)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_vertex_connectivity(&c_graph, &c_res, c_checks)); + IGRAPH_R_CHECK(igraph_edge_disjoint_paths(&c_graph, &c_res, c_source, c_target)); /* Convert output */ PROTECT(res=NEW_NUMERIC(1)); @@ -11085,23 +15315,24 @@ SEXP R_igraph_vertex_connectivity(SEXP graph, SEXP checks) { } /*-------------------------------------------/ -/ igraph_edge_connectivity / +/ igraph_vertex_disjoint_paths / /-------------------------------------------*/ -SEXP R_igraph_edge_connectivity(SEXP graph, SEXP checks) { +SEXP R_igraph_vertex_disjoint_paths(SEXP graph, SEXP source, SEXP target) { /* Declarations */ igraph_t c_graph; igraph_integer_t c_res; - igraph_bool_t c_checks; + igraph_integer_t c_source; + igraph_integer_t c_target; SEXP res; SEXP r_result; /* Convert input */ Rz_SEXP_to_igraph(graph, &c_graph); c_res=0; - IGRAPH_R_CHECK_BOOL(checks); - c_checks = LOGICAL(checks)[0]; + c_source = (igraph_integer_t) REAL(source)[0]; + c_target = (igraph_integer_t) REAL(target)[0]; /* Call igraph */ - IGRAPH_R_CHECK(igraph_edge_connectivity(&c_graph, &c_res, c_checks)); + IGRAPH_R_CHECK(igraph_vertex_disjoint_paths(&c_graph, &c_res, c_source, c_target)); /* Convert output */ PROTECT(res=NEW_NUMERIC(1)); @@ -12671,6 +16902,144 @@ SEXP R_igraph_maximum_bipartite_matching(SEXP graph, SEXP types, SEXP weights, S return(r_result); } +/*-------------------------------------------/ +/ igraph_adjacency_spectral_embedding / +/-------------------------------------------*/ +SEXP R_igraph_adjacency_spectral_embedding(SEXP graph, SEXP no, SEXP weights, SEXP which, SEXP scaled, SEXP cvec, SEXP options) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_no; + igraph_vector_t c_weights; + igraph_eigen_which_position_t c_which; + igraph_bool_t c_scaled; + igraph_matrix_t c_X; + igraph_matrix_t c_Y; + igraph_vector_t c_D; + igraph_vector_t c_cvec; + igraph_arpack_options_t c_options; + SEXP X; + SEXP Y; + SEXP D; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK_INT(no); + c_no = (igraph_integer_t) REAL(no)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_which=INTEGER(which)[0]; + IGRAPH_R_CHECK_BOOL(scaled); + c_scaled = LOGICAL(scaled)[0]; + IGRAPH_R_CHECK(igraph_matrix_init(&c_X, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_X); + IGRAPH_R_CHECK(igraph_matrix_init(&c_Y, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_Y); + IGRAPH_R_CHECK(igraph_vector_init(&c_D, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_D); + Rz_SEXP_to_vector(cvec, &c_cvec); + Rz_SEXP_to_igraph_arpack_options(options, &c_options); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_adjacency_spectral_embedding(&c_graph, c_no, (Rf_isNull(weights) ? 0 : &c_weights), c_which, c_scaled, &c_X, &c_Y, &c_D, &c_cvec, &c_options)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(X=Ry_igraph_matrix_to_SEXP(&c_X)); + igraph_matrix_destroy(&c_X); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(Y=Ry_igraph_matrix_to_SEXP(&c_Y)); + igraph_matrix_destroy(&c_Y); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(D=Ry_igraph_vector_to_SEXP(&c_D)); + igraph_vector_destroy(&c_D); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); + SET_VECTOR_ELT(r_result, 0, X); + SET_VECTOR_ELT(r_result, 1, Y); + SET_VECTOR_ELT(r_result, 2, D); + SET_VECTOR_ELT(r_result, 3, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("X")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("Y")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("D")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("options")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_laplacian_spectral_embedding / +/-------------------------------------------*/ +SEXP R_igraph_laplacian_spectral_embedding(SEXP graph, SEXP no, SEXP weights, SEXP which, SEXP type, SEXP scaled, SEXP options) { + /* Declarations */ + igraph_t c_graph; + igraph_integer_t c_no; + igraph_vector_t c_weights; + igraph_eigen_which_position_t c_which; + igraph_laplacian_spectral_embedding_type_t c_type; + igraph_bool_t c_scaled; + igraph_matrix_t c_X; + igraph_matrix_t c_Y; + igraph_vector_t c_D; + igraph_arpack_options_t c_options; + SEXP X; + SEXP Y; + SEXP D; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK_INT(no); + c_no = (igraph_integer_t) REAL(no)[0]; + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + c_which=INTEGER(which)[0]; + c_type = (igraph_laplacian_spectral_embedding_type_t) Rf_asInteger(type); + IGRAPH_R_CHECK_BOOL(scaled); + c_scaled = LOGICAL(scaled)[0]; + IGRAPH_R_CHECK(igraph_matrix_init(&c_X, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_X); + IGRAPH_R_CHECK(igraph_matrix_init(&c_Y, 0, 0)); + IGRAPH_FINALLY(igraph_matrix_destroy, &c_Y); + IGRAPH_R_CHECK(igraph_vector_init(&c_D, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_D); + Rz_SEXP_to_igraph_arpack_options(options, &c_options); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_laplacian_spectral_embedding(&c_graph, c_no, (Rf_isNull(weights) ? 0 : &c_weights), c_which, c_type, c_scaled, &c_X, &c_Y, &c_D, &c_options)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(4)); + PROTECT(r_names=NEW_CHARACTER(4)); + PROTECT(X=Ry_igraph_matrix_to_SEXP(&c_X)); + igraph_matrix_destroy(&c_X); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(Y=Ry_igraph_matrix_to_SEXP(&c_Y)); + igraph_matrix_destroy(&c_Y); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(D=Ry_igraph_vector_to_SEXP(&c_D)); + igraph_vector_destroy(&c_D); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(options=Ry_igraph_arpack_options_to_SEXP(&c_options)); + SET_VECTOR_ELT(r_result, 0, X); + SET_VECTOR_ELT(r_result, 1, Y); + SET_VECTOR_ELT(r_result, 2, D); + SET_VECTOR_ELT(r_result, 3, options); + SET_STRING_ELT(r_names, 0, Rf_mkChar("X")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("Y")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("D")); + SET_STRING_ELT(r_names, 3, Rf_mkChar("options")); + SET_NAMES(r_result, r_names); + UNPROTECT(5); + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_eigen_adjacency / /-------------------------------------------*/ @@ -12837,6 +17206,40 @@ SEXP R_igraph_running_mean(SEXP data, SEXP binwidth) { return(r_result); } +/*-------------------------------------------/ +/ igraph_random_sample / +/-------------------------------------------*/ +SEXP R_igraph_random_sample(SEXP l, SEXP h, SEXP length) { + /* Declarations */ + igraph_vector_int_t c_res; + igraph_integer_t c_l; + igraph_integer_t c_h; + igraph_integer_t c_length; + SEXP res; + + SEXP r_result; + /* Convert input */ + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + IGRAPH_R_CHECK_INT(l); + c_l = (igraph_integer_t) REAL(l)[0]; + IGRAPH_R_CHECK_INT(h); + c_h = (igraph_integer_t) REAL(h)[0]; + IGRAPH_R_CHECK_INT(length); + c_length = (igraph_integer_t) REAL(length)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_random_sample(&c_res, c_l, c_h, c_length)); + + /* Convert output */ + PROTECT(res=Ry_igraph_vector_int_to_SEXP(&c_res)); + igraph_vector_int_destroy(&c_res); + IGRAPH_FINALLY_CLEAN(1); + r_result = res; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_convex_hull_2d / /-------------------------------------------*/ @@ -12903,6 +17306,54 @@ SEXP R_igraph_dim_select(SEXP sv) { return(r_result); } +/*-------------------------------------------/ +/ igraph_almost_equals / +/-------------------------------------------*/ +SEXP R_igraph_almost_equals(SEXP a, SEXP b, SEXP eps) { + /* Declarations */ + double c_a; + double c_b; + double c_eps; + igraph_bool_t c_result; + SEXP r_result; + /* Convert input */ + + /* Call igraph */ + c_result=igraph_almost_equals(c_a, c_b, c_eps); + + /* Convert output */ + + PROTECT(r_result=NEW_LOGICAL(1)); + LOGICAL(r_result)[0]=c_result; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_cmp_epsilon / +/-------------------------------------------*/ +SEXP R_igraph_cmp_epsilon(SEXP a, SEXP b, SEXP eps) { + /* Declarations */ + double c_a; + double c_b; + double c_eps; + int c_result; + SEXP r_result; + /* Convert input */ + + /* Call igraph */ + c_result=igraph_cmp_epsilon(c_a, c_b, c_eps); + + /* Convert output */ + + PROTECT(r_result=NEW_INTEGER(1)); + INTEGER(r_result)[0]=(int) c_result; + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_solve_lsap / /-------------------------------------------*/ @@ -13409,6 +17860,37 @@ SEXP R_igraph_is_complete(SEXP graph) { return(r_result); } +/*-------------------------------------------/ +/ igraph_minimum_spanning_tree / +/-------------------------------------------*/ +SEXP R_igraph_minimum_spanning_tree(SEXP graph, SEXP weights) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_int_t c_res; + igraph_vector_t c_weights; + SEXP res; + + SEXP r_result; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_int_init(&c_res, 0)); + IGRAPH_FINALLY(igraph_vector_int_destroy, &c_res); + if (!Rf_isNull(weights)) { + Rz_SEXP_to_vector(weights, &c_weights); + } + /* Call igraph */ + IGRAPH_R_CHECK(igraph_minimum_spanning_tree(&c_graph, &c_res, (Rf_isNull(weights) ? 0 : &c_weights))); + + /* Convert output */ + PROTECT(res=Ry_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_minimum_spanning_tree_unweighted / /-------------------------------------------*/ @@ -13797,6 +18279,141 @@ SEXP R_igraph_stochastic_imitation(SEXP graph, SEXP vid, SEXP algo, SEXP quantit return(r_result); } +/*-------------------------------------------/ +/ igraph_convergence_degree / +/-------------------------------------------*/ +SEXP R_igraph_convergence_degree(SEXP graph) { + /* Declarations */ + igraph_t c_graph; + igraph_vector_t c_result; + igraph_vector_t c_in; + igraph_vector_t c_out; + SEXP result; + SEXP in; + SEXP out; + + SEXP r_result, r_names; + /* Convert input */ + Rz_SEXP_to_igraph(graph, &c_graph); + IGRAPH_R_CHECK(igraph_vector_init(&c_result, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_result); + IGRAPH_R_CHECK(igraph_vector_init(&c_in, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_in); + IGRAPH_R_CHECK(igraph_vector_init(&c_out, 0)); + IGRAPH_FINALLY(igraph_vector_destroy, &c_out); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_convergence_degree(&c_graph, &c_result, &c_in, &c_out)); + + /* Convert output */ + PROTECT(r_result=NEW_LIST(3)); + PROTECT(r_names=NEW_CHARACTER(3)); + PROTECT(result=Ry_igraph_vector_to_SEXP(&c_result)); + igraph_vector_destroy(&c_result); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(in=Ry_igraph_vector_to_SEXP(&c_in)); + igraph_vector_destroy(&c_in); + IGRAPH_FINALLY_CLEAN(1); + PROTECT(out=Ry_igraph_vector_to_SEXP(&c_out)); + igraph_vector_destroy(&c_out); + IGRAPH_FINALLY_CLEAN(1); + SET_VECTOR_ELT(r_result, 0, result); + SET_VECTOR_ELT(r_result, 1, in); + SET_VECTOR_ELT(r_result, 2, out); + SET_STRING_ELT(r_names, 0, Rf_mkChar("result")); + SET_STRING_ELT(r_names, 1, Rf_mkChar("in")); + SET_STRING_ELT(r_names, 2, Rf_mkChar("out")); + SET_NAMES(r_result, r_names); + UNPROTECT(4); + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_has_attribute_table / +/-------------------------------------------*/ +SEXP R_igraph_has_attribute_table(void) { + /* Declarations */ + igraph_bool_t c_result; + SEXP r_result; + /* Convert input */ + + /* Call igraph */ + c_result=igraph_has_attribute_table(); + + /* Convert output */ + + PROTECT(r_result=NEW_LOGICAL(1)); + LOGICAL(r_result)[0]=c_result; + + UNPROTECT(1); + return(r_result); +} + +/*-------------------------------------------/ +/ igraph_progress / +/-------------------------------------------*/ +SEXP R_igraph_progress(SEXP message, SEXP percent) { + /* Declarations */ + const char* c_message; + igraph_real_t c_percent; + + + /* Convert input */ + c_message = Rf_translateCharUTF8(STRING_ELT(message, 0)); + IGRAPH_R_CHECK_REAL(percent); + c_percent = REAL(percent)[0]; + /* Call igraph */ + IGRAPH_R_CHECK(igraph_progress(c_message, c_percent, 0)); + + /* Convert output */ + + + + return(R_NilValue); +} + +/*-------------------------------------------/ +/ igraph_status / +/-------------------------------------------*/ +SEXP R_igraph_status(SEXP message) { + /* Declarations */ + const char* c_message; + + + /* Convert input */ + c_message = Rf_translateCharUTF8(STRING_ELT(message, 0)); + /* Call igraph */ + IGRAPH_R_CHECK(igraph_status(c_message, 0)); + + /* Convert output */ + + + + return(R_NilValue); +} + +/*-------------------------------------------/ +/ igraph_strerror / +/-------------------------------------------*/ +SEXP R_igraph_strerror(SEXP igraph_errno) { + /* Declarations */ + igraph_error_t c_igraph_errno; + const char* c_result; + SEXP r_result; + /* Convert input */ + + /* Call igraph */ + c_result=igraph_strerror(c_igraph_errno); + + /* Convert output */ + + PROTECT(r_result = Rf_ScalarString(Rf_mkCharLenCE(c_result, strlen(c_result), CE_UTF8))); + + UNPROTECT(1); + return(r_result); +} + /*-------------------------------------------/ / igraph_expand_path_to_pairs / /-------------------------------------------*/ diff --git a/tests/testthat/_snaps/aaa-auto.md b/tests/testthat/_snaps/aaa-auto.md index 26e86730a0..d724e68b6c 100644 --- a/tests/testthat/_snaps/aaa-auto.md +++ b/tests/testthat/_snaps/aaa-auto.md @@ -856,6 +856,16 @@ + edges: [1] 1--2 1--2 2--3 1--3 1--4 2--4 1--5 4--5 +--- + + Code + growing_random_game_impl(n = 10, m = 1, directed = TRUE, citation = FALSE) + Output + IGRAPH D--- 10 9 -- Growing random graph + + attr: name (g/c), m (g/n), citation (g/l) + + edges: + [1] 2->2 2->3 4->4 4->4 3->2 1->3 1->8 5->6 5->4 + # growing_random_game_impl errors Code @@ -1402,6 +1412,21 @@ [1] TRUE +--- + + Code + closeness_impl(graph = g, vids = V(g), mode = c("out", "in", "all", "total")) + Output + $res + [1] 0.1666667 0.1666667 0.1666667 0.1666667 0.1666667 + + $reachable_count + [1] 4 4 4 4 4 + + $all_reachable + [1] TRUE + + # closeness_impl errors Code @@ -1596,6 +1621,18 @@ [1] 0 1 2 +--- + + Code + voronoi_impl(graph = g, generators = c(1, 5), mode = c("out", "in", "all")) + Output + $membership + [1] 0 0 0 1 1 1 1 1 0 0 + + $distances + [1] 0 1 2 1 0 1 2 3 2 1 + + # voronoi_impl errors Code @@ -1708,6 +1745,14 @@ + 2/2 edges: [1] 1--2 2--3 +--- + + Code + spanner_impl(graph = g, stretch = 2) + Output + + 5/5 edges: + [1] 1--2 2--3 3--4 4--5 1--5 + # spanner_impl errors Code @@ -1753,6 +1798,13 @@ Output [1] 2 2 +--- + + Code + edge_betweenness_impl(graph = g, directed = FALSE) + Output + [1] 4 4 4 4 + # edge_betweenness_impl errors Code @@ -4884,6 +4936,18 @@ [2,] -0.4861377 0.8738822 0 [3,] 0.0000000 0.0000000 1 +--- + + Code + layout_sphere_impl(graph = g) + Output + [,1] [,2] [,3] + [1,] 0.0000000 0.0000000 -1.0 + [2,] -0.2461774 0.8302992 -0.5 + [3,] -0.9468790 -0.3215901 0.0 + [4,] 0.5001161 -0.7070246 0.5 + [5,] 0.0000000 0.0000000 1.0 + # layout_sphere_impl errors Code @@ -5334,6 +5398,13 @@ Output [1] 1 +--- + + Code + compare_communities_impl(comm1 = comm1, comm2 = comm2, method = "vi") + Output + [1] 0.5493061 + # compare_communities_impl errors Code @@ -7651,7 +7722,10 @@ [3,] 0.6718598 -0.4487712 $Y - NULL + [,1] [,2] + [1,] 0.6718598 -0.4487712 + [2,] 1.1328501 0.5323058 + [3,] 0.6718598 -0.4487712 $D [1] 2.1861407 -0.6861407 @@ -7732,7 +7806,10 @@ [3,] 0.7563200 0.4912963 $Y - NULL + [,1] [,2] + [1,] 0.1720265 -0.7864357 + [2,] 0.6311790 -0.3743620 + [3,] 0.7563200 0.4912963 $D [1] 4.669079 1.476024 @@ -7820,7 +7897,10 @@ [3,] -0.7071068 0.7071068 $Y - NULL + [,1] [,2] + [1,] -0.7071068 -0.7071068 + [2,] 1.4142136 0.0000000 + [3,] -0.7071068 0.7071068 $D [1] 3 1 @@ -10416,3 +10496,688 @@ Error in `ensure_igraph()`: ! Must provide a graph object (provided `NULL`). +# star_impl basic + + Code + star_impl(n = 5, mode = "out", center = 0) + Output + IGRAPH D--- 5 4 -- + + edges: + [1] 1->2 1->3 1->4 1->5 + +--- + + Code + star_impl(n = 6, mode = "in", center = 1) + Output + IGRAPH D--- 6 5 -- + + edges: + [1] 1->2 3->2 4->2 5->2 6->2 + +--- + + Code + star_impl(n = 4, mode = "undirected", center = 0) + Output + IGRAPH U--- 4 3 -- + + edges: + [1] 1--2 1--3 1--4 + +# ring_impl basic + + Code + ring_impl(n = 5, directed = FALSE, mutual = FALSE, circular = TRUE) + Output + IGRAPH U--- 5 5 -- + + edges: + [1] 1--2 2--3 3--4 4--5 1--5 + +--- + + Code + ring_impl(n = 4, directed = TRUE, mutual = FALSE, circular = FALSE) + Output + IGRAPH D--- 4 3 -- + + edges: + [1] 1->2 2->3 3->4 + +# full_impl basic + + Code + full_impl(n = 4, directed = FALSE, loops = FALSE) + Output + IGRAPH U--- 4 6 -- + + edges: + [1] 1--2 1--3 1--4 2--3 2--4 3--4 + +--- + + Code + full_impl(n = 3, directed = TRUE, loops = FALSE) + Output + IGRAPH D--- 3 6 -- + + edges: + [1] 1->2 1->3 2->1 2->3 3->1 3->2 + +# kary_tree_impl basic + + Code + kary_tree_impl(n = 7, children = 2, type = c("out", "in", "undirected")) + Output + IGRAPH D--- 7 6 -- + + edges: + [1] 1->2 1->3 2->4 2->5 3->6 3->7 + +--- + + Code + kary_tree_impl(n = 10, children = 3, type = c("in", "out", "undirected")) + Output + IGRAPH D--- 10 9 -- + + edges: + [1] 2->1 3->1 4->1 5->2 6->2 7->2 8->3 9->3 10->3 + +# barabasi_game_impl basic + + Code + barabasi_game_impl(n = 10, power = 1, m = 2, directed = FALSE, algo = "bag") + Output + IGRAPH U--- 10 18 -- + + edges: + [1] 1-- 2 1-- 2 2-- 3 1-- 3 2-- 4 2-- 4 2-- 5 2-- 5 4-- 6 2-- 6 2-- 7 1-- 7 + [13] 3-- 8 2-- 8 8-- 9 5-- 9 6--10 5--10 + +--- + + Code + barabasi_game_impl(n = 10, power = 1, m = 2, directed = FALSE, algo = "psumtree") + Output + IGRAPH U--- 10 17 -- + + edges: + [1] 1-- 2 1-- 3 2-- 3 1-- 4 2-- 4 2-- 5 4-- 5 1-- 6 3-- 6 6-- 7 3-- 7 6-- 8 + [13] 2-- 8 3-- 9 5-- 9 2--10 6--10 + +# grg_game_impl basic + + Code + grg_game_impl(nodes = 10, radius = 0.3, torus = FALSE) + Output + $graph + IGRAPH U--- 10 12 -- + + edges: + [1] 3-- 5 3-- 6 5-- 6 5-- 7 5-- 8 6-- 8 7-- 8 7-- 9 7--10 8-- 9 8--10 9--10 + + $x + [1] 0.08565451 0.15145413 0.45222514 0.45939554 0.55956278 0.61872370 + [7] 0.76201957 0.82545284 0.86690370 0.95857358 + + $y + [1] 0.07820721 0.85018913 0.08700766 0.73223568 0.33212277 0.14562638 + [7] 0.53326474 0.32235478 0.49679861 0.31410636 + + +# watts_strogatz_game_impl basic + + Code + watts_strogatz_game_impl(dim = 1, size = 10, nei = 2, p = 0.1) + Output + IGRAPH U--- 10 20 -- + + edges: + [1] 1-- 2 2-- 6 2-- 3 4-- 5 5-- 6 6-- 7 7-- 8 8-- 9 9--10 1--10 1-- 8 1-- 9 + [13] 2--10 2-- 4 3-- 5 4-- 6 5-- 7 6-- 8 7-- 9 8--10 + +# distances_impl basic + + Code + distances_impl(graph = g, from = V(g), to = V(g), mode = c("out", "in", "all", + "total")) + Output + [,1] [,2] [,3] [,4] [,5] + [1,] 0 1 2 2 1 + [2,] 1 0 1 2 2 + [3,] 2 1 0 1 2 + [4,] 2 2 1 0 1 + [5,] 1 2 2 1 0 + +# diameter_impl basic + + Code + diameter_impl(graph = g, directed = FALSE, unconnected = TRUE) + Output + $res + [1] 5 + + $from + [1] 0 + + $to + [1] 5 + + $vertex_path + [1] 0 1 2 3 4 5 + + $edge_path + [1] 0 1 2 3 4 + + +# get_shortest_paths_impl basic + + Code + get_shortest_paths_impl(graph = g, from = 1, to = 3, mode = c("out", "in", + "all", "total")) + Output + $vertices + $vertices[[1]] + + 3/5 vertices: + [1] 1 2 3 + + + $edges + $edges[[1]] + + 2/5 edges: + [1] 1--2 2--3 + + + $parents + [1] -1 0 1 -2 0 + + $inbound_edges + [1] -1 0 1 -1 4 + + +# subcomponent_impl basic + + Code + subcomponent_impl(graph = g, v = 1, mode = c("all", "out", "in")) + Output + + 3/6 vertices, named: + [1] A B C + +# betweenness_impl basic + + Code + betweenness_impl(graph = g, vids = V(g), directed = FALSE) + Output + [1] 6 0 0 0 0 + +# harmonic_centrality_impl basic + + Code + harmonic_centrality_impl(graph = g, vids = V(g), mode = c("out", "in", "all", + "total")) + Output + [1] 4.0 2.5 2.5 2.5 2.5 + +# pagerank_impl basic + + Code + pagerank_impl(graph = g, vids = V(g), directed = TRUE, damping = 0.85) + Output + $vector + [1] 0.2 0.2 0.2 0.2 0.2 + + $value + [1] 1 + + $options + NULL + + +# hub_score_impl basic + + Code + hub_score_impl(graph = g, scale = TRUE, weights = NULL) + Output + $vector + [1] 1.0000000 0.2500078 0.2500078 0.2500078 0.2500078 + + $value + [1] 4 + + $options + $options$bmat + [1] "I" + + $options$n + [1] 5 + + $options$which + [1] "LA" + + $options$nev + [1] 1 + + $options$tol + [1] 0 + + $options$ncv + [1] 0 + + $options$ldv + [1] 0 + + $options$ishift + [1] 1 + + $options$maxiter + [1] 3000 + + $options$nb + [1] 1 + + $options$mode + [1] 1 + + $options$start + [1] 1 + + $options$sigma + [1] 0 + + $options$sigmai + [1] 0 + + $options$info + [1] 0 + + $options$iter + [1] 1 + + $options$nconv + [1] 1 + + $options$numop + [1] 4 + + $options$numopb + [1] 0 + + $options$numreo + [1] 4 + + + +# authority_score_impl basic + + Code + authority_score_impl(graph = g, scale = TRUE, weights = NULL) + Output + $vector + [1] 1.0000000 0.9999686 0.9999686 0.9999686 0.9999686 + + $value + [1] 4 + + $options + $options$bmat + [1] "I" + + $options$n + [1] 5 + + $options$which + [1] "LA" + + $options$nev + [1] 1 + + $options$tol + [1] 0 + + $options$ncv + [1] 0 + + $options$ldv + [1] 0 + + $options$ishift + [1] 1 + + $options$maxiter + [1] 3000 + + $options$nb + [1] 1 + + $options$mode + [1] 1 + + $options$start + [1] 1 + + $options$sigma + [1] 0 + + $options$sigmai + [1] 0 + + $options$info + [1] 0 + + $options$iter + [1] 1 + + $options$nconv + [1] 1 + + $options$numop + [1] 4 + + $options$numopb + [1] 0 + + $options$numreo + [1] 4 + + + +# community_walktrap_impl basic + + Code + community_walktrap_impl(graph = g, steps = 4) + Output + $merges + [,1] [,2] + [1,] 4 5 + [2,] 1 2 + [3,] 3 6 + [4,] 0 7 + [5,] 8 9 + + $modularity + [1] -0.17346939 -0.07142857 0.03061224 0.19387755 0.35714286 0.00000000 + + $membership + [1] 0 0 0 1 1 1 + + +# community_fastgreedy_impl basic + + Code + community_fastgreedy_impl(graph = g) + Output + $merges + [,1] [,2] + [1,] 2 1 + [2,] 0 6 + [3,] 5 4 + [4,] 3 8 + [5,] 9 7 + + $modularity + [1] -1.734694e-01 -7.142857e-02 9.183673e-02 1.938776e-01 3.571429e-01 + [6] 5.551115e-17 + + $membership + [1] 1 1 1 0 0 0 + + +# community_edge_betweenness_impl basic + + Code + community_edge_betweenness_impl(graph = g, directed = FALSE) + Output + $removed_edges + [1] 2 0 1 3 4 5 6 + + $edge_betweenness + [1] 9 1 2 1 1 2 1 + + $merges + [,1] [,2] + [1,] 5 4 + [2,] 6 3 + [3,] 2 1 + [4,] 8 0 + [5,] 7 9 + + $bridges + [1] 7 6 4 3 1 + + $modularity + [1] -0.17346939 -0.07142857 0.09183673 0.19387755 0.35714286 0.00000000 + + $membership + [1] 0 0 0 1 1 1 + + +# edge_connectivity_impl basic + + Code + edge_connectivity_impl(graph = g) + Output + [1] 2 + +# vertex_connectivity_impl basic + + Code + vertex_connectivity_impl(graph = g) + Output + [1] 2 + +# create_bipartite_impl basic + + Code + create_bipartite_impl(types = c(FALSE, FALSE, TRUE, TRUE), edges = c(0, 2, 0, 3, + 1, 2, 1, 3), directed = FALSE) + Output + IGRAPH U--- 4 4 -- + + edges: + [1] 1--3 1--4 2--3 2--4 + +# bipartite_game_impl basic + + Code + bipartite_game_impl(type = "gnp", n1 = 5, n2 = 5, p = 0.3, directed = FALSE) + Output + $graph + IGRAPH U--- 10 10 -- + + edges: + [1] 1-- 6 2-- 6 4-- 6 5-- 6 1-- 7 4-- 7 4-- 8 3-- 9 3--10 4--10 + + $types + [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE + + +--- + + Code + bipartite_game_impl(type = "gnm", n1 = 5, n2 = 5, m = 10, directed = FALSE) + Output + $graph + IGRAPH U--- 10 10 -- + + edges: + [1] 1-- 6 3-- 7 5-- 7 1-- 8 3-- 8 4-- 8 2-- 9 5-- 9 2--10 3--10 + + $types + [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE + + +# decompose_impl basic + + Code + decompose_impl(graph = g, mode = c("weak", "strong")) + Output + [[1]] + IGRAPH UN-- 3 2 -- + + attr: name (v/c) + + edges (vertex names): + [1] A--B B--C + + [[2]] + IGRAPH UN-- 2 1 -- + + attr: name (v/c) + + edge (vertex names): + [1] D--E + + +# neighborhood_impl basic + + Code + neighborhood_impl(graph = g, order = 1, vids = V(g), mode = c("all", "out", + "in")) + Output + [[1]] + + 3/5 vertices: + [1] 1 2 5 + + [[2]] + + 3/5 vertices: + [1] 2 1 3 + + [[3]] + + 3/5 vertices: + [1] 3 2 4 + + [[4]] + + 3/5 vertices: + [1] 4 3 5 + + [[5]] + + 3/5 vertices: + [1] 5 1 4 + + +# neighborhood_size_impl basic + + Code + neighborhood_size_impl(graph = g, order = 1, vids = V(g), mode = c("all", "out", + "in")) + Output + [1] 3 3 3 3 3 + +# get_adjacency_impl basic + + Code + get_adjacency_impl(graph = g, type = c("both", "upper", "lower")) + Output + [,1] [,2] [,3] + [1,] 0 1 1 + [2,] 1 0 1 + [3,] 1 1 0 + +# write_graph_edgelist_impl basic + + Code + content + Output + [1] "0 1" "0 2" "1 2" + +# read_graph_edgelist_impl basic + + Code + read_graph_edgelist_impl(instream = tmp, n = 3, directed = FALSE) + Output + IGRAPH U--- 3 3 -- + + edges: + [1] 1--2 2--3 1--3 + +# degree_sequence_game_impl basic + + Code + degree_sequence_game_impl(out_deg = c(2, 2, 2, 2), method = "configuration") + Output + IGRAPH U--- 4 4 -- + + edges: + [1] 2--4 3--3 1--4 1--2 + +--- + + Code + degree_sequence_game_impl(out_deg = c(2, 2, 2, 2), method = "vl") + Output + IGRAPH U--- 4 4 -- + + edges: + [1] 1--2 1--4 2--3 3--4 + +# connect_neighborhood_impl basic + + Code + connect_neighborhood_impl(graph = g, order = 1, mode = c("all", "out", "in")) + Condition + Warning in `connect_neighborhood_impl()`: + At vendor/cigraph/src/operators/connect_neighborhood.c:85 : Order smaller than two, graph will be unchanged. + Output + IGRAPH U--- 5 5 -- Ring graph + + attr: name (g/c), mutual (g/l), circular (g/l) + + edges: + [1] 1--2 2--3 3--4 4--5 1--5 + +# eccentricity_impl basic + + Code + eccentricity_impl(graph = g, vids = V(g), mode = c("out", "in", "all")) + Output + [1] 2 2 2 2 2 + +# radius_impl basic + + Code + radius_impl(graph = g, mode = c("out", "in", "all")) + Output + [1] 2 + +# graph_center_impl basic + + Code + graph_center_impl(graph = g, mode = c("out", "in", "all")) + Output + + 1/5 vertex: + [1] 1 + +# maximal_cliques_impl basic + + Code + maximal_cliques_impl(graph = g, min_size = 1, max_size = 0) + Output + [[1]] + + 4/4 vertices: + [1] 1 2 4 3 + + +# independent_vertex_sets_impl basic + + Code + independent_vertex_sets_impl(graph = g, min_size = 1, max_size = 0) + Output + [[1]] + + 1/5 vertex: + [1] 1 + + [[2]] + + 1/5 vertex: + [1] 2 + + [[3]] + + 1/5 vertex: + [1] 3 + + [[4]] + + 1/5 vertex: + [1] 4 + + [[5]] + + 1/5 vertex: + [1] 5 + + [[6]] + + 2/5 vertices: + [1] 1 3 + + [[7]] + + 2/5 vertices: + [1] 1 4 + + [[8]] + + 2/5 vertices: + [1] 2 4 + + [[9]] + + 2/5 vertices: + [1] 2 5 + + [[10]] + + 2/5 vertices: + [1] 3 5 + + diff --git a/tests/testthat/test-aaa-auto.R b/tests/testthat/test-aaa-auto.R index 1b59cb8883..f5f344cadb 100644 --- a/tests/testthat/test-aaa-auto.R +++ b/tests/testthat/test-aaa-auto.R @@ -10618,3 +10618,484 @@ test_that("intersection_impl errors", { right = NULL )) }) + + +# Tests for newly autogenerated _impl functions + +# Graph constructors + +test_that("star_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(star_impl(n = 5, mode = "out", center = 0)) + expect_snapshot(star_impl(n = 6, mode = "in", center = 1)) + expect_snapshot(star_impl(n = 4, mode = "undirected", center = 0)) +}) + +test_that("ring_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(ring_impl( + n = 5, + directed = FALSE, + mutual = FALSE, + circular = TRUE + )) + expect_snapshot(ring_impl( + n = 4, + directed = TRUE, + mutual = FALSE, + circular = FALSE + )) +}) + +test_that("full_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(full_impl(n = 4, directed = FALSE, loops = FALSE)) + expect_snapshot(full_impl(n = 3, directed = TRUE, loops = FALSE)) +}) + +test_that("kary_tree_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(kary_tree_impl( + n = 7, + children = 2, + type = c("out", "in", "undirected") + )) + expect_snapshot(kary_tree_impl( + n = 10, + children = 3, + type = c("in", "out", "undirected") + )) +}) + +# Random graph generators + +test_that("barabasi_game_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(barabasi_game_impl( + n = 10, + power = 1, + m = 2, + directed = FALSE, + algo = "bag" + )) + expect_snapshot(barabasi_game_impl( + n = 10, + power = 1, + m = 2, + directed = FALSE, + algo = "psumtree" + )) +}) + +test_that("growing_random_game_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(growing_random_game_impl( + n = 10, + m = 1, + directed = TRUE, + citation = FALSE + )) +}) + +test_that("grg_game_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(grg_game_impl(nodes = 10, radius = 0.3, torus = FALSE)) +}) + +test_that("watts_strogatz_game_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(watts_strogatz_game_impl( + dim = 1, + size = 10, + nei = 2, + p = 0.1 + )) +}) + +# Distance and path functions + +test_that("distances_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(distances_impl( + graph = g, + from = V(g), + to = V(g), + mode = c("out", "in", "all", "total") + )) +}) + +test_that("diameter_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(10) + expect_snapshot(diameter_impl( + graph = g, + directed = FALSE, + unconnected = TRUE + )) +}) + +test_that("get_shortest_paths_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(get_shortest_paths_impl( + graph = g, + from = 1, + to = 3, + mode = c("out", "in", "all", "total") + )) +}) + +test_that("subcomponent_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_graph(~ A-B-C, D-E-F) + expect_snapshot(subcomponent_impl( + graph = g, + v = 1, + mode = c("all", "out", "in") + )) +}) + +# Centrality measures + +test_that("betweenness_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_star(5, mode = "undirected") + expect_snapshot(betweenness_impl(graph = g, vids = V(g), directed = FALSE)) +}) + +test_that("closeness_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(closeness_impl( + graph = g, + vids = V(g), + mode = c("out", "in", "all", "total") + )) +}) + +test_that("harmonic_centrality_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_star(5, mode = "undirected") + expect_snapshot(harmonic_centrality_impl( + graph = g, + vids = V(g), + mode = c("out", "in", "all", "total") + )) +}) + +test_that("pagerank_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5, directed = TRUE) + expect_snapshot(pagerank_impl( + graph = g, + vids = V(g), + directed = TRUE, + damping = 0.85 + )) +}) + +test_that("hub_score_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_star(5, mode = "undirected") + expect_snapshot(hub_score_impl(graph = g, scale = TRUE, weights = NULL)) +}) + +test_that("authority_score_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_star(5, mode = "undirected") + expect_snapshot(authority_score_impl(graph = g, scale = TRUE, weights = NULL)) +}) + +# Community detection + +test_that("community_walktrap_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_graph(~ A-B-C-A, D-E-F-D, A-D) + expect_snapshot(community_walktrap_impl(graph = g, steps = 4)) +}) + +test_that("community_fastgreedy_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_graph(~ A-B-C-A, D-E-F-D, A-D) + expect_snapshot(community_fastgreedy_impl(graph = g)) +}) + +test_that("community_edge_betweenness_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_graph(~ A-B-C-A, D-E-F-D, A-D) + expect_snapshot(community_edge_betweenness_impl(graph = g, directed = FALSE)) +}) + +# Connectivity + +test_that("edge_connectivity_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(edge_connectivity_impl(graph = g)) +}) + +test_that("vertex_connectivity_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(vertex_connectivity_impl(graph = g)) +}) + +# Layout functions + +test_that("layout_sphere_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(layout_sphere_impl(graph = g)) +}) + +# Bipartite functions + +test_that("create_bipartite_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(create_bipartite_impl( + types = c(FALSE, FALSE, TRUE, TRUE), + edges = c(0, 2, 0, 3, 1, 2, 1, 3), + directed = FALSE + )) +}) + +test_that("bipartite_game_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(bipartite_game_impl( + type = "gnp", + n1 = 5, + n2 = 5, + p = 0.3, + directed = FALSE + )) + expect_snapshot(bipartite_game_impl( + type = "gnm", + n1 = 5, + n2 = 5, + m = 10, + directed = FALSE + )) +}) + +# Other structural functions + +test_that("decompose_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_graph(~ A-B-C, D-E) + expect_snapshot(decompose_impl(graph = g, mode = c("weak", "strong"))) +}) + +test_that("neighborhood_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(neighborhood_impl( + graph = g, + order = 1, + vids = V(g), + mode = c("all", "out", "in") + )) +}) + +test_that("neighborhood_size_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(neighborhood_size_impl( + graph = g, + order = 1, + vids = V(g), + mode = c("all", "out", "in") + )) +}) + +# Graph properties + +test_that("is_chordal_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + # is_chordal_impl has a bug where optional INDEX_VECTOR parameters + # cannot be NULL - they are always passed to C even when NULL + # This needs to be fixed in the generator or function spec + skip("is_chordal_impl has bug with optional INDEX_VECTOR parameters") +}) + +test_that("get_adjacency_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(3) + expect_snapshot(get_adjacency_impl( + graph = g, + type = c("both", "upper", "lower") + )) +}) + +# IO functions + +test_that("write_graph_edgelist_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(3) + tmp <- tempfile() + write_graph_edgelist_impl(graph = g, outstream = tmp) + content <- readLines(tmp) + unlink(tmp) + expect_snapshot(content) +}) + +test_that("read_graph_edgelist_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + tmp <- tempfile() + writeLines(c("0 1", "1 2", "2 0"), tmp) + expect_snapshot(read_graph_edgelist_impl( + instream = tmp, + n = 3, + directed = FALSE + )) + unlink(tmp) +}) + +# Utility functions + +test_that("compare_communities_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + comm1 <- c(1, 1, 2, 2, 3, 3) + comm2 <- c(1, 1, 2, 2, 2, 3) + expect_snapshot(compare_communities_impl( + comm1 = comm1, + comm2 = comm2, + method = "vi" + )) +}) + +# Additional game functions + +test_that("degree_sequence_game_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + expect_snapshot(degree_sequence_game_impl( + out_deg = c(2, 2, 2, 2), + method = "configuration" + )) + expect_snapshot(degree_sequence_game_impl( + out_deg = c(2, 2, 2, 2), + method = "vl" + )) +}) + +test_that("connect_neighborhood_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(connect_neighborhood_impl( + graph = g, + order = 1, + mode = c("all", "out", "in") + )) +}) + +# Additional distance functions + +test_that("eccentricity_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(eccentricity_impl( + graph = g, + vids = V(g), + mode = c("out", "in", "all") + )) +}) + +test_that("radius_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(radius_impl(graph = g, mode = c("out", "in", "all"))) +}) + +test_that("graph_center_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_star(5, mode = "undirected") + expect_snapshot(graph_center_impl(graph = g, mode = c("out", "in", "all"))) +}) + +test_that("voronoi_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(10) + expect_snapshot(voronoi_impl( + graph = g, + generators = c(1, 5), + mode = c("out", "in", "all") + )) +}) + +# Spanner + +test_that("spanner_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(spanner_impl(graph = g, stretch = 2)) +}) + +# Additional centrality + +test_that("edge_betweenness_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_star(5, mode = "undirected") + expect_snapshot(edge_betweenness_impl(graph = g, directed = FALSE)) +}) + +# Maximal cliques + +test_that("maximal_cliques_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_full_graph(4) + expect_snapshot(maximal_cliques_impl(graph = g, min_size = 1, max_size = 0)) +}) + +test_that("independent_vertex_sets_impl basic", { + withr::local_seed(20250909) + local_igraph_options(print.id = FALSE) + g <- make_ring(5) + expect_snapshot(independent_vertex_sets_impl( + graph = g, + min_size = 1, + max_size = 0 + )) +}) diff --git a/tools/stimulus/functions-R.yaml b/tools/stimulus/functions-R.yaml index 917483d006..680a954703 100644 --- a/tools/stimulus/functions-R.yaml +++ b/tools/stimulus/functions-R.yaml @@ -12,7 +12,6 @@ # Not needed in R, we use igraph_emtpy() instead igraph_empty_attrs: - IGNORE: RR, RC igraph_add_vertices: @@ -27,15 +26,15 @@ igraph_is_directed: igraph_degree: igraph_edge: - IGNORE: RR, RC, RInit igraph_edges: igraph_get_eid: + # Needs custom handling - OUT parameter eid should be scalar not vector IGNORE: RR, RC, RInit igraph_get_eids: - IGNORE: RR, RC, RInit + DEPS: pairs ON graph, eids ON graph igraph_get_all_eids_between: # This is a temporary hack; we need to find a way to handle default values @@ -47,12 +46,10 @@ igraph_get_all_eids_between: igraph_incident: igraph_is_same_graph: - IGNORE: RR, RC, RInit # Not needed in R; we can simply compare things in the R layer without # calling into C igraph_create: - IGNORE: RR, RC ####################################### # Constructors, deterministic @@ -60,34 +57,27 @@ igraph_create: # TODO: temporarily disabled igraph_adjacency: - IGNORE: RR -# TODO: temporarily disabled +# TODO: temporarily disabled - needs SPARSEMAT converter implementation igraph_sparse_adjacency: IGNORE: RR, RC -# TODO: temporarily disabled +# TODO: temporarily disabled - needs SPARSEMAT converter implementation igraph_sparse_weighted_adjacency: IGNORE: RR, RC # TODO: temporarily disabled igraph_weighted_adjacency: - IGNORE: RR igraph_star: - IGNORE: RR, RC igraph_ring: - IGNORE: RR, RC igraph_kary_tree: - IGNORE: RR, RC igraph_full: - IGNORE: RR, RC igraph_connect_neighborhood: - IGNORE: RR, RC igraph_famous: @@ -133,6 +123,7 @@ igraph_turan: # TODO: temporarily disabled igraph_weighted_sparsemat: + # Needs SPARSEMAT converter implementation IGNORE: RR, RC ####################################### @@ -140,10 +131,8 @@ igraph_weighted_sparsemat: ####################################### igraph_barabasi_game: - IGNORE: RR, RC igraph_degree_sequence_game: - IGNORE: RR, RC igraph_growing_random_game: PARAMS: |- @@ -155,34 +144,24 @@ igraph_growing_random_game: GATTR-PARAM: m, citation igraph_barabasi_aging_game: - IGNORE: RR, RC igraph_recent_degree_game: - IGNORE: RR, RC igraph_recent_degree_aging_game: - IGNORE: RR, RC igraph_callaway_traits_game: - IGNORE: RR, RC igraph_establishment_game: - IGNORE: RR, RC igraph_grg_game: - IGNORE: RR, RC, RInit igraph_watts_strogatz_game: - IGNORE: RR, RC igraph_lastcit_game: - IGNORE: RR, RC igraph_cited_type_game: - IGNORE: RR, RC igraph_citing_cited_type_game: - IGNORE: RR, RC igraph_forest_fire_game: R: @@ -246,29 +225,22 @@ igraph_correlated_game: # Deprecated in C core igraph_are_connected: - IGNORE: RR, RC ####################################### # Structural properties ####################################### igraph_diameter: - IGNORE: RR, RC, RInit igraph_diameter_dijkstra: - IGNORE: RR, RC, RInit igraph_distances: - IGNORE: RR, RC igraph_distances_cutoff: - IGNORE: RR, RC igraph_get_shortest_path_astar: - IGNORE: RR, RC, Rinit igraph_get_shortest_paths: - IGNORE: RR, RC, RInit igraph_get_all_shortest_paths: PARAM_NAMES: @@ -276,16 +248,12 @@ igraph_get_all_shortest_paths: edges: epaths igraph_distances_dijkstra: - IGNORE: RR, RC igraph_distances_dijkstra_cutoff: - IGNORE: RR, RC igraph_get_shortest_paths_dijkstra: - IGNORE: RR, RC, RInit igraph_get_shortest_paths_bellman_ford: - IGNORE: RR, RC, RInit igraph_get_all_shortest_paths_dijkstra: PARAM_NAMES: @@ -293,13 +261,10 @@ igraph_get_all_shortest_paths_dijkstra: edges: epaths igraph_distances_bellman_ford: - IGNORE: RR, RC igraph_distances_johnson: - IGNORE: RR, RC igraph_distances_floyd_warshall: - IGNORE: RR, RC igraph_voronoi: FIRST_KW_PARAM: weights @@ -345,21 +310,17 @@ igraph_spanner: DEPS: weights ON graph, spanner ON graph igraph_subcomponent: - IGNORE: RR, RC igraph_betweenness: - IGNORE: RR, RC igraph_betweenness_subset: DEPS: |- vids ON graph, weights ON graph, res ON graph vids, sources ON graph, targets ON graph igraph_harmonic_centrality: - IGNORE: RR, RC, RInit # This is handled by igraph_harmonic_centrality_cutoff igraph_pagerank: - IGNORE: RR, RC, RInit igraph_personalized_pagerank_vs: DEPS: vids ON graph, weights ON graph, vector ON graph vids, @@ -371,7 +332,6 @@ igraph_rewire: mode: 0L igraph_average_path_length: - IGNORE: RR, RC, RInit # No need for it, igraph_average_path_length_dijkstra takes care of the # unweighted case as well @@ -388,13 +348,10 @@ igraph_maxdegree: vids: v igraph_neighborhood_size: - IGNORE: RR, RC, RInit igraph_neighborhood: - IGNORE: RR, RC, RInit igraph_neighborhood_graphs: - IGNORE: RR, RC igraph_topological_sorting: @@ -413,7 +370,6 @@ igraph_count_multiple: igraph_girth: igraph_add_edge: - IGNORE: RR, RC, RInit igraph_chung_lu_game: PARAMS: |- @@ -432,10 +388,10 @@ igraph_eigenvector_centrality: DEPS: weights ON graph, vector ON graph V(graph) igraph_hub_score: - IGNORE: RR, RC + DEPS: weights ON graph, vector ON graph V(graph) igraph_authority_score: - IGNORE: RR, RC + DEPS: weights ON graph, vector ON graph V(graph) igraph_hub_and_authority_scores: # This is a temporary hack; we need to find a way to handle default values @@ -452,25 +408,21 @@ igraph_is_mutual: es: eids igraph_is_chordal: - IGNORE: RR, RC, RInit # We use igraph_eccentricity_dijkstra instead igraph_eccentricity: - IGNORE: RR, RC 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: - IGNORE: RR, RC igraph_radius_dijkstra: FIRST_KW_PARAM: weights @@ -485,26 +437,26 @@ igraph_random_walk: PARAM_ORDER: graph, start, steps, ... igraph_random_edge_walk: - IGNORE: RR, RC ####################################### # Degree sequences ####################################### igraph_is_bigraphical: - IGNORE: RR, RC, RInit ####################################### # Visitors ####################################### igraph_bfs: + # Has callback parameter (BFS_FUNC) IGNORE: RR, RC, RInit igraph_bfs_simple: DEPS: root ON graph, order ON graph igraph_dfs: + # Has callback parameter (DFS_FUNC) IGNORE: RR, RC, RInit ####################################### @@ -526,10 +478,9 @@ igraph_bipartite_projection_size: ####################################### igraph_bipartite_projection: - IGNORE: RR, RC, RInit igraph_create_bipartite: - IGNORE: RR + DEPS: types ON res$graph V(res$graph) igraph_biadjacency: DEPS: types ON res$graph V(res$graph) @@ -552,7 +503,7 @@ igraph_bipartite_game_gnm: NEIMODE mode=ALL igraph_bipartite_game: - IGNORE: RR, RC + DEPS: types ON res$graph V(res$graph) igraph_full_bipartite: DEPS: types ON res$graph @@ -571,7 +522,6 @@ igraph_full_bipartite: ####################################### igraph_decompose: - IGNORE: RR, RC ####################################### # Cliques @@ -591,11 +541,9 @@ igraph_clique_size_hist: INTERNAL: true igraph_maximal_cliques: - IGNORE: RR, RC, RInit # TODO: temporarily disabled igraph_maximal_cliques_subset: - IGNORE: RR, RC igraph_maximal_cliques_callback: IGNORE: RR, RC, RInit @@ -603,7 +551,6 @@ igraph_maximal_cliques_callback: igraph_maximal_cliques_count: igraph_maximal_cliques_file: - IGNORE: RR, RC, RInit igraph_maximal_cliques_hist: # Wrapper function is hand-rolled in the R layer; the generated version @@ -611,7 +558,6 @@ igraph_maximal_cliques_hist: INTERNAL: true igraph_independent_vertex_sets: - IGNORE: RR, RC igraph_largest_independent_vertex_sets: @@ -624,36 +570,54 @@ igraph_independence_number: ####################################### igraph_layout_fruchterman_reingold: - IGNORE: RR, RC, RInit + PARAMS: |- + GRAPH graph, OPTIONAL INOUT MATRIX coords, + BOOLEAN use_seed=FALSE, INTEGER niter=500, + REAL start_temp=sqrt(vcount(graph)), + LAYOUT_GRID grid=AUTO, OPTIONAL EDGEWEIGHTS weights, + OPTIONAL VECTOR minx, OPTIONAL VECTOR maxx, + OPTIONAL VECTOR miny, OPTIONAL VECTOR maxy, + DEPRECATED coolexp=NULL, DEPRECATED maxdelta=NULL, DEPRECATED area=NULL, + DEPRECATED repulserad=NULL + DEPS: weights ON graph igraph_layout_kamada_kawai: - IGNORE: RR, RC, RInit igraph_layout_lgl: - IGNORE: RR, RC + PARAMS: |- + GRAPH graph, OUT MATRIX res, INTEGER maxiter=150, REAL maxdelta=vcount(graph), + REAL area=vcount(graph)^2, REAL coolexp=1.5, REAL repulserad=vcount(graph)^3, REAL cellsize=vcount(graph), + INTEGER root=-1 igraph_layout_reingold_tilford: - IGNORE: RR, RC, RInit igraph_layout_reingold_tilford_circular: - IGNORE: RR, RC, RInit igraph_layout_fruchterman_reingold_3d: - IGNORE: RR, RC, RInit + PARAMS: |- + GRAPH graph, OPTIONAL INOUT MATRIX coords, + BOOLEAN use_seed=FALSE, INTEGER niter=500, + REAL start_temp=sqrt(vcount(graph)), + OPTIONAL EDGEWEIGHTS weights, + OPTIONAL VECTOR minx, OPTIONAL VECTOR maxx, + OPTIONAL VECTOR miny, OPTIONAL VECTOR maxy, + OPTIONAL VECTOR minz, OPTIONAL VECTOR maxz, + DEPRECATED coolexp=NULL, DEPRECATED maxdelta=NULL, DEPRECATED area=NULL, + DEPRECATED repulserad=NULL + DEPS: weights ON graph igraph_layout_kamada_kawai_3d: - IGNORE: RR, RC, RInit igraph_layout_graphopt: - IGNORE: RR, RC, RInit igraph_layout_drl: - IGNORE: RR + DEPS: weights ON graph igraph_layout_drl_3d: - IGNORE: RR + DEPS: weights ON graph igraph_layout_merge_dla: + # Needs custom handling - GRAPH_PTR_LIST type not properly supported IGNORE: RR, RC ####################################### @@ -669,38 +633,32 @@ igraph_bibcoupling: ####################################### igraph_community_spinglass: - IGNORE: RR, RC, RInit igraph_community_spinglass_single: - IGNORE: RR, RC, RInit igraph_community_walktrap: - IGNORE: RR, RC, RInit igraph_community_edge_betweenness: - IGNORE: RR, RC, RInit igraph_community_eb_get_merges: - IGNORE: RR, RC, RInit + DEPS: edges ON graph, weights ON graph igraph_community_fastgreedy: - IGNORE: RR, RC, RInit igraph_community_to_membership: - IGNORE: RR, RC, RInit igraph_le_community_to_membership: - IGNORE: RR, RC, RInit igraph_reindex_membership: - IGNORE: RR, RC, RInit igraph_community_leading_eigenvector: + # Needs custom handling - has callback parameter (LEVCFUNC) IGNORE: RR, RC, RInit R: CLASS: igraph.eigenc igraph_community_voronoi: + # Needs custom handling - optional pointer parameter generates incorrect conditional IGNORE: RR, RC, RInit ####################################### @@ -708,7 +666,6 @@ igraph_community_voronoi: ####################################### igraph_graphlets: - IGNORE: RC igraph_graphlets_candidate_basis: @@ -734,7 +691,6 @@ igraph_hrg_create: ####################################### igraph_get_adjacency: - IGNORE: RR, RC igraph_get_edgelist: @@ -747,13 +703,15 @@ igraph_to_directed: ####################################### igraph_read_graph_edgelist: - IGNORE: RR, RC igraph_read_graph_ncol: - IGNORE: RR, RC + PARAMS: |- + INFILE instream, OPTIONAL VECTOR_STR predefnames, BOOLEAN names=TRUE, + ADD_WEIGHTS weights=TRUE, BOOLEAN directed=TRUE igraph_read_graph_lgl: - IGNORE: RR, RC + PARAMS: |- + INFILE instream, BOOLEAN names=TRUE, ADD_WEIGHTS weights=TRUE, BOOLEAN directed=TRUE igraph_read_graph_pajek: @@ -761,7 +719,6 @@ igraph_read_graph_graphml: # TODO: temporarily disabled igraph_read_graph_dimacs_flow: - IGNORE: RR, RC igraph_read_graph_graphdb: @@ -772,10 +729,8 @@ igraph_read_graph_dl: igraph_write_graph_edgelist: igraph_write_graph_ncol: - IGNORE: RR, RC igraph_write_graph_lgl: - IGNORE: RR, RC igraph_write_graph_leda: @@ -785,7 +740,7 @@ igraph_write_graph_pajek: # TODO: temporarily disabled igraph_write_graph_dimacs_flow: - IGNORE: RR, RC + DEPS: source ON graph, target ON graph PARAMS: |- INOUT GRAPH graph, OUTFILE outstream, VERTEX source=0, VERTEX target=0, VECTOR capacity @@ -803,16 +758,19 @@ igraph_write_graph_dot: igraph_disjoint_union: igraph_disjoint_union_many: + # Needs custom handling - GRAPH_PTR_LIST const pointer issue IGNORE: RR, RC, RInit igraph_union: igraph_union_many: + # Needs custom handling - GRAPH_PTR_LIST const pointer issue IGNORE: RR, RC, RInit igraph_intersection: igraph_intersection_many: + # Needs custom handling - GRAPH_PTR_LIST const pointer issue IGNORE: RR, RC, RInit igraph_difference: @@ -826,30 +784,24 @@ igraph_compose: ####################################### igraph_maxflow_value: - IGNORE: RR, RC, RInit igraph_mincut: igraph_mincut_value: igraph_st_mincut_value: - IGNORE: RR, RC igraph_st_vertex_connectivity: - IGNORE: RR, RC, RInit igraph_vertex_connectivity: igraph_st_edge_connectivity: - IGNORE: RR, RC igraph_edge_connectivity: igraph_edge_disjoint_paths: - IGNORE: RR, RC igraph_vertex_disjoint_paths: - IGNORE: RR, RC igraph_adhesion: @@ -880,8 +832,8 @@ igraph_get_subisomorphisms_vf2_callback: IGNORE: RR, RC igraph_subisomorphic_lad: + # R function is hand-rolled - C signature changed, needs manual update IGNORE: RR, RC, RInit - # R function is hand-rolled # Despite their names, vertex_color and edge_color are not really colors # but _multiplicities_, so we simply use VECTOR_INT there PARAMS: |- @@ -896,10 +848,8 @@ igraph_subisomorphic_lad: ####################################### igraph_adjacency_spectral_embedding: - IGNORE: RC igraph_laplacian_spectral_embedding: - IGNORE: RC ####################################### # Eigensolvers @@ -924,22 +874,20 @@ igraph_sir: igraph_running_mean: igraph_random_sample: - IGNORE: RR, RC # Not needed in R igraph_almost_equals: - IGNORE: RR, RC # Not needed in R igraph_cmp_epsilon: - IGNORE: RR, RC # TODO: temporarily disabled igraph_eigen_matrix: + # TODO: temporarily disabled - missing SPARSEMAT converter IGNORE: RR, RC -# TODO: temporarily disabled igraph_eigen_matrix_symmetric: + # TODO: temporarily disabled - missing SPARSEMAT converter IGNORE: RR, RC ####################################### @@ -999,7 +947,6 @@ igraph_from_prufer: GATTR-PARAM: prufer igraph_minimum_spanning_tree: - IGNORE: RR, RC, RInit igraph_minimum_spanning_tree_unweighted: @@ -1028,31 +975,26 @@ igraph_moran_process: ####################################### igraph_convergence_degree: - IGNORE: RR, RC, RInit # Not needed in R igraph_has_attribute_table: - IGNORE: RR, RC ####################################### # Progress, status handling ####################################### igraph_progress: - IGNORE: RR, RC igraph_status: - IGNORE: RR, RC igraph_strerror: - IGNORE: RR, RC ####################################### # Other functions, documented, graph related ####################################### igraph_expand_path_to_pairs: - IGNORE: RR + DEPS: path ON path igraph_invalidate_cache: PARAMS: INOUT GRAPH graph diff --git a/tools/stimulus/types-RR.yaml b/tools/stimulus/types-RR.yaml index 522c08bd75..617e5f6b94 100644 --- a/tools/stimulus/types-RR.yaml +++ b/tools/stimulus/types-RR.yaml @@ -21,6 +21,7 @@ REAL: ECROSSW: 1.0 - sqrt(edge_density(graph)) ELENW: edge_density(graph) / 10 NEDISTW: 0.2 * (1 - edge_density(graph)) + VCOUNT: vcount INCONV: IN: '%I% <- as.numeric(%I%)' @@ -103,6 +104,81 @@ TRANSITIVITY_MODE: NAN: c("nan", "zero") INCONV: '%I% <- switch_igraph_arg(%I%, "nan" = 0L, "zero" = 1L)' +STAR_MODE: + DEFAULT: + OUT: c("out", "in", "undirected", "mutual") + IN: c("in", "out", "undirected", "mutual") + UNDIRECTED: c("undirected", "out", "in", "mutual") + MUTUAL: c("mutual", "out", "in", "undirected") + INCONV: '%I% <- switch_igraph_arg(%I%, "out" = 0L, "in" = 1L, "undirected" = 2L, "mutual" = 3L)' + +BARABASI_ALGORITHM: + DEFAULT: + BAG: c("bag", "psumtree", "psumtree_multiple") + PSUMTREE: c("psumtree", "bag", "psumtree_multiple") + PSUMTREE_MULTIPLE: c("psumtree_multiple", "bag", "psumtree") + INCONV: '%I% <- switch_igraph_arg(%I%, "bag" = 0L, "psumtree" = 1L, "psumtree_multiple" = 2L)' + +ERDOS_RENYI_TYPE: + DEFAULT: + GNP: c("gnp", "gnm") + GNM: c("gnm", "gnp") + INCONV: '%I% <- switch_igraph_arg(%I%, "gnp" = 0L, "gnm" = 1L)' + +DEGSEQ_MODE: + DEFAULT: + CONFIGURATION: c("configuration", "fast_heur_simple", "configuration_simple", "edge_switching_simple", "vl") + VL: c("vl", "configuration", "fast_heur_simple", "configuration_simple", "edge_switching_simple") + FAST_HEUR_SIMPLE: c("fast_heur_simple", "configuration", "configuration_simple", "edge_switching_simple", "vl") + CONFIGURATION_SIMPLE: c("configuration_simple", "configuration", "fast_heur_simple", "edge_switching_simple", "vl") + EDGE_SWITCHING_SIMPLE: c("edge_switching_simple", "configuration", "fast_heur_simple", "configuration_simple", "vl") + INCONV: '%I% <- switch_igraph_arg(%I%, "configuration" = 0L, "vl" = 1L, "fast_heur_simple" = 2L, "configuration_simple" = 3L, "edge_switching_simple" = 4L)' + +ADJACENCY_MODE: + DEFAULT: + DIRECTED: c("directed", "undirected", "upper", "lower", "min", "plus", "max") + UNDIRECTED: c("undirected", "directed", "upper", "lower", "min", "plus", "max") + UPPER: c("upper", "lower", "directed", "undirected", "min", "plus", "max") + LOWER: c("lower", "upper", "directed", "undirected", "min", "plus", "max") + MIN: c("min", "max", "plus", "directed", "undirected", "upper", "lower") + PLUS: c("plus", "min", "max", "directed", "undirected", "upper", "lower") + MAX: c("max", "min", "plus", "directed", "undirected", "upper", "lower") + INCONV: '%I% <- switch_igraph_arg(%I%, "directed" = 0L, "undirected" = 1L, "upper" = 2L, "lower" = 3L, "min" = 4L, "plus" = 5L, "max" = 6L)' + +SPINCOMMUPDATE: + DEFAULT: + SIMPLE: c("simple", "config") + CONFIG: c("config", "simple") + INCONV: '%I% <- switch_igraph_arg(%I%, "simple" = 0L, "config" = 1L)' + +SPINGLASS_IMPLEMENTATION: + DEFAULT: + ORIG: c("orig", "neg") + NEG: c("neg", "orig") + INCONV: '%I% <- switch_igraph_arg(%I%, "orig" = 0L, "neg" = 1L)' + +FWALGORITHM: + DEFAULT: + AUTOMATIC: c("automatic", "original", "tree") + ORIGINAL: c("original", "automatic", "tree") + TREE: c("tree", "automatic", "original") + INCONV: '%I% <- switch_igraph_arg(%I%, "automatic" = 0L, "original" = 1L, "tree" = 2L)' + +LAYOUT_GRID: + DEFAULT: + GRID: c("grid", "nogrid", "auto") + NOGRID: c("nogrid", "grid", "auto") + AUTO: c("auto", "grid", "nogrid") + INCONV: '%I% <- switch_igraph_arg(%I%, "grid" = 0L, "nogrid" = 1L, "auto" = 2L)' + +VCONNNEI: + DEFAULT: + ERROR: c("error", "number_of_nodes", "ignore", "negative") + NUMBER_OF_NODES: c("number_of_nodes", "error", "ignore", "negative") + IGNORE: c("ignore", "error", "number_of_nodes", "negative") + NEGATIVE: c("negative", "error", "number_of_nodes", "ignore") + INCONV: '%I% <- switch_igraph_arg(%I%, "error" = 0L, "number_of_nodes" = 1L, "ignore" = 2L, "negative" = 3L)' + INT: INCONV: '%I% <- as.integer(%I%)' @@ -476,7 +552,6 @@ PAGERANKOPT: DEPRECATED: CALL: {} - HEADER: ~ INCONV: if (!missing(%I%)) { warning("Argument `%I%' is deprecated and has no effect") } LSETYPE: