| Title: | Functions Finding Connected Links in Directed Graphs |
|---|---|
| Description: | Functions finding connected links in directed graphs. |
| Authors: | Hauke Sonnenberg [aut, cre] (ORCID: <https://orcid.org/0000-0001-9134-2871>), Michael Rustler [ctb] (ORCID: <https://orcid.org/0000-0003-0647-7726>), KURAS [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
| Maintainer: | Hauke Sonnenberg <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-29 09:19:05 UTC |
| Source: | https://github.com/KWB-R/kwb.graph |
Example data describing a network of connected links
exampleNetwork(n_links = 30L, index = 1L)exampleNetwork(n_links = 30L, index = 1L)
n_links |
number of links that the network to be returned shall contain. If there is no network with the given number of links, a network that is slightly smaller or bigger is returned. Giving -1L here returns the biggest possible network that is stored in this package. |
index |
integer number to switch between different sub nets if more than one subset of the required size is available. |
data frame with (roughly) n_links observations of two
variables. The variables us_node_id (upstream node ID) and
ds_node_id (downstream node ID) define the connections between
links. They are needed if the list of connected links upstream of each node
is to be calculated by means of getConnectedLinks.
Get Connected Links
getConnectedLinks(x, upstream = TRUE, version = 1, dbg = FALSE, ...)getConnectedLinks(x, upstream = TRUE, version = 1, dbg = FALSE, ...)
x |
data frame with each row representing a link of the network. Required columns: us_node_id, ds_node_id |
upstream |
if TRUE (upstream), if FALSE (downstream), default: TRUE |
version |
1: R-implementation, 2: C-implementation, (default: 1) |
dbg |
default: FALSE |
... |
additional arguments passed to |
get connected links
network <- kwb.graph::exampleNetwork(n_links = -1L) runtime.R <- vector() runtime.C1 <- vector() runtime.C2 <- vector() n <- 1 resultSize <- 2054851 queueSize <- 100*1024 elapsed <- function(exp) system.time(exp)["elapsed"] for (i in 1:n) { cat("run", i, "/", n, "\n") runtime.R[i] <- elapsed(x1 <- getConnectedLinks( network )) runtime.C1[i] <- elapsed(x2 <- getConnectedLinks( network, version = 2, resultSize = resultSize, queueSize = queueSize )) runtime.C2[i] <- elapsed(x3 <- getConnectedLinks( network, version = 3, resultSize = resultSize, queueSize = queueSize )) } cat("mean runtime with R-functions:", mean(runtime.R), "\n") cat("mean runtime with C-functions(1):", mean(runtime.C1), "\n") cat("mean runtime with C-functions(2):", mean(runtime.C2), "\n") runtimeData <- data.frame( version = 1:3, runtime = c(runtime.R), runtime.C1, runtime.C2 ) boxplot(runtime ~ version, data = runtimeData)network <- kwb.graph::exampleNetwork(n_links = -1L) runtime.R <- vector() runtime.C1 <- vector() runtime.C2 <- vector() n <- 1 resultSize <- 2054851 queueSize <- 100*1024 elapsed <- function(exp) system.time(exp)["elapsed"] for (i in 1:n) { cat("run", i, "/", n, "\n") runtime.R[i] <- elapsed(x1 <- getConnectedLinks( network )) runtime.C1[i] <- elapsed(x2 <- getConnectedLinks( network, version = 2, resultSize = resultSize, queueSize = queueSize )) runtime.C2[i] <- elapsed(x3 <- getConnectedLinks( network, version = 3, resultSize = resultSize, queueSize = queueSize )) } cat("mean runtime with R-functions:", mean(runtime.R), "\n") cat("mean runtime with C-functions(1):", mean(runtime.C1), "\n") cat("mean runtime with C-functions(2):", mean(runtime.C2), "\n") runtimeData <- data.frame( version = 1:3, runtime = c(runtime.R), runtime.C1, runtime.C2 ) boxplot(runtime ~ version, data = runtimeData)
#' Get Connected Links (C Implementation)
getConnectedLinks.C( directLinks, resultSize = 60000, queueSize = 1024 * 1024, version = 1, dbg = FALSE )getConnectedLinks.C( directLinks, resultSize = 60000, queueSize = 1024 * 1024, version = 1, dbg = FALSE )
directLinks |
directLinks |
resultSize |
default: 60000 |
queueSize |
default: 1024*1024 |
version |
version of C implementation: 1,2 or 3 (default: 1) |
dbg |
default: FALSE |
get connected links with C implementation
Get Connected Links (R Implementation)
getConnectedLinks.R(directly.connected, dbg = FALSE)getConnectedLinks.R(directly.connected, dbg = FALSE)
directly.connected |
directly.connected |
dbg |
default: FALSE |
get connected links with R implementation
Get Direct Links (C Implementation)
getDirectLinks.C(x, MAX_DIRECT_CONNECTIONS = 5, dbg = FALSE)getDirectLinks.C(x, MAX_DIRECT_CONNECTIONS = 5, dbg = FALSE)
x |
data frame with each row representing a link of the network. Required columns: us_node_id, ds_node_id |
MAX_DIRECT_CONNECTIONS |
default: 5 |
dbg |
default: FALSE |
get direct links with C implementation
Get Direct Links (R Implementation)
getDirectLinks.R(x, upstream = TRUE)getDirectLinks.R(x, upstream = TRUE)
x |
data frame with each row representing a link of the network. Required columns: us_node_id, ds_node_id |
upstream |
if TRUE (upstream), if FALSE (downstream), default: TRUE |
get direct links with R implementation