navigate_network_dfs: Navigate all Paths Depth First

View source: R/navigate_network_dfs.R

navigate_network_dfsR Documentation

Description

given a starting node, return all reachable paths. Once visited, a node is marked as visited and will not take part in a future path.

Usage

navigate_network_dfs(x, starts, direction = "down", reset = FALSE)

Arguments

x

data.frame containing hydroloom compatible network or list as returned by make_index_ids (for down) or make_fromids (for up). The list formats avoids recreating the index ids for every call to navigate network dfs in the case that it needs to be called many times.

starts

vector with ids from x to start at.

direction

character "up", "upmain", "down", or "downmain". If "upmain" or "downmain", x must contain sufficient information to construct an upmain and downmain network (see details).

reset

logical if TRUE, reset graph for each start such that later paths will have overlapping results.

Details

navigate_network_dfs offers two usage patterns. In the simple case, you can provide an hy in which case preprocessing is performed automatically, or you can do the preprocessing ahead of time and provide index ids. The latter is more complicated but can be much faster in certain circumstances.

hy object:

If the function will only be called one or a few times, it can be called with x containing (at a minimum) id and toid. For "upmain" and "downmain" support, x also requires attributes for determination of the primary upstream and downstream connection across every junction.

In this pattern, the hy object will be passed to make_index_ids called for every call to navigate_network_dfs and the resulting index ids will be used for network navigation.

Index ids:

If the function will be called repeatedly or index_ids are available for other reasons, the index_id list as created by make_index_ids (for downstream) or make_fromids (for upstream) can be used. For "upmain" and "downmain" support, the main element must be included.

Value

list containing dfs result for each start.

Examples


x <- hy(sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom")))

x <- add_toids(x, return_dendritic = FALSE)

navigate_network_dfs(x, 8893402)

navigate_network_dfs(x, 8897784, direction = "up")


hydroloom documentation built on Sept. 11, 2024, 8:20 p.m.