diff --git a/.github/workflows/java-r5rcore-build.yaml b/.github/workflows/java-r5rcore-build.yaml new file mode 100644 index 00000000..547fcd8f --- /dev/null +++ b/.github/workflows/java-r5rcore-build.yaml @@ -0,0 +1,62 @@ +name: Java R5RCore build + +on: + push: + paths: + - java-r5rcore/** + - .github/workflows/java-r5rcore-build.yaml + +jobs: + build: + env: + GH_TOKEN: ${{ github.token }} + + runs-on: ubuntu-latest + + # don't build on merges to master + if: ${{ !github.ref_protected }} + + steps: + - uses: actions/checkout@v3 + - name: Set up R + uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - name: Install R packages + run: | + install.packages(c('devtools', 'remotes')) + remotes::install_deps(dependencies = TRUE) + shell: Rscript {0} + working-directory: r-package + + - name: Install system dependencies + run: | + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') + working-directory: r-package + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3 + - name: Build with Gradle + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + with: + arguments: build + build-root-directory: java-r5rcore + + - name: Create pull request + # https://github.com/actions/checkout/pull/1184 + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + mv java-r5rcore/build/libs/java-r5rcore-*.jar r-package/inst/jar/r5r.jar + git add r-package/inst/jar/r5r.jar + git commit -m "Rebuild JAR for commit ${GITHUB_SHA}" + git push \ No newline at end of file diff --git a/java-r5rcore/.gitignore b/java-r5rcore/.gitignore new file mode 100644 index 00000000..1f94fa77 --- /dev/null +++ b/java-r5rcore/.gitignore @@ -0,0 +1,3 @@ +.idea +.gradle +build diff --git a/java-r5rcore/.idea/.gitignore b/java-r5rcore/.idea/.gitignore deleted file mode 100644 index 26d33521..00000000 --- a/java-r5rcore/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/java-r5rcore/.idea/.name b/java-r5rcore/.idea/.name deleted file mode 100644 index 9422dbc8..00000000 --- a/java-r5rcore/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -r5r \ No newline at end of file diff --git a/java-r5rcore/.idea/artifacts/r5r_1_0_0_jar.xml b/java-r5rcore/.idea/artifacts/r5r_1_1_0_jar.xml similarity index 67% rename from java-r5rcore/.idea/artifacts/r5r_1_0_0_jar.xml rename to java-r5rcore/.idea/artifacts/r5r_1_1_0_jar.xml index 28cbc139..116c0fea 100644 --- a/java-r5rcore/.idea/artifacts/r5r_1_0_0_jar.xml +++ b/java-r5rcore/.idea/artifacts/r5r_1_1_0_jar.xml @@ -1,7 +1,7 @@ - + $PROJECT_DIR$/../r-package/inst/jar - + diff --git a/java-r5rcore/.idea/libraries/JRI.xml b/java-r5rcore/.idea/libraries/JRI.xml deleted file mode 100644 index ec21cd8b..00000000 --- a/java-r5rcore/.idea/libraries/JRI.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/java-r5rcore/.idea/libraries/r5_v6_8_all.xml b/java-r5rcore/.idea/libraries/r5_v6_9_all.xml similarity index 55% rename from java-r5rcore/.idea/libraries/r5_v6_8_all.xml rename to java-r5rcore/.idea/libraries/r5_v6_9_all.xml index 4179b5ec..fa926685 100644 --- a/java-r5rcore/.idea/libraries/r5_v6_8_all.xml +++ b/java-r5rcore/.idea/libraries/r5_v6_9_all.xml @@ -1,7 +1,7 @@ - + - + diff --git a/java-r5rcore/.idea/misc.xml b/java-r5rcore/.idea/misc.xml index 3950286f..030b5fe0 100644 --- a/java-r5rcore/.idea/misc.xml +++ b/java-r5rcore/.idea/misc.xml @@ -1,6 +1,7 @@ - + + diff --git a/java-r5rcore/.idea/modules.xml b/java-r5rcore/.idea/modules.xml deleted file mode 100644 index fcb4a31b..00000000 --- a/java-r5rcore/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/java-r5rcore/.idea/uiDesigner.xml b/java-r5rcore/.idea/uiDesigner.xml deleted file mode 100644 index e96534fb..00000000 --- a/java-r5rcore/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/java-r5rcore/.idea/vcs.xml b/java-r5rcore/.idea/vcs.xml deleted file mode 100644 index 6c0b8635..00000000 --- a/java-r5rcore/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/java-r5rcore/build.gradle b/java-r5rcore/build.gradle new file mode 100644 index 00000000..d43453f0 --- /dev/null +++ b/java-r5rcore/build.gradle @@ -0,0 +1,37 @@ +plugins { + id 'java' +} + +group 'org.ipea' +version '1.0.2-SNAPSHOT' + +// Build against the version of R5 that the current r5r download_r5 function will +// grab +def baos = new ByteArrayOutputStream() +exec { + commandLine 'R', '--no-save', '-q', '-s', '-e', 'setwd("../r-package"); devtools::load_all(quiet=T); cat(download_r5());' + standardOutput = baos +} +def r5Path = baos.toString() + +def rjava_baos = new ByteArrayOutputStream() +exec { + commandLine 'R', '--no-save', '-q', '-s', '-e', 'cat(system.file("jri/JRI.jar", package="rJava"))' + standardOutput = rjava_baos +} +def rJavaPath = rjava_baos.toString() + +println(rJavaPath) + +sourceSets { + main { + java { + srcDirs = ['src'] + } + } +} + +dependencies { + implementation files(r5Path) + implementation files(rJavaPath) +} \ No newline at end of file diff --git a/java-r5rcore/gradle/wrapper/gradle-wrapper.jar b/java-r5rcore/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..ccebba77 Binary files /dev/null and b/java-r5rcore/gradle/wrapper/gradle-wrapper.jar differ diff --git a/java-r5rcore/gradle/wrapper/gradle-wrapper.properties b/java-r5rcore/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..42defcc9 --- /dev/null +++ b/java-r5rcore/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +networkTimeout=10000 +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/java-r5rcore/gradlew b/java-r5rcore/gradlew new file mode 100755 index 00000000..79a61d42 --- /dev/null +++ b/java-r5rcore/gradlew @@ -0,0 +1,244 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/java-r5rcore/gradlew.bat b/java-r5rcore/gradlew.bat new file mode 100644 index 00000000..6689b85b --- /dev/null +++ b/java-r5rcore/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/java-r5rcore/r5r.iml b/java-r5rcore/r5r.iml deleted file mode 100644 index 6c422515..00000000 --- a/java-r5rcore/r5r.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/java-r5rcore/src/org/ipea/r5r/Fares/FareStructure.java b/java-r5rcore/src/org/ipea/r5r/Fares/FareStructure.java index 0ba5b252..e15d794e 100644 --- a/java-r5rcore/src/org/ipea/r5r/Fares/FareStructure.java +++ b/java-r5rcore/src/org/ipea/r5r/Fares/FareStructure.java @@ -3,11 +3,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.PropertyNamingStrategy; import java.util.ArrayList; import java.util.List; +import static org.ipea.r5r.JsonUtil.OBJECT_MAPPER; + @JsonIgnoreProperties(ignoreUnknown = true) public class FareStructure { @@ -92,10 +92,8 @@ public FareStructure() { } public static FareStructure fromJson(String data) { - ObjectMapper objectMapper = new ObjectMapper(); try { - objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); - return objectMapper.readValue(data, FareStructure.class); + return OBJECT_MAPPER.readValue(data, FareStructure.class); } catch (JsonProcessingException e) { e.printStackTrace(); return null; @@ -103,10 +101,8 @@ public static FareStructure fromJson(String data) { } public String toJson() { - ObjectMapper objectMapper = new ObjectMapper(); try { - objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); - return objectMapper.writeValueAsString(this); + return OBJECT_MAPPER.writeValueAsString(this); } catch (JsonProcessingException e) { e.printStackTrace(); } diff --git a/java-r5rcore/src/org/ipea/r5r/Fares/RuleBasedInRoutingFareCalculator.java b/java-r5rcore/src/org/ipea/r5r/Fares/RuleBasedInRoutingFareCalculator.java index c3c767eb..729f0c84 100644 --- a/java-r5rcore/src/org/ipea/r5r/Fares/RuleBasedInRoutingFareCalculator.java +++ b/java-r5rcore/src/org/ipea/r5r/Fares/RuleBasedInRoutingFareCalculator.java @@ -112,7 +112,7 @@ public FareBounds calculateFare(McRaptorSuboptimalPathProfileRouter.McRaptorStat int currentBoardTime = -1; // first leg of multimodal trip - if (patterns.size() > 0) { + if (!patterns.isEmpty()) { currentPatternIndex = patterns.get(0); previousBoardTime = boardTimes.get(0); diff --git a/java-r5rcore/src/org/ipea/r5r/JsonUtil.java b/java-r5rcore/src/org/ipea/r5r/JsonUtil.java new file mode 100644 index 00000000..d9632291 --- /dev/null +++ b/java-r5rcore/src/org/ipea/r5r/JsonUtil.java @@ -0,0 +1,15 @@ +package org.ipea.r5r; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; + +/** + * Contains a static ObjectMapper for use in R5R. + */ +public class JsonUtil { + public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + static { + OBJECT_MAPPER.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); + } +} \ No newline at end of file diff --git a/java-r5rcore/src/org/ipea/r5r/Process/AccessibilityEstimator.java b/java-r5rcore/src/org/ipea/r5r/Process/AccessibilityEstimator.java index 2fc1122b..19b8cdbc 100644 --- a/java-r5rcore/src/org/ipea/r5r/Process/AccessibilityEstimator.java +++ b/java-r5rcore/src/org/ipea/r5r/Process/AccessibilityEstimator.java @@ -37,6 +37,11 @@ public void setDecayFunction(String decayFunction, double decayValue) { this.decayFunction.prepare(); } + @Override + protected boolean isOneToOne() { + return false; + } + public AccessibilityEstimator(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) { super(threadPool, transportNetwork, routingProperties); } diff --git a/java-r5rcore/src/org/ipea/r5r/Process/DetailedItineraryPlanner.java b/java-r5rcore/src/org/ipea/r5r/Process/DetailedItineraryPlanner.java index d0b56b68..324b0720 100644 --- a/java-r5rcore/src/org/ipea/r5r/Process/DetailedItineraryPlanner.java +++ b/java-r5rcore/src/org/ipea/r5r/Process/DetailedItineraryPlanner.java @@ -18,6 +18,11 @@ public class DetailedItineraryPlanner extends R5Process { private boolean dropItineraryGeometry = false; public void dropItineraryGeometry() { dropItineraryGeometry = true; } + @Override + protected boolean isOneToOne() { + return true; + } + public DetailedItineraryPlanner(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) { super(threadPool, transportNetwork, routingProperties); } diff --git a/java-r5rcore/src/org/ipea/r5r/Process/FastDetailedItineraryPlanner.java b/java-r5rcore/src/org/ipea/r5r/Process/FastDetailedItineraryPlanner.java index 579c4f41..9619ebe7 100644 --- a/java-r5rcore/src/org/ipea/r5r/Process/FastDetailedItineraryPlanner.java +++ b/java-r5rcore/src/org/ipea/r5r/Process/FastDetailedItineraryPlanner.java @@ -25,6 +25,11 @@ private boolean hasFares() { return routingProperties.fareCalculator != null; } + @Override + protected boolean isOneToOne() { + return true; + } + public FastDetailedItineraryPlanner(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) { super(threadPool, transportNetwork, routingProperties); } diff --git a/java-r5rcore/src/org/ipea/r5r/Process/ParetoFrontierCalculator.java b/java-r5rcore/src/org/ipea/r5r/Process/ParetoFrontierCalculator.java index 714f96ff..b233680f 100644 --- a/java-r5rcore/src/org/ipea/r5r/Process/ParetoFrontierCalculator.java +++ b/java-r5rcore/src/org/ipea/r5r/Process/ParetoFrontierCalculator.java @@ -15,6 +15,11 @@ public class ParetoFrontierCalculator extends R5Process { + @Override + protected boolean isOneToOne() { + return false; + } + public ParetoFrontierCalculator(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) { super(threadPool, transportNetwork, routingProperties); } diff --git a/java-r5rcore/src/org/ipea/r5r/Process/ParetoItineraryPlanner.java b/java-r5rcore/src/org/ipea/r5r/Process/ParetoItineraryPlanner.java index b71ee0e0..57a1a394 100644 --- a/java-r5rcore/src/org/ipea/r5r/Process/ParetoItineraryPlanner.java +++ b/java-r5rcore/src/org/ipea/r5r/Process/ParetoItineraryPlanner.java @@ -16,6 +16,11 @@ public class ParetoItineraryPlanner extends R5Process { public static boolean travelAllowanceActive = true; + @Override + protected boolean isOneToOne() { + return true; + } + public ParetoItineraryPlanner(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) { super(threadPool, transportNetwork, routingProperties); } diff --git a/java-r5rcore/src/org/ipea/r5r/Process/R5Process.java b/java-r5rcore/src/org/ipea/r5r/Process/R5Process.java index 9e070f9c..58dbda9b 100644 --- a/java-r5rcore/src/org/ipea/r5r/Process/R5Process.java +++ b/java-r5rcore/src/org/ipea/r5r/Process/R5Process.java @@ -59,6 +59,8 @@ public abstract class R5Process { protected int maxCarTime; protected int maxTripDuration; + protected abstract boolean isOneToOne(); + public R5Process(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) { this.r5rThreadPool = threadPool; this.transportNetwork = transportNetwork; @@ -189,7 +191,7 @@ private RDataFrame tryRunProcess(AtomicInteger totalProcessed, int index) { } if (Utils.saveOutputToCsv & results != null) { - String filename = Utils.outputCsvFolder + "/from_" + fromIds[index] + ".csv"; + String filename = getCsvFilename(index); results.saveToCsv(filename); results.clear(); } @@ -204,6 +206,20 @@ private RDataFrame tryRunProcess(AtomicInteger totalProcessed, int index) { return Utils.saveOutputToCsv ? null : results; } + private String getCsvFilename(int index) { + String filename; + if (this.isOneToOne()) { + // one-to-one functions, such as detailed itineraries + // save one file per origin-destination pair + filename = Utils.outputCsvFolder + "/from_" + fromIds[index] + "_to_" + toIds[index] + ".csv"; + } else { + // one-to-many functions, such as travel time matrix + // save one file per origin + filename = Utils.outputCsvFolder + "/from_" + fromIds[index] + ".csv"; + } + return filename; + } + protected abstract RDataFrame runProcess(int index) throws ParseException; private RDataFrame mergeResults(List processResults) { diff --git a/java-r5rcore/src/org/ipea/r5r/Process/TravelTimeMatrixComputer.java b/java-r5rcore/src/org/ipea/r5r/Process/TravelTimeMatrixComputer.java index 1199b721..840c77d6 100644 --- a/java-r5rcore/src/org/ipea/r5r/Process/TravelTimeMatrixComputer.java +++ b/java-r5rcore/src/org/ipea/r5r/Process/TravelTimeMatrixComputer.java @@ -87,6 +87,11 @@ public void unreachable() { private static final Logger LOG = LoggerFactory.getLogger(TravelTimeMatrixComputer.class); + @Override + protected boolean isOneToOne() { + return false; + } + public TravelTimeMatrixComputer(ForkJoinPool threadPool, TransportNetwork transportNetwork, RoutingProperties routingProperties) { super(threadPool, transportNetwork, routingProperties); } diff --git a/java-r5rcore/src/org/ipea/r5r/R5RCore.java b/java-r5rcore/src/org/ipea/r5r/R5RCore.java index fb59efc1..6895e06d 100644 --- a/java-r5rcore/src/org/ipea/r5r/R5RCore.java +++ b/java-r5rcore/src/org/ipea/r5r/R5RCore.java @@ -29,7 +29,7 @@ public class R5RCore { - public static final String R5_VERSION = "6.7"; + public static final String R5_VERSION = "6.9"; public static final String R5R_VERSION = "1.0.0"; private int numberOfThreads; diff --git a/java-r5rcore/src/org/ipea/r5r/RoutingProperties.java b/java-r5rcore/src/org/ipea/r5r/RoutingProperties.java index 8f7dba5e..72f4d9bc 100644 --- a/java-r5rcore/src/org/ipea/r5r/RoutingProperties.java +++ b/java-r5rcore/src/org/ipea/r5r/RoutingProperties.java @@ -3,8 +3,13 @@ import com.conveyal.r5.analyst.cluster.PathResult; import com.conveyal.r5.analyst.fare.*; import com.conveyal.r5.transit.TransitLayer; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.core.JsonProcessingException; import org.ipea.r5r.Fares.RuleBasedInRoutingFareCalculator; +import static org.ipea.r5r.JsonUtil.OBJECT_MAPPER; + + public class RoutingProperties { public double walkSpeed; @@ -26,7 +31,19 @@ public class RoutingProperties { public TransitLayer transitLayer; public void setFareCalculatorJson(String fareCalculatorJson) { - this.fareCalculator = new RuleBasedInRoutingFareCalculator(transitLayer, fareCalculatorJson); + // first, check to see if this is a built-in R5 fare calculator JSON representation + try { + ObjectNode node = OBJECT_MAPPER.readValue(fareCalculatorJson, ObjectNode.class); + // https://stackoverflow.com/questions/26190851 + if (node.has("type")) { + this.fareCalculator = OBJECT_MAPPER.readValue(fareCalculatorJson, InRoutingFareCalculator.class); + } else { + this.fareCalculator = new RuleBasedInRoutingFareCalculator(transitLayer, fareCalculatorJson); + } + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } public RoutingProperties() { diff --git a/r-package/DESCRIPTION b/r-package/DESCRIPTION index a6c7c84e..815dc195 100644 --- a/r-package/DESCRIPTION +++ b/r-package/DESCRIPTION @@ -11,7 +11,7 @@ Authors@R: c( comment = c(ORCID = "0000-0001-8066-1105")), person("Carlos Kaue Vieira", "Braga", , "kaue@kauebraga.dev", role = "aut", comment = c(ORCID = "0000-0002-6104-7297")), - person("Matthew Wigginton", "Conway", , "mwconway@asu.edu", role = "aut", + person("Matthew Wigginton", "Bhagat-Conway", , "mwbc@unc.edu", role = "aut", comment = c(ORCID = "0000-0002-1210-2982")), person("Ipea - Institute for Applied Economic Research", role = c("cph", "fnd")) ) diff --git a/r-package/R/accessibility.R b/r-package/R/accessibility.R index 71842f95..28a3244d 100644 --- a/r-package/R/accessibility.R +++ b/r-package/R/accessibility.R @@ -230,16 +230,6 @@ accessibility <- function(r5r_core, set_output_dir(r5r_core, output_dir) set_cutoffs(r5r_core, cutoffs, decay_function) - # accessibility cannot be computed on frequencies-based GTFS when a - # Fare Structure is set, because it uses McRaptor - if (!is.null(fare_structure) & r5r_core$hasFrequencies()) { - stop( - "Assertion on 'r5r_core' failed: None of the GTFS feeds used to create ", - "the transit network can contain a 'frequencies' table. Try using ", - "gtfstools::frequencies_to_stop_times() to create a suitable feed." - ) - } - # call r5r_core method and process results ------------------------------ # wrap r5r_core inputs in arrays (this helps to simplify the Java code) diff --git a/r-package/R/fare_structure.R b/r-package/R/fare_structure.R index da661b38..be4d6e68 100644 --- a/r-package/R/fare_structure.R +++ b/r-package/R/fare_structure.R @@ -336,127 +336,134 @@ assert_fare_structure <- function(fare_structure) { # TODO: fares_per_route$route_id must be unique checkmate::assert_list(fare_structure, any.missing = FALSE) - element_names <- c( - "max_discounted_transfers", - "transfer_time_allowance", - "fare_cap", - "fares_per_type", - "fares_per_transfer", - "fares_per_route", - "debug_settings" - ) - checkmate::assert_names( - names(fare_structure), - type = "unique", - must.include = element_names, - subset.of = element_names - ) + if ("type" %in% names(fare_structure)) { + # this is an R5 built-in fare structure + return(invisible(TRUE)) + } else { + # This is an R5R fare structure object + + element_names <- c( + "max_discounted_transfers", + "transfer_time_allowance", + "fare_cap", + "fares_per_type", + "fares_per_transfer", + "fares_per_route", + "debug_settings" + ) + checkmate::assert_names( + names(fare_structure), + type = "unique", + must.include = element_names, + subset.of = element_names + ) - checkmate::assert_number(fare_structure$max_discounted_transfers, lower = 0) - checkmate::assert_number(fare_structure$transfer_time_allowance, lower = 0) - checkmate::assert_number(fare_structure$fare_cap, lower = 0) + checkmate::assert_number(fare_structure$max_discounted_transfers, lower = 0) + checkmate::assert_number(fare_structure$transfer_time_allowance, lower = 0) + checkmate::assert_number(fare_structure$fare_cap, lower = 0) - checkmate::expect_data_frame(fare_structure$fares_per_type) - checkmate::expect_character( - fare_structure$fares_per_type$type, - any.missing = FALSE, - unique = TRUE - ) - checkmate::expect_logical( - fare_structure$fares_per_type$unlimited_transfers, - any.missing = FALSE - ) - checkmate::expect_logical( - fare_structure$fares_per_type$allow_same_route_transfer, - any.missing = FALSE - ) - checkmate::expect_logical( - fare_structure$fares_per_type$use_route_fare, - any.missing = FALSE - ) - checkmate::expect_numeric( - fare_structure$fares_per_type$fare, - any.missing = FALSE, - lower = 0, - finite = TRUE - ) + checkmate::expect_data_frame(fare_structure$fares_per_type) + checkmate::expect_character( + fare_structure$fares_per_type$type, + any.missing = FALSE, + unique = TRUE + ) + checkmate::expect_logical( + fare_structure$fares_per_type$unlimited_transfers, + any.missing = FALSE + ) + checkmate::expect_logical( + fare_structure$fares_per_type$allow_same_route_transfer, + any.missing = FALSE + ) + checkmate::expect_logical( + fare_structure$fares_per_type$use_route_fare, + any.missing = FALSE + ) + checkmate::expect_numeric( + fare_structure$fares_per_type$fare, + any.missing = FALSE, + lower = 0, + finite = TRUE + ) - checkmate::expect_data_frame(fare_structure$fares_per_transfer) - if (length(names(fare_structure$fares_per_transfer)) > 0) { + checkmate::expect_data_frame(fare_structure$fares_per_transfer) + if (length(names(fare_structure$fares_per_transfer)) > 0) { + checkmate::expect_character( + fare_structure$fares_per_transfer$first_leg, + any.missing = FALSE + ) + checkmate::assert_names( + fare_structure$fares_per_transfer$first_leg, + subset.of = unique(fare_structure$fares_per_type$type) + ) + checkmate::expect_character( + fare_structure$fares_per_transfer$second_leg, + any.missing = FALSE + ) + checkmate::assert_names( + fare_structure$fares_per_transfer$second_leg, + subset.of = unique(fare_structure$fares_per_type$type) + ) + checkmate::expect_numeric( + fare_structure$fares_per_transfer$fare, + any.missing = FALSE, + lower = 0, + finite = TRUE + ) + } + + checkmate::expect_data_frame(fare_structure$fares_per_route) checkmate::expect_character( - fare_structure$fares_per_transfer$first_leg, + fare_structure$fares_per_route$agency_id, any.missing = FALSE ) - checkmate::assert_names( - fare_structure$fares_per_transfer$first_leg, - subset.of = unique(fare_structure$fares_per_type$type) + checkmate::expect_character( + fare_structure$fares_per_route$agency_name, + any.missing = FALSE ) checkmate::expect_character( - fare_structure$fares_per_transfer$second_leg, + fare_structure$fares_per_route$route_id, any.missing = FALSE ) - checkmate::assert_names( - fare_structure$fares_per_transfer$second_leg, - subset.of = unique(fare_structure$fares_per_type$type) + checkmate::expect_character( + fare_structure$fares_per_route$route_short_name, + any.missing = FALSE + ) + checkmate::expect_character( + fare_structure$fares_per_route$route_long_name, + any.missing = FALSE + ) + checkmate::expect_character( + fare_structure$fares_per_route$mode, + any.missing = FALSE ) checkmate::expect_numeric( - fare_structure$fares_per_transfer$fare, + fare_structure$fares_per_route$route_fare, any.missing = FALSE, lower = 0, finite = TRUE ) - } - - checkmate::expect_data_frame(fare_structure$fares_per_route) - checkmate::expect_character( - fare_structure$fares_per_route$agency_id, - any.missing = FALSE - ) - checkmate::expect_character( - fare_structure$fares_per_route$agency_name, - any.missing = FALSE - ) - checkmate::expect_character( - fare_structure$fares_per_route$route_id, - any.missing = FALSE - ) - checkmate::expect_character( - fare_structure$fares_per_route$route_short_name, - any.missing = FALSE - ) - checkmate::expect_character( - fare_structure$fares_per_route$route_long_name, - any.missing = FALSE - ) - checkmate::expect_character( - fare_structure$fares_per_route$mode, - any.missing = FALSE - ) - checkmate::expect_numeric( - fare_structure$fares_per_route$route_fare, - any.missing = FALSE, - lower = 0, - finite = TRUE - ) - checkmate::expect_character( - fare_structure$fares_per_route$fare_type, - any.missing = FALSE - ) - checkmate::assert_names( - fare_structure$fares_per_route$fare_type, - subset.of = unique(fare_structure$fares_per_type$type) - ) + checkmate::expect_character( + fare_structure$fares_per_route$fare_type, + any.missing = FALSE + ) + checkmate::assert_names( + fare_structure$fares_per_route$fare_type, + subset.of = unique(fare_structure$fares_per_type$type) + ) - debug_elements <- c("output_file", "trip_info") - checkmate::assert_list(fare_structure$debug_settings) - checkmate::assert_names( - names(fare_structure$debug_settings), - type = "unique", - must.include = debug_elements, - subset.of = debug_elements - ) - checkmate::assert_string(fare_structure$debug_settings$output_file) - checkmate::assert_string(fare_structure$debug_settings$trip_info) + debug_elements <- c("output_file", "trip_info") + checkmate::assert_list(fare_structure$debug_settings) + checkmate::assert_names( + names(fare_structure$debug_settings), + type = "unique", + must.include = debug_elements, + subset.of = debug_elements + ) + checkmate::assert_string(fare_structure$debug_settings$output_file) + checkmate::assert_string(fare_structure$debug_settings$trip_info) - return(invisible(TRUE)) + return(invisible(TRUE)) + } } diff --git a/r-package/R/pareto_frontier.R b/r-package/R/pareto_frontier.R index 2849bbf3..739f02fb 100644 --- a/r-package/R/pareto_frontier.R +++ b/r-package/R/pareto_frontier.R @@ -164,15 +164,6 @@ pareto_frontier <- function(r5r_core, set_output_dir(r5r_core, output_dir) set_fare_cutoffs(r5r_core, fare_cutoffs) - # pareto frontiers cannot be computed on frequencies-based GTFS, because it uses McRaptor - if (!is.null(fare_structure) & r5r_core$hasFrequencies()) { - stop( - "Assertion on 'r5r_core' failed: None of the GTFS feeds used to create ", - "the transit network can contain a 'frequencies' table. Try using ", - "gtfstools::frequencies_to_stop_times() to create a suitable feed." - ) - } - # call r5r_core method and process result ------------------------------- frontier <- r5r_core$paretoFrontier( diff --git a/r-package/R/set.R b/r-package/R/set.R index f83532f4..cee28b62 100644 --- a/r-package/R/set.R +++ b/r-package/R/set.R @@ -265,14 +265,17 @@ set_fare_structure <- function(r5r_core, fare_structure) { if (!is.null(fare_structure)) { assert_fare_structure(fare_structure) - if (fare_structure$fare_cap == Inf) { - fare_structure$fare_cap <- -1 - } - if (fare_structure$transfer_time_allowance == Inf) { - fare_structure$transfer_time_allowance <- -1 - } - if (fare_structure$max_discounted_transfers == Inf) { - fare_structure$max_discounted_transfers <- -1 + if (!("type" %in% names(fare_structure))) { + # this is an R5R fare structure object + if (fare_structure$fare_cap == Inf) { + fare_structure$fare_cap <- -1 + } + if (fare_structure$transfer_time_allowance == Inf) { + fare_structure$transfer_time_allowance <- -1 + } + if (fare_structure$max_discounted_transfers == Inf) { + fare_structure$max_discounted_transfers <- -1 + } } fare_settings_json <- jsonlite::toJSON(fare_structure, auto_unbox = TRUE) diff --git a/r-package/R/setup_r5.R b/r-package/R/setup_r5.R index 8b276eb3..219b84a8 100644 --- a/r-package/R/setup_r5.R +++ b/r-package/R/setup_r5.R @@ -127,22 +127,15 @@ setup_r5 <- function(data_path, if (is.null(check)) { return(invisible(NULL)) } } - # start r5r and R5 JAR - existing_files <- list.files(system.file("jar", package = "r5r")) - r5r_jar <- file.path( - system.file("jar", package = "r5r"), - existing_files[grepl("r5r", existing_files)] - ) - jri_jar <- file.path( - system.file("jar", package = "r5r"), - existing_files[grepl("JRI", existing_files)] - ) - # r5r jar + r5r_jar <- system.file("jar/r5r.jar", package = "r5r") rJava::.jaddClassPath(path = r5r_jar) + # R5 jar rJava::.jaddClassPath(path = jar_file) + # JRI jar + jri_jar <- system.file("jri/JRI.jar", package="rJava") rJava::.jaddClassPath(path = jri_jar) # check if data_path already has a network.dat file @@ -169,7 +162,12 @@ setup_r5 <- function(data_path, ) # build new r5r_core - r5r_core <- rJava::.jnew("org.ipea.r5r.R5RCore", data_path, verbose, elevation) + r5r_core <- rJava::.jnew("org.ipea.r5r.R5RCore", data_path, verbose, elevation, check=F) + ex = rJava::.jgetEx(clear=T) + if (!is.null(NULL)) { + ex$printStackTrace() + return(NULL) + } # display a message if there is a PBF file but no GTFS data if (any_pbf == TRUE & any_gtfs == FALSE) { diff --git a/r-package/R/travel_time_matrix.R b/r-package/R/travel_time_matrix.R index ab60ff26..bf925540 100644 --- a/r-package/R/travel_time_matrix.R +++ b/r-package/R/travel_time_matrix.R @@ -189,16 +189,6 @@ travel_time_matrix <- function(r5r_core, set_expanded_travel_times(r5r_core, FALSE) set_breakdown(r5r_core, FALSE) - # travel time matrix cannot be computed on frequencies-based GTFS when a - # Fare Structure is set, because it uses McRaptor - if (!is.null(fare_structure) & r5r_core$hasFrequencies()) { - stop( - "Assertion on 'r5r_core' failed: None of the GTFS feeds used to create ", - "the transit network can contain a 'frequencies' table. Try using ", - "gtfstools::frequencies_to_stop_times() to create a suitable feed." - ) - } - # call r5r_core method and process result ------------------------------- travel_times <- r5r_core$travelTimeMatrix( diff --git a/r-package/inst/jar/JRI.jar b/r-package/inst/jar/JRI.jar deleted file mode 100644 index 4bc71e40..00000000 Binary files a/r-package/inst/jar/JRI.jar and /dev/null differ diff --git a/r-package/inst/jar/r5r.jar b/r-package/inst/jar/r5r.jar new file mode 100644 index 00000000..ecd66c3e Binary files /dev/null and b/r-package/inst/jar/r5r.jar differ diff --git a/r-package/inst/jar/r5r_1_0_0.jar b/r-package/inst/jar/r5r_1_0_0.jar deleted file mode 100644 index 82f811f1..00000000 Binary files a/r-package/inst/jar/r5r_1_0_0.jar and /dev/null differ diff --git a/r-package/tests/tests_marcus/debug_fare_calculator.R b/r-package/tests/tests_marcus/debug_fare_calculator.R index f9d0c657..799a6be3 100644 --- a/r-package/tests/tests_marcus/debug_fare_calculator.R +++ b/r-package/tests/tests_marcus/debug_fare_calculator.R @@ -77,8 +77,8 @@ dest <- poi %>% sample_n(size = nrow(poi)) system.time( frontiers_df <- pareto_itineraries(r5r_core, - origins = poi[10, ], - destinations = poi[12, ], + # origins = poi[10, ], + # destinations = poi[12, ], # origins = poi[c(10, 10), ], # destinations = poi[c(9, 12), ], origins = orig, diff --git a/r-package/tests/tests_marcus/debug_fares_itineraries.R b/r-package/tests/tests_marcus/debug_fares_itineraries.R new file mode 100644 index 00000000..12e7213d --- /dev/null +++ b/r-package/tests/tests_marcus/debug_fares_itineraries.R @@ -0,0 +1,58 @@ +# load packages +#library("r5r") +devtools::load_all('.') +library("dplyr") +library("ggplot2") + +# build transport network +data_path <- system.file("extdata/poa", package = "r5r") +r5r_core <- setup_r5(data_path) + +# load origin/destination points +points <- read.csv(file.path(data_path, "poa_points_of_interest.csv")) + +# load fare structure object +fare_structure_path <- system.file( + "extdata/poa/fares/fares_poa.zip", + package = "r5r" +) +fare_structure <- read_fare_structure(fare_structure_path) + +# inputs +departure_datetime <- as.POSIXct("13-05-2019 14:00:00", + format = "%d-%m-%Y %H:%M:%S") +# plan itineraries +dit <- detailed_itineraries(r5r_core, + origins = points[10,], + destinations = points[12,], + mode = c("WALK", "TRANSIT"), + departure_datetime = departure_datetime, + max_trip_duration = 140, + fare_structure = fare_structure, + max_fare = 9, + shortest_path = FALSE, + drop_geometry = TRUE) + + +# build Pareto frontiers +pareto_df <- dit |> + group_by(option) |> + summarise(travel_time = max(total_duration), + fare = max(total_fare), + mode = paste(if_else(mode == "WALK", "", mode), collapse = " ")) |> + mutate(mode = if_else(mode == "", "WALK", mode)) + + +# plot Pareto frontiers +ggplot(pareto_df , aes(x=fare, y=travel_time)) + + geom_step() + + geom_point() + + geom_text(aes(label=mode), hjust = -0.1, vjust=-0.5) + + geom_text(aes(label=paste("BRL", scales::comma(fare, accuracy = 0.01))), + hjust = 0.3, vjust=1.5) + + scale_y_continuous(breaks = seq(0, 140, 20), limits = c(0, 140)) + + scale_x_continuous(breaks = 0:10, limits = c(0, 10), + labels = scales::comma_format(accuracy = 0.01)) + + theme_light() + + labs(x = "fare (BRL)", y = "travel time (minutes)", + subtitle = "Travel time and monetary cost of trips between\nFarrapos Station and Praia de Belas Shopping Mall") diff --git a/r-package/tests/tests_marcus/pareto_itineraries.R b/r-package/tests/tests_marcus/pareto_itineraries.R index 3fc1f596..fa5f2819 100644 --- a/r-package/tests/tests_marcus/pareto_itineraries.R +++ b/r-package/tests/tests_marcus/pareto_itineraries.R @@ -101,7 +101,7 @@ pareto_itineraries <- function(r5r_core, checkmate::assert_class(r5r_core, "jobjRef") # modes - mode_list <- select_mode(mode, mode_egress) + mode_list <- assign_mode(mode, mode_egress) # departure time departure <- posix_to_string(departure_datetime)