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

get_multi_paths fails to return the right value between the same nodes #17

Open
latot opened this issue Dec 14, 2023 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@latot
Copy link

latot commented Dec 14, 2023

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!

@vlarmet
Copy link
Owner

vlarmet commented Dec 15, 2023

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

@vlarmet vlarmet added the bug Something isn't working label Dec 15, 2023
@vlarmet vlarmet self-assigned this Dec 19, 2023
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

2 participants