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

Missing combinations in route_matrix() #30

Closed
munterfinger opened this issue Jan 18, 2020 · 1 comment
Closed

Missing combinations in route_matrix() #30

munterfinger opened this issue Jan 18, 2020 · 1 comment
Assignees
Labels
bug

Comments

@munterfinger
Copy link
Owner

@munterfinger munterfinger commented Jan 18, 2020

Route combinations are missing in the matrix returned by route_matrix() from the HERE Routing API. This is the case if the maximum size of 100 in the dimension N is exceeded in M:N and 1:N input combinations.

Construct a dummy data set:

library(sf)
#> Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
n <- 200
l <- n*n
(sf <- 
  data.frame(
    idx = seq(1, n),
    lng = runif(n, 7.5, 8.5),
    lat = runif(n, 47.25, 47.75)
  ) %>% 
  st_as_sf(coords = c("lng", "lat")) %>% 
  st_set_crs(4326))
#> Simple feature collection with 200 features and 1 field
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 7.501636 ymin: 47.25102 xmax: 8.499705 ymax: 47.74729
#> epsg (SRID):    4326
#> proj4string:    +proj=longlat +datum=WGS84 +no_defs
#> First 10 features:
#>    idx                  geometry
#> 1    1 POINT (8.437796 47.32556)
#> 2    2 POINT (7.952149 47.64342)
#> 3    3 POINT (8.113918 47.30319)
#> 4    4 POINT (8.164873 47.36452)
#> 5    5 POINT (7.948922 47.44872)
#> 6    6 POINT (7.840909 47.56165)
#> 7    7 POINT (7.556707 47.68344)
#> 8    8 POINT (7.966527 47.36275)
#> 9    9 POINT (8.462874 47.35851)
#> 10  10 POINT (7.833083 47.44759)

Functions for testing inputs, requests and return values:

n_request <- function(x, y = NULL) {
  message(
    sprintf(
      "Number of requests: %s",
      ifelse(
        is.null(y),
        length(route_matrix(x, url_only = TRUE)),
        length(route_matrix(x, y, url_only = TRUE))
      )
    )
  )
}

test_one_input <- function(x) {
  message("* Only origin *")
  n_request(x)
  el <- route_matrix(x)
  message(sprintf(
    "Orig rows: %s, edgelist rows: %s \nInput combinations: %s, ouput combinations: %s",
     nrow(x), nrow(x)*nrow(x), nrow(el),
    length(unique(paste0(el$origIndex, "_", el$destIndex)))))
  return(el)
}

test_two_inputs <- function(x, y) {
  message("* Origin and destination*")
  n_request(x, y)
  el <- route_matrix(x, y)
  message(sprintf(
    "Orig rows: %s, dest rows: %s, edgelist rows: %s \ninput combinations: %s, Ouput combinations: %s",
    nrow(x), nrow(y), nrow(el), nrow(x)*nrow(y),
    length(unique(paste0(el$origIndex, "_", el$destIndex)))))
  return(el)
}

Calculate all input variants in route_matrix() and compare the number of combinations in the inputs with the combinations in the returned edge lists.

  • M - Only origin
el1 <- test_one_input(sf)
#> * Only origin *
#> Number of requests: 14
#> Orig rows: 200, edgelist rows: 40000 
#> Input combinations: 20000, ouput combinations: 20000
  • M:N - Origin and destination of same length
el2 <- test_two_inputs(sf[1:(n/2), ], sf[(n/2 + 1):n, ])
#> * Origin and destination*
#> Number of requests: 7
#> Orig rows: 100, dest rows: 100, edgelist rows: 10000 
#> input combinations: 10000, Ouput combinations: 10000
  • M:N - Origin and destination of different length
el3 <- test_two_inputs(sf[(n/3 + 1):n, ], sf[1:(n/2), ])
#> * Origin and destination*
#> Number of requests: 7
#> Orig rows: 133, dest rows: 100, edgelist rows: 10000 
#> input combinations: 13300, Ouput combinations: 10000
el4 <- test_two_inputs(sf[1:(n/2), ], sf[(n/3 + 1):n, ])
#> * Origin and destination*
#> Number of requests: 7
#> Orig rows: 100, dest rows: 133, edgelist rows: 10000 
#> input combinations: 13300, Ouput combinations: 10000
  • M:1 - Origin and destination
el6 <- test_two_inputs(sf[1:(n - 1), ], sf[n, ])
#> * Origin and destination*
#> Number of requests: 1
#> Orig rows: 199, dest rows: 1, edgelist rows: 100 
#> input combinations: 199, Ouput combinations: 100
  • 1:N - Origin and destination
el5 <- test_two_inputs(sf[1, ], sf[2:n, ])
#> * Origin and destination*
#> Number of requests: 1
#> Orig rows: 1, dest rows: 199, edgelist rows: 100 
#> input combinations: 199, Ouput combinations: 100
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.2 (2019-12-12)
#>  os       macOS Catalina 10.15.2      
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  de_CH.UTF-8                 
#>  ctype    de_CH.UTF-8                 
#>  tz       Europe/Zurich               
#>  date     2020-01-18                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 3.6.0)
#>  backports     1.1.5   2019-10-02 [1] CRAN (R 3.6.0)
#>  callr         3.4.0   2019-12-09 [1] CRAN (R 3.6.0)
#>  class         7.3-15  2019-01-01 [1] CRAN (R 3.6.2)
#>  classInt      0.4-2   2019-10-17 [1] CRAN (R 3.6.0)
#>  cli           2.0.0   2019-12-09 [1] CRAN (R 3.6.0)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.6.0)
#>  curl          4.3     2019-12-02 [1] CRAN (R 3.6.0)
#>  data.table    1.12.8  2019-12-09 [1] CRAN (R 3.6.0)
#>  DBI           1.1.0   2019-12-15 [1] CRAN (R 3.6.0)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 3.6.0)
#>  devtools      2.2.1   2019-09-24 [1] CRAN (R 3.6.0)
#>  digest        0.6.23  2019-11-23 [1] CRAN (R 3.6.0)
#>  e1071         1.7-3   2019-11-26 [1] CRAN (R 3.6.0)
#>  ellipsis      0.3.0   2019-09-20 [1] CRAN (R 3.6.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 3.6.0)
#>  fansi         0.4.0   2018-10-05 [1] CRAN (R 3.6.0)
#>  fs            1.3.1   2019-05-06 [1] CRAN (R 3.6.0)
#>  glue          1.3.1   2019-03-12 [1] CRAN (R 3.6.0)
#>  hereR       * 0.3.0   2020-01-07 [1] CRAN (R 3.6.0)
#>  htmltools     0.4.0   2019-10-04 [1] CRAN (R 3.6.0)
#>  jsonlite      1.6     2018-12-07 [1] CRAN (R 3.6.0)
#>  KernSmooth    2.23-16 2019-10-15 [1] CRAN (R 3.6.2)
#>  knitr         1.26    2019-11-12 [1] CRAN (R 3.6.0)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 3.6.0)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.6.0)
#>  pkgbuild      1.0.6   2019-10-09 [1] CRAN (R 3.6.0)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.6.0)
#>  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.6.0)
#>  processx      3.4.1   2019-07-18 [1] CRAN (R 3.6.0)
#>  ps            1.3.0   2018-12-21 [1] CRAN (R 3.6.0)
#>  R6            2.4.1   2019-11-12 [1] CRAN (R 3.6.0)
#>  Rcpp          1.0.3   2019-11-08 [1] CRAN (R 3.6.0)
#>  remotes       2.1.0   2019-06-24 [1] CRAN (R 3.6.0)
#>  rlang         0.4.2   2019-11-23 [1] CRAN (R 3.6.0)
#>  rmarkdown     2.0     2019-12-12 [1] CRAN (R 3.6.0)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.6.0)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.6.0)
#>  sf          * 0.8-0   2019-09-17 [1] CRAN (R 3.6.0)
#>  stringi       1.4.3   2019-03-12 [1] CRAN (R 3.6.0)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.6.0)
#>  testthat      2.3.1   2019-12-01 [1] CRAN (R 3.6.0)
#>  units         0.6-5   2019-10-08 [1] CRAN (R 3.6.0)
#>  usethis       1.5.1   2019-07-04 [1] CRAN (R 3.6.0)
#>  withr         2.1.2   2018-03-15 [1] CRAN (R 3.6.0)
#>  xfun          0.11    2019-11-12 [1] CRAN (R 3.6.0)
#>  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.6.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library
@munterfinger
Copy link
Owner Author

@munterfinger munterfinger commented Jan 18, 2020

Fixed:

  • M - Only origin
el1 <- test_one_input(sf)
#> * Only origin *
#> Number of requests: 28
#> Orig rows: 200, edgelist rows: 40000 
#> Input combinations: 40000, ouput combinations: 40000
  • M:N - Origin and destination of same length
el2 <- test_two_inputs(sf[1:(n/2), ], sf[(n/2 + 1):n, ])
#> * Origin and destination*
#> Number of requests: 7
#> Orig rows: 100, dest rows: 100, edgelist rows: 10000 
#> input combinations: 10000, Ouput combinations: 10000
  • M:N - Origin and destination of different length
el3 <- test_two_inputs(sf[(n/3 + 1):n, ], sf[1:(n/2), ])
#> * Origin and destination*
#> Number of requests: 14
#> Orig rows: 133, dest rows: 100, edgelist rows: 13300 
#> input combinations: 13300, Ouput combinations: 13300
el4 <- test_two_inputs(sf[1:(n/2), ], sf[(n/3 + 1):n, ])
#> * Origin and destination*
#> Number of requests: 14
#> Orig rows: 100, dest rows: 133, edgelist rows: 13300 
#> input combinations: 13300, Ouput combinations: 13300
  • M:1 - Origin and destination
el6 <- test_two_inputs(sf[1:(n - 1), ], sf[n, ])
#> * Origin and destination*
#> Number of requests: 2
#> Orig rows: 199, dest rows: 1, edgelist rows: 199 
#> input combinations: 199, Ouput combinations: 199
  • 1:N - Origin and destination
el5 <- test_two_inputs(sf[1, ], sf[2:n, ])
#> * Origin and destination*
#> Number of requests: 2
#> Orig rows: 1, dest rows: 199, edgelist rows: 199 
#> input combinations: 199, Ouput combinations: 199
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.2 (2019-12-12)
#>  os       macOS Catalina 10.15.2      
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  de_CH.UTF-8                 
#>  ctype    de_CH.UTF-8                 
#>  tz       Europe/Zurich               
#>  date     2020-01-18                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date       lib source        
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)
#>  backports     1.1.5      2019-10-02 [1] CRAN (R 3.6.0)
#>  callr         3.4.0      2019-12-09 [1] CRAN (R 3.6.0)
#>  class         7.3-15     2019-01-01 [1] CRAN (R 3.6.2)
#>  classInt      0.4-2      2019-10-17 [1] CRAN (R 3.6.0)
#>  cli           2.0.0      2019-12-09 [1] CRAN (R 3.6.0)
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)
#>  curl          4.3        2019-12-02 [1] CRAN (R 3.6.0)
#>  data.table    1.12.8     2019-12-09 [1] CRAN (R 3.6.0)
#>  DBI           1.1.0      2019-12-15 [1] CRAN (R 3.6.0)
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)
#>  devtools      2.2.1      2019-09-24 [1] CRAN (R 3.6.0)
#>  digest        0.6.23     2019-11-23 [1] CRAN (R 3.6.0)
#>  e1071         1.7-3      2019-11-26 [1] CRAN (R 3.6.0)
#>  ellipsis      0.3.0      2019-09-20 [1] CRAN (R 3.6.0)
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)
#>  fansi         0.4.0      2018-10-05 [1] CRAN (R 3.6.0)
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.0)
#>  hereR       * 0.3.0.9000 2020-01-18 [1] local         
#>  htmltools     0.4.0      2019-10-04 [1] CRAN (R 3.6.0)
#>  jsonlite      1.6        2018-12-07 [1] CRAN (R 3.6.0)
#>  KernSmooth    2.23-16    2019-10-15 [1] CRAN (R 3.6.2)
#>  knitr         1.26       2019-11-12 [1] CRAN (R 3.6.0)
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)
#>  pkgbuild      1.0.6      2019-10-09 [1] CRAN (R 3.6.0)
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.6.0)
#>  processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.0)
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)
#>  R6            2.4.1      2019-11-12 [1] CRAN (R 3.6.0)
#>  Rcpp          1.0.3      2019-11-08 [1] CRAN (R 3.6.0)
#>  remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.0)
#>  rlang         0.4.2      2019-11-23 [1] CRAN (R 3.6.0)
#>  rmarkdown     2.0        2019-12-12 [1] CRAN (R 3.6.0)
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)
#>  sf          * 0.8-0      2019-09-17 [1] CRAN (R 3.6.0)
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)
#>  testthat      2.3.1      2019-12-01 [1] CRAN (R 3.6.0)
#>  units         0.6-5      2019-10-08 [1] CRAN (R 3.6.0)
#>  usethis       1.5.1      2019-07-04 [1] CRAN (R 3.6.0)
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)
#>  xfun          0.11       2019-11-12 [1] CRAN (R 3.6.0)
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.