-
Notifications
You must be signed in to change notification settings - Fork 16
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
dodgr_flows_aggregate() weight column unclear #258
Comments
Thanks @jonas260492, you're correct that there's something odd going on there. The problem arises because of dodgr's internal caching system. A work-around in this case is to simply turn the cache off: library(dodgr)
dodgr_cache_off () And after that point, everything works as expected: graph <- weight_streetnet(hampi, wt_profile = "foot")
set.seed(123)
from <- sample(graph$from_id, size = 200)
to <- sample(graph$to_id, size = 200)
flows=matrix(
data=runif(n=length(from) * length(to),min=1,max=13),
nrow=length(from),ncol=length(to)
)
graph_with_flows <- dodgr_flows_aggregate(graph, from = from, to = to, flows = flows, contract = FALSE)
graph_with_flows [2146, ]
#> geom_num edge_id from_id from_lon from_lat to_id to_lon to_lat
#> 2146 70 2146 1376768839 76.46362 15.32709 1376768475 76.46331 15.32718
#> d d_weighted highway way_id component time time_weighted
#> 2146 35.37003 35.37003 path 123463598 1 25.46642 25.46642
#> flow
#> 2146 0.9961289
graph2 <- graph
graph2[graph2$edge_id%in%c(2146),c("d_weighted")]=99999999
graph_with_flows2 <- dodgr_flows_aggregate(graph2, from = from, to = to, flows = flows, contract = FALSE)
graph_with_flows2[graph_with_flows2$edge_id%in%c(2146),]
#> geom_num edge_id from_id from_lon from_lat to_id to_lon to_lat
#> 2146 70 2146 1376768839 76.46362 15.32709 1376768475 76.46331 15.32718
#> d d_weighted highway way_id component time time_weighted
#> 2146 35.37003 1e+08 path 123463598 1 25.46642 25.46642
#> flow
#> 2146 0 Created on 2024-12-06 with reprex v2.1.1 But that doesn't really help if you don't know what causes the problem in the first place ... 😕 The caching system starts graph contraction in the background as soon as a graph is constructed, so that the whole package functions much quicker. Caching and re-caching require checking for changes in a graph, but graphs are often too big to check everything, so shortcuts are used instead. That means caching won't always catch every change to a graph, which is what's happening here. I'm not sure at the moment what a solution might be ... I'll think about it and get back to you. |
@jonas260492 Updated the function docs to explain what you're seeing: https://urbananalyst.github.io/dodgr/reference/dodgr_flows_aggregate.html - Let me know if that's clear, or feel free to suggest any improvements to the explanation. Also via PR to the docs if you want. Thanks! |
Thank you very much for this work-around. Still, there is the issue with the "invisible" column of "d_weight" which cannot get deleted and is actually used for the least-cost-path instead of d_weighted. |
Yeah, good point. I'll reopen the issue to address that. |
I want to calculate the flows in a network for a base scenario and for a scenario where I reduce the speed for an edge to a very high number (I am interested in speed reduction so, I don't want to delete the edge).
The weight column for dodgr_flows_aggregate() is stated as "d_weighted" in the c++ function flows.cpp (line 719).
However, when I change the value of d_weighted to almost infinite the flows on this edge stay the same. There is an alternative route available!
However I found out that entering a very high number in "weight" column leads to almost no more flow. But since this column did not exist in the "graph" before, I cannot understand how it is used.
Also in the "graph" there is an "invisible" column called "d_weight" which contains same values as "d_weighted". You can print this column if you explicitly call it, but it does not show if you print or View the "graph"
Did I oversee something? Who can explain it?
Structure graph:
Here is a minimum reproducible example:
The text was updated successfully, but these errors were encountered: