cppRouting
cppRouting copied to clipboard
get_multi_paths fails to return the right value between the same nodes
Hi, I was using the shortest path function and I found something that seems to be a bug, usually the results are catalogued in the same way:
- If the shortestpath does not exists because are in different components, return
logical(0) - if is requested from the same node to the same node, like from x to x, it returns a vector like
c(x) - if is requested from/to different nodes, a vector with their respective nodes
In get_multi_paths if we request node x to node x, we are getting logical(0) instead c(c), this is pretty important in the moment to recognize if the path exists or not.
library(wrapr)
network <- local({
nodes <- sf::st_sf(
geom = sf::st_sfc(
sf::st_point(c(0, 0)),
sf::st_point(c(0, 1))
),
crs = CITLib::sf_planar_crs
)
edges <- sf::st_sf(
geom = sf::st_sfc(
sf::st_linestring(c(
sf::st_point(c(0, 0)),
sf::st_point(c(0, 1))
)),
crs = CITLib::sf_planar_crs
),
from = c(1),
to = c(2)
)
edges$weight <- sf::st_length(sf::st_geometry(edges))
sfnetworks::sfnetwork(nodes, edges, directed = FALSE)
})
weight <- "weight"
cppRouting_graph <- cppRouting::makegraph(
network %.>%
sfnetworks::activate(., "edges") %.>%
sf::st_as_sf(.) %.>%
sf::st_drop_geometry(.) %.>%
as.data.frame(.) %.>%
dplyr::transmute(., .data$from, .data$to, cost = .data[[weight]]),
directed = igraph::is_directed(network)
)
ret <- cppRouting::get_multi_paths(Graph = cppRouting_graph, from = c(1), to = c(1))
ret
$`1`
$`1`$`1`
character(0)
Thx!
Hi,
Thanks for pointing this !
You're right, the behavior should be the same in get_path_pair and get_multi_paths functions when going from node x to node x.
I'll fix it asap