if (FALSE) {
# load a network dynamic object
nd <- readRDS("nd_obj.Rds")
# convert it to a cumulative edgelist
el_cuml <- as_cumulative_edgelist(nd)
# sample 100 node indexes
nnodes <- max(el_cuml$head, el_cuml$tail)
nodes <- sample(nnodes, 100)
# `get_forward_reachable` uses steps [from_step, to_step] inclusive
el_fwd <- get_forward_reachable(el_cuml, 1, 52, nodes)[["reached"]]
# check if the results are consistent with `tsna::tPath`
nodes <- strsplit(names(el_fwd), "_")
for (i in seq_along(el_fwd)) {
node <- as.integer(nodes[[i]][2])
t_fwd <- tsna::tPath(
nd, v = node,
start = 1, end = 52 + 1, # tPath works from [start, end) right exclusive
direction = "fwd"
)
t_fwd_set <- which(t_fwd$tdist < Inf)
if(!setequal(el_fwd[[i]], t_fwd_set))
stop("Missmatch on node: ", node)
}
# Backward:
el_bkwd <- get_backward_reachable(el_cuml, 1, 52, nodes = 1)[["reached"]]
nodes <- strsplit(names(el_bkwd), "_")
t_bkwd <- tsna::tPath(
nd, v = nodes[i][2],
start = 1, end = 52 + 1,
direction = "bkwd", type = "latest.depart"
)
t_bkwd_set <- which(t_bkwd$tdist < Inf)
setequal(el_bkwd[[1]], t_bkwd_set)
}
Run the code above in your browser using DataLab