Coder Social home page Coder Social logo

Comments (5)

franciscopasqual avatar franciscopasqual commented on August 25, 2024

I managed to create the cross product of all origins and destinations pairs but still not sure on how to use that to run detailed_itineraires for all combinations. What would be the right arguments to do so?

from r5r.

rafapereirabr avatar rafapereirabr commented on August 25, 2024

please follow the example below:

library(r5r)
library(data.table)
library(dplyr)

# build transport network
data_path <- system.file("extdata/poa", package = "r5r")
r5r_core <- setup_r5(data_path = data_path, temp_dir = TRUE)


# Read points
origins <- read.csv(file.path(data_path, "poa_points_of_interest.csv"))[1:4,]
destinations <- read.csv(file.path(data_path, "poa_points_of_interest.csv"))[3:10,]

# get all possible combinations between origins and destinations
# function
get_all_od_combinations <- function(origins, destinations){
  
  # all possible id combinations
  base <- expand.grid(origins$id, destinations$id)
  
  # rename df
  setDT(base)
  setnames(base, 'Var1', 'idorig')
  setnames(base, 'Var2', 'iddest')
  
  # bring spatial coordinates from origin and destination
  base[origins, on=c('idorig'='id'), c('lon_orig', 'lat_orig') := list(i.lon, i.lat)]
  base[destinations, on=c('iddest'='id'), c('lon_dest', 'lat_dest') := list(i.lon, i.lat)]
  
  return(base)
}

df <- get_all_od_combinations(origins, destinations)

# select/rename columns for r5r input
all_orig <- dplyr::select(df, c('id'=idorig, 'lon'=lon_orig,'lat'=lat_orig))
all_dest <- dplyr::select(df, c('id'=iddest, 'lon'=lon_dest,'lat'=lat_dest))


# run r5r
departure_datetime <- as.POSIXct("13-05-2019 14:00:00", format = "%d-%m-%Y %H:%M:%S")
dit <- detailed_itineraries(r5r_core,
                            origins = all_orig,
                            destinations = all_dest,
                            mode = c("WALK", "TRANSIT"),
                            departure_datetime = departure_datetime,
                            max_walk_dist = 1000,
                            max_trip_duration = 30)

from r5r.

rafapereirabr avatar rafapereirabr commented on August 25, 2024

This is related to #224.

The dev version of the detailed_itineraries() function now has a new parameter all_to_all, which allows users to set whether they want to query routes between all origins to all destinations (all_to_all = TRUE) or to query. By default (FALSE), the functions queries routes between the the 1st row of origins to the 1st row of destinations, then the 2nd row of origins to the 2nd row of destinations, and so on.

from r5r.

franciscopasqual avatar franciscopasqual commented on August 25, 2024

@rafapereirabr how do I access the dev version? This new parameter would be really helpful.

from r5r.

rafapereirabr avatar rafapereirabr commented on August 25, 2024

You can install the dev verison with the code below:

  utils::remove.packages('r5r')

  devtools::install_github("ipeaGIT/r5r", subdir = "r-package")
  library(r5r)

from r5r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.