Default behaviour for setting edge weights #192
Replies: 3 comments
-
Good and important point. As a first thought that pops in my head, I would say it is better for me as a user to always explicitely tell my functions what to use, so that I am in full control of what happens and why. If I set a |
Beta Was this translation helpful? Give feedback.
-
I love the current behaviour of sfnetworks (i.e. internally adopt geographical lengths as weights when no weight argument is explicitly set), but I agree that it might be confusing for tidygraph users. Moreover, the I think we could change the existing code in our package and adopt the same approach as tidygraph. However, in that case, I would highlight this part in the NEWS file and also add a warning message (maybe until v0.7 or v1.0 and perhaps just a once-per-session warning, see
|
Beta Was this translation helpful? Give feedback.
-
I think we can consider keeping edge length as a default in sfnetworks shortest paths function, e.g. by st_network_paths(weights = edge_length()) I think the core issue is not that the defaults of sfnetworks might differ from tidygraph (as long as it is clearly documented) but that the same setting This does mean that the "weight" column does not get special treatment anymore (and also that the |
Beta Was this translation helpful? Give feedback.
-
This has been discussed before, but I am reopening it in a dedicated space. For any function that involves route calculations, you can define what to use as edge weights by setting the
weights
argument. However, what values you may provide to this parameter and how these values are interpreted is different forigraph
,sfnetworks
andtidygraph
... This can be very confusing.In
igraph
:The default value in
igraph
for this parameter is alwaysNULL
, meaning that the values of an edge attribute named "weight" will be used if present, and no weights will be used otherwise.In
sfnetworks
we extended this behaviour by 1) allowing the name of an edge attribute column as as value given to the weights argument and 2) using the geographic length of the edges as weight ifweights = NULL
and there is no edge attribute column named "weight". Hence:The default value in
sfnetworks
for this parameter is alwaysNULL
, meaning that the values of an edge attribute named "weight" will be used if present, and geographic edge lengths will be used otherwise. The only case in which no weights are used at all is when settingweights = NA
.Hence the behaviour of
sfnetworks
is similar to the behaviour ofigraph
, with the only difference being the geographic edge lengths as "lowest-level default" instead of using no weights at all. Which I think makes sense for spatial networks. However:tidygraph
used to have the same behaviour asigraph
(it just forwarded the weights parameter value to the igraph function it is wrapping), but changed this last year (see this commit). Now, it interpretsweights = NULL
always as "do not use any edge weights", even if there is an edge attribute named "weight". It does this intentionally in every function that has a weights parameter, by changingNULL
toNA
before forwarding the weights parameter value to the igraph function:I do understand the thought behind this. It is indeed somewhat confusing that
weights = NULL
does not mean "do not use any edge weights" inigraph
. However, now it is super confusing thatsfnetworks
andtidygraph
don't interpret the weights argument in the same way. Sincesfnetworks
is mainly meant to be used as a spatial network extension oftidygraph
(and not in the first place ofigraph
) I would argue that it is more important for us to follow tidygraphs design choices instead of igraphs design choices in case they differ. For example, in the current situation, the following two lines interpret the weights argument differently:In both cases shortest paths are calculated, and in both cases we don't explicitly set the weights argument, i.e. it uses the default value of
weights = NULL
. However, in the first case that means no edge weights are used, while in the second case this means the values of a weight column in the edges table are used (or geographic edge lengths whenever this column does not exist).As an
sfnetworks
user you are now used to not having to explicitly set the weights argument whenever you have an edge attribute named "weight". Every time you use atidygraph
function you have to remember that in that case you do have to explicitly tell the function to use the "weight" attribute. Again, I think this is super confusing and surely will lead to mistakes at some point.Should we also force users to explicitly tell routing functions which column to use for edge weights? Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions