UrbanAnalyst / dodgr

Distances on Directed Graphs in R
https://urbananalyst.github.io/dodgr/
127 stars 16 forks source link

Bug in dodgr_isodists? #168

Closed mpadge closed 2 years ago

mpadge commented 2 years ago

These lines should have d [j] and not w [j]: https://github.com/ATFutures/dodgr/blob/7f24c82cebb426c9a0f3d4b770872fe15096e70a/src/run_sp.cpp#L292-L300

mpadge commented 2 years ago
library (dodgr)
packageVersion ("dodgr")
#> [1] '0.2.9.29'
graph <- weight_streetnet (hampi, wt_profile = "foot")
graph <- graph [graph$component == 1, ]

do1 <- function (graph, n = 1) {

    from <- dodgr_vertices (graph)$id [n]
    x <- dodgr_isodists (graph, from = from, dlim = 1000)
    if (nrow (x) == 0L)
        return (NA)

    to <- x$id
    d <- dodgr_dists (graph, from = from, to = to)
    max (d)
}

d0 <- vapply (seq (nrow (dodgr_vertices (graph))),
              function (i) do1 (graph, i),
              numeric (1))
devtools::load_all (".", export_all = TRUE)
#> ℹ Loading dodgr
packageVersion ("dodgr")
#> [1] '0.2.9.32'
d <- vapply (seq (nrow (dodgr_vertices (graph))),
             function (i) do1 (graph, i),
             numeric (1))

plot (d0, d, pch = 1, col = "orange")

Created on 2021-09-19 by the reprex package (v2.0.0.9000)

And the distribution beforehand (d0) was all mucked up, with way too many distances well below the threshold. New version (d) clearly gets it right.