GIScience / openrouteservice

🌍 The open source route planner api with plenty of features.
https://openrouteservice.org
GNU General Public License v3.0
1.43k stars 393 forks source link

Matrix results change when locations are added to the query #1194

Open aoles opened 2 years ago

aoles commented 2 years ago

It has been reported by one of the users that adding locations to the matrix query might alter the results for the existing locations, as in the example below.

library(openrouteservice)

coordinates <- list(
  c(20.29302, 50.14362),
  c(20.30200, 50.14231)
  )
(res1 <- ors_matrix(coordinates)$durations)
#>       [,1]  [,2]
#> [1,]  0.00 48.98
#> [2,] 48.98  0.00

## add 3rd location to the query
coordinates[[3]] <- c(20.27696, 50.15716)
(res2 <- ors_matrix(coordinates)$durations)
#>        [,1]   [,2]   [,3]
#> [1,]   0.00  48.98 230.51
#> [2,]  48.98   0.00 273.73
#> [3,] 230.51 273.73   0.00

## different 3rd location
coordinates[[3]] <- c(20.29904, 50.14285)
(res3 <- ors_matrix(coordinates)$durations)
#>       [,1]  [,2]  [,3]
#> [1,]  0.00 49.01 33.34
#> [2,] 49.01  0.00 15.67
#> [3,] 33.34 15.67  0.00

identical(res1[1,2], res2[1,2])
#> [1] TRUE
identical(res1[1,2], res3[1,2])
#> [1] FALSE

Created on 2022-06-24 by the reprex package (v2.0.1)

Unfortunately, I was unable to reproduce this locally. The problem might be related the use of virtual edges introduced by the additional locations.

aoles commented 2 years ago

I was able to find a reproducible example on the HD test graph where adding a 3rd location increases the original travel time. This happens regardless of the matrix algorithm used, i.e. both for RPHAST and Dijkstra.

library(openrouteservice)

options(openrouteservice.url = "http://localhost:8082/ors")

coordinates <- list(
  c(8.679177, 49.41364),
  c(8.686624, 49.423034)
)
(ref <- ors_matrix(coordinates)$durations)
#>        [,1]   [,2]
#> [1,]   0.00 353.47
#> [2,] 364.28   0.00

coordinates[[3]] <- c(8.679672, 49.413868)
(res <- ors_matrix(coordinates)$durations)
#>        [,1]   [,2]   [,3]
#> [1,]   0.00 353.49   5.96
#> [2,] 364.28   0.00 370.25
#> [3,] 122.96 347.53   0.00

identical(ref, res[-3, -3])
#> [1] FALSE

Created on 2022-06-27 by the reprex package (v2.0.1)