diff --git a/R/times.R b/R/times.R index ddf1a90b..95d76f7e 100644 --- a/R/times.R +++ b/R/times.R @@ -9,6 +9,7 @@ dodgr_times <- function (graph, from = NULL, to = NULL, shortest = FALSE, + pairwise = FALSE, heap = "BHeap") { graph <- tbl_to_df (graph) @@ -29,6 +30,6 @@ dodgr_times <- function (graph, } graph [[gr_cols$d_weighted]] <- graph [[gr_cols$time_weighted]] } - - dodgr_dists (graph, from, to, heap = heap) -} + + dodgr_dists (graph = graph, from = from, to = to, heap = heap, pairwise= pairwise) +} \ No newline at end of file diff --git a/man/dodgr_times.Rd b/man/dodgr_times.Rd index 097f4fdc..a9aeec51 100644 --- a/man/dodgr_times.Rd +++ b/man/dodgr_times.Rd @@ -4,7 +4,14 @@ \alias{dodgr_times} \title{Calculate matrix of pair-wise travel times between points.} \usage{ -dodgr_times(graph, from = NULL, to = NULL, shortest = FALSE, heap = "BHeap") +dodgr_times( + graph, + from = NULL, + to = NULL, + shortest = FALSE, + pairwise = FALSE, + heap = "BHeap" +) } \arguments{ \item{graph}{\code{data.frame} or equivalent object representing the network @@ -54,6 +61,9 @@ generated with the \pkg{osmdata} function \code{osmdata_sf()}, and will be much more accurate when derived from \code{sc}-format data generated with \code{osmdata_sc()}. See \link{weight_streetnet} for details.} +\item{pairwise}{If \code{TRUE}, calculate distances only between the ordered +pairs of \code{from} and \code{to}.} + \item{heap}{Type of heap to use in priority queue. Options include Fibonacci Heap (default; \code{FHeap}), Binary Heap (\code{BHeap}), \verb{Trinomial Heap (}TriHeap\verb{), Extended Trinomial Heap (}TriHeapExt\verb{, and 2-3 Heap (}Heap23`).} diff --git a/tests/testthat/test-dists.R b/tests/testthat/test-dists.R index 5953a529..d2cadf61 100644 --- a/tests/testthat/test-dists.R +++ b/tests/testthat/test-dists.R @@ -178,6 +178,21 @@ test_that ("times", { expect_identical (t2, t0) }) +test_that ("times-pairwise", { + graph <- weight_streetnet (hampi) + n <- 50 + set.seed (1) + from <- sample (graph$from_id, size = n) + to <- sample (graph$to_id, size = n) + expect_silent (d <- dodgr_times (graph, from = from, to = to)) + expect_equal (dim (d), c (n, n)) + expect_silent (d <- dodgr_times (graph, + from = from, to = to, + pairwise = TRUE + )) + expect_equal (dim (d), c (50, 1)) +}) + test_that ("all dists", { graph <- weight_streetnet (hampi) graph <- graph [graph$component == 2, ]