Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge map order is wrong #173

Closed
mpadge opened this issue Nov 26, 2021 · 3 comments
Closed

Edge map order is wrong #173

mpadge opened this issue Nov 26, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@mpadge
Copy link
Member

mpadge commented Nov 26, 2021

The neighbourhoods package needs to uncontract edges, for which it uses the cached edge maps. The order of these is, however, all mucked up, and so can't be used in current form to directly uncontract the edges:

library (dodgr)
f <- "/<path>/<to>/bristol-sc.Rds"
net <- readRDS (f) |>
    weight_streetnet (wt_profile = "motorcar")
#> Loading required namespace: geodist
#> Loading required namespace: dplyr
netc <- dodgr_contract_graph (net)

h <- attr (netc, "hashc")
f <- list.files (tempdir (), full.names = TRUE,
                 pattern = paste0 ("edge\\_map\\_", h))
edge_map <- readRDS (f)

# group by number of edges, and choose largest contracted edge:
n <- dplyr::group_by (edge_map, edge_new) |>
    dplyr::summarise (n = dplyr::n ()) |>
    dplyr::arrange (by = dplyr::desc (n))
edge_old <- edge_map$edge_old [which (edge_map$edge_new == n$edge_new [1])]
g <- net [match (edge_old, net$edge_), ]
plot (g$.vx0_x, g$.vx0_y, type = "l")

Created on 2021-11-26 by the reprex package (v2.0.1.9000)

@mpadge mpadge added the bug Something isn't working label Nov 26, 2021
@mpadge mpadge closed this as completed in 7a49a39 Nov 26, 2021
@mpadge
Copy link
Member Author

mpadge commented Nov 26, 2021

The above commit just changed the old_edges from a std::set to a std::vector, so they are retained in the order in which they are input.

library (dodgr)
packageVersion ("dodgr")
#> [1] '0.2.12.22'
f <- "/<path>/<to>/bristol-sc.Rds"
net <- readRDS (f) |>
    weight_streetnet (wt_profile = "motorcar")
#> Loading required namespace: geodist
#> Loading required namespace: dplyr
netc <- dodgr_contract_graph (net)

h <- attr (netc, "hashc")
f <- list.files (tempdir (), full.names = TRUE,
                 pattern = paste0 ("edge\\_map\\_", h))
edge_map <- readRDS (f)
n <- dplyr::group_by (edge_map, edge_new) |>
    dplyr::summarise (n = dplyr::n ()) |>
    dplyr::arrange (by = dplyr::desc (n))
edge_old <- edge_map$edge_old [which (edge_map$edge_new == n$edge_new [1])]
g <- net [match (edge_old, net$edge_), ]
plot (g$.vx0_x, g$.vx0_y, type = "l")

Created on 2021-11-26 by the reprex package (v2.0.1.9000)

@mpadge
Copy link
Member Author

mpadge commented Nov 26, 2021

Re-opening because the result is not quite what it should be:

library (dodgr)
packageVersion ("dodgr")
#> [1] '0.2.12.22'
f <- "/data/mega/code/repos/atfutures-labs/neighbourhoods/bristol-sc.Rds"
net <- readRDS (f) |>
    weight_streetnet (wt_profile = "motorcar")
#> Loading required namespace: geodist
#> Loading required namespace: dplyr
netc <- dodgr_contract_graph (net)
h <- attr (netc, "hashc")
f <- list.files (tempdir (), full.names = TRUE,
                 pattern = paste0 ("edge\\_map\\_", h))
edge_map <- readRDS (f)
n <- dplyr::group_by (edge_map, edge_new) |>
    dplyr::summarise (n = dplyr::n ()) |>
    dplyr::arrange (by = dplyr::desc (n))
edge_old <- edge_map$edge_old [which (edge_map$edge_new == n$edge_new [1])]
g <- net [match (edge_old, net$edge_), ]
par (mfrow = c (1, 2))
plot (g$.vx0_x, g$.vx0_y, type = "l")

obj <- unique (net$object_ [match (g$edge_, net$edge_)])
g2 <- net [which (net$object_ %in% obj), ]
plot (g2$.vx0_x, g2$.vx0_y, type = "l")

Created on 2021-11-26 by the reprex package (v2.0.1.9000)

The re-constructed edges still have a couple of glitches in them.

@mpadge mpadge reopened this Nov 26, 2021
mpadge added a commit that referenced this issue Nov 26, 2021
@mpadge mpadge closed this as completed in 4500e96 Nov 29, 2021
@mpadge
Copy link
Member Author

mpadge commented Nov 29, 2021

All good now:

library (dodgr)
packageVersion ("dodgr")
#> [1] '0.2.12.24'
f <- "/<path>/<to>/bristol-sc.Rds"
graph <- x <- readRDS (f) |>
    weight_streetnet (wt_profile = "motorcar")
#> Loading required namespace: geodist
#> Loading required namespace: dplyr
v <- dodgr_vertices (graph)
verts <- NULL
graph_contracted <- dodgr_contract_graph_internal (graph, v, verts)
edge_map <- graph_contracted$edge_map
n <- dplyr::group_by (edge_map, edge_new) |>
    dplyr::summarise (n = dplyr::n ()) |>
    dplyr::arrange (by = dplyr::desc (n))
edge_old <- edge_map$edge_old [which (edge_map$edge_new == n$edge_new [1])]
g <- graph [match (edge_old, graph$edge_), ]
par (mfrow = c (1, 2))
plot (g$.vx0_x, g$.vx0_y, type = "l")

obj <- unique (graph$object_ [match (g$edge_, graph$edge_)])
g2 <- graph [which (graph$object_ %in% obj), ]
plot (g2$.vx0_x, g2$.vx0_y, type = "l")

Created on 2021-11-29 by the reprex package (v2.0.1.9000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant