vlarmet / cppRouting

Algorithms for Routing and Solving the Traffic Assignment Problem
109 stars 9 forks source link

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

Open latot opened 10 months ago

latot commented 10 months ago

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:

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 commented 10 months ago

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