From e78f5569bcce22f6579460457b62f67a67ec5b90 Mon Sep 17 00:00:00 2001 From: rakow Date: Tue, 6 Aug 2024 11:09:52 +0200 Subject: [PATCH] started v3 version with matsim updates --- .mvn/wrapper/MavenWrapperDownloader.java | 117 ---- .mvn/wrapper/maven-wrapper.properties | 20 +- checkstyle.xml | 365 ++++++++++++ mvnw | 224 ++++--- mvnw.cmd | 57 +- pom.xml | 151 ++++- .../input/gladbeck-v3.0-10pct.config.xml | 545 ++++++++++++++++++ .../AirPollutionByVehicleCategory.java | 377 ------------ .../matsim/analysis/EmissionsAnalysis.java | 9 - .../java/org/matsim/analysis/PopAnalysis.java | 2 +- src/main/java/org/matsim/gui/MATSimGUI.java | 1 - .../prepare/AssignPersonAttributes.java | 11 +- .../org/matsim/run/RunGladbeckScenario.java | 298 +++++----- .../matsim/run/GladbeckIntegrationTest.java | 21 +- ...ntermodalPtAnalysisModeIdentifierTest.java | 188 ------ .../org/matsim/run/TestBicycleRouting.java | 23 +- .../java/org/matsim/run/TestKlimaTaler.java | 61 +- src/test/java/org/matsim/run/TestParking.java | 27 +- .../org/matsim/run/TestPersonAttributes.java | 12 +- src/test/java/org/matsim/run/TestPtFlat.java | 24 +- .../org/matsim/run/TestSchoolClosure.java | 32 +- 21 files changed, 1440 insertions(+), 1125 deletions(-) delete mode 100644 .mvn/wrapper/MavenWrapperDownloader.java create mode 100644 checkstyle.xml create mode 100644 scenarios/gladbeck-v3.0/input/gladbeck-v3.0-10pct.config.xml delete mode 100644 src/main/java/org/matsim/analysis/AirPollutionByVehicleCategory.java delete mode 100644 src/main/java/org/matsim/analysis/EmissionsAnalysis.java delete mode 100644 src/test/java/org/matsim/run/IntermodalPtAnalysisModeIdentifierTest.java diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index b901097..0000000 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2007-present the original author or 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 - * - * http://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. - */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 642d572..eacdc9e 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,18 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.5/apache-maven-3.9.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..d7bed60 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,365 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mvnw b/mvnw index 41c0f0c..8d937f4 100755 --- a/mvnw +++ b/mvnw @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# Maven Start Up Batch script +# Apache Maven Wrapper startup batch script, version 3.2.0 # # Required ENV vars: # ------------------ @@ -27,7 +27,6 @@ # # Optional ENV vars # ----------------- -# M2_HOME - location of maven2's installed home dir # MAVEN_OPTS - parameters passed to the Java VM when running Maven # e.g. to debug Maven itself, use # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @@ -36,6 +35,10 @@ if [ -z "$MAVEN_SKIP_RC" ] ; then + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + if [ -f /etc/mavenrc ] ; then . /etc/mavenrc fi @@ -50,7 +53,7 @@ fi cygwin=false; darwin=false; mingw=false -case "`uname`" in +case "$(uname)" in CYGWIN*) cygwin=true ;; MINGW*) mingw=true;; Darwin*) darwin=true @@ -58,9 +61,9 @@ case "`uname`" in # See https://developer.apple.com/library/mac/qa/qa1170/_index.html if [ -z "$JAVA_HOME" ]; then if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" + JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME else - export JAVA_HOME="/Library/Java/Home" + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME fi fi ;; @@ -68,68 +71,38 @@ esac if [ -z "$JAVA_HOME" ] ; then if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` + JAVA_HOME=$(java-config --jre-home) fi fi -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - # For Cygwin, ensure paths are in UNIX format before anything is touched if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") fi # For Mingw, ensure paths are in UNIX format before anything is touched if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && + JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" fi if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + javaHome="$(dirname "\"$javaExecutable\"")" + javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" else - javaExecutable="`readlink -f \"$javaExecutable\"`" + javaExecutable="$(readlink -f "\"$javaExecutable\"")" fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` + javaHome="$(dirname "\"$javaExecutable\"")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') JAVA_HOME="$javaHome" export JAVA_HOME fi @@ -145,7 +118,7 @@ if [ -z "$JAVACMD" ] ; then JAVACMD="$JAVA_HOME/bin/java" fi else - JAVACMD="`which java`" + JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" fi fi @@ -159,12 +132,9 @@ if [ -z "$JAVA_HOME" ] ; then echo "Warning: JAVA_HOME environment variable is not set." fi -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - # traverses directory structure from process work directory to filesystem root # first directory with .mvn subdirectory is considered project base directory find_maven_basedir() { - if [ -z "$1" ] then echo "Path not specified to find_maven_basedir" @@ -180,96 +150,99 @@ find_maven_basedir() { fi # workaround for JBEAP-8937 (on Solaris 10/Sparc) if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` + wdir=$(cd "$wdir/.." || exit 1; pwd) fi # end of workaround done - echo "${basedir}" + printf '%s' "$(cd "$basedir" || exit 1; pwd)" } # concatenates all lines of a file concat_lines() { if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' < "$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" fi } -BASE_DIR=`find_maven_basedir "$(pwd)"` +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") if [ -z "$BASE_DIR" ]; then exit 1; fi +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + ########################################################################################## # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central # This allows using the maven wrapper in projects that prohibit checking in binary data. ########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi + log "Couldn't find $wrapperJarPath, downloading it ..." + if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") fi if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" fi elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" fi - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" # For Cygwin, switch paths to Windows format before running javac if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" fi fi fi @@ -278,33 +251,58 @@ fi # End of extension ########################################################################################## -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; + esac +done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum > /dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi fi + MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" # For Cygwin, switch paths to Windows format before running java if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + CLASSPATH=$(cygpath --path --windows "$CLASSPATH") [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` + MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") fi # Provide a "standardized" way to retrieve the CLI args that will # work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" export MAVEN_CMD_LINE_ARGS WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain +# shellcheck disable=SC2086 # safe args exec "$JAVACMD" \ $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd index 8611571..c4586b5 100644 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -18,13 +18,12 @@ @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script +@REM Apache Maven Wrapper startup batch script, version 3.2.0 @REM @REM Required ENV vars: @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @@ -46,8 +45,8 @@ if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") @REM Execute a user defined script before this one if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre @REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* :skipRcPre @setlocal @@ -120,10 +119,10 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B ) @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central @@ -134,11 +133,11 @@ if exist %WRAPPER_JAR% ( ) ) else ( if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" ) if "%MVNW_VERBOSE%" == "true" ( echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% + echo Downloading from: %WRAPPER_URL% ) powershell -Command "&{"^ @@ -146,7 +145,7 @@ if exist %WRAPPER_JAR% ( "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ "}" if "%MVNW_VERBOSE%" == "true" ( echo Finished downloading %WRAPPER_JAR% @@ -154,11 +153,35 @@ if exist %WRAPPER_JAR% ( ) @REM End of extension +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + @REM Provide a "standardized" way to retrieve the CLI args that will @REM work with both Windows and non-Windows executions. set MAVEN_CMD_LINE_ARGS=%* -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* if ERRORLEVEL 1 goto error goto end @@ -168,15 +191,15 @@ set ERROR_CODE=1 :end @endlocal & set ERROR_CODE=%ERROR_CODE% -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost @REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" :skipRcPost @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause +if "%MAVEN_BATCH_PAUSE%"=="on" pause -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% -exit /B %ERROR_CODE% +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml index 432ed19..5d42c54 100644 --- a/pom.xml +++ b/pom.xml @@ -1,31 +1,36 @@ + + + org.matsim + matsim-all + + + + + + 2025.0-PR3388 + + + + + 4.0.0 com.github.matsim-scenarios matsim-gladbeck - 2.0-SNAPSHOT + 3.0-SNAPSHOT MATSim Gladbeck project MATSim Gladbeck project - - + + ${project.parent.version} - - - - - - - - 15.0-PR2210 - UTF-8 UTF-8 - 17 - 17 + 21 @@ -84,14 +89,12 @@ com.github.matsim-scenarios matsim-metropole-ruhr master-99292af8ca-1 - - - - - junit - junit - 4.13.2 - test + + + com.github.matsim-vsp + pt-extensions + + @@ -110,6 +113,24 @@ test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter + test + + + + org.assertj + assertj-core + test + + @@ -149,27 +170,58 @@ - com.github.matsim-org - GTFS2MATSim - 11.1 - + com.github.matsim-org + gtfs2matsim + fc8b13954d + + + org.matsim + matsim + + + org.apache.commons commons-csv - 1.9.0 + 1.11.0 org.apache.poi poi-ooxml - 4.1.1 + 5.3.0 com.github.matsim-vsp pt-extensions - 662c5ace49 + b39f03f2f0 + + + org.matsim + matsim + + + org.matsim.contrib + drt + + + org.matsim.contrib + dvrp + + + org.matsim.contrib + vsp + + + + + + + org.hsqldb + hsqldb + 2.7.3 @@ -179,11 +231,11 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M5 + 3.0.0-M9 - once + 1 - -Xmx6500m -Djava.awt.headless=true -Dmatsim.preferLocalDtds=true + @{argLine} -Xmx6500m -Djava.awt.headless=true -Dmatsim.preferLocalDtds=true @@ -249,6 +301,41 @@ + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.4.0 + + + com.puppycrawl.tools + checkstyle + 10.17.0 + + + com.github.sevntu-checkstyle + sevntu-checks + 1.44.1 + + + + checkstyle.xml + true + true + true + false + + + + checkstyle + package + + check + + + + + diff --git a/scenarios/gladbeck-v3.0/input/gladbeck-v3.0-10pct.config.xml b/scenarios/gladbeck-v3.0/input/gladbeck-v3.0-10pct.config.xml new file mode 100644 index 0000000..a7032c5 --- /dev/null +++ b/scenarios/gladbeck-v3.0/input/gladbeck-v3.0-10pct.config.xml @@ -0,0 +1,545 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/matsim/analysis/AirPollutionByVehicleCategory.java b/src/main/java/org/matsim/analysis/AirPollutionByVehicleCategory.java deleted file mode 100644 index 2219b01..0000000 --- a/src/main/java/org/matsim/analysis/AirPollutionByVehicleCategory.java +++ /dev/null @@ -1,377 +0,0 @@ -package org.matsim.analysis; - -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2017 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -import com.google.common.collect.Iterables; -import it.unimi.dsi.fastutil.objects.Object2DoubleMap; -import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap; -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVPrinter; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.application.MATSimAppCommand; -import org.matsim.application.options.CrsOptions; -import org.matsim.contrib.emissions.EmissionModule; -import org.matsim.contrib.emissions.HbefaVehicleCategory; -import org.matsim.contrib.emissions.Pollutant; -import org.matsim.contrib.emissions.analysis.EmissionsOnLinkEventHandler; -import org.matsim.contrib.emissions.events.ColdEmissionEvent; -import org.matsim.contrib.emissions.events.ColdEmissionEventHandler; -import org.matsim.contrib.emissions.events.WarmEmissionEvent; -import org.matsim.contrib.emissions.events.WarmEmissionEventHandler; -import org.matsim.contrib.emissions.utils.EmissionsConfigGroup; -import org.matsim.contrib.emissions.utils.EmissionsConfigGroup.DetailedVsAverageLookupBehavior; -import org.matsim.contrib.emissions.utils.EmissionsConfigGroup.HbefaRoadTypeSource; -import org.matsim.contrib.emissions.utils.EmissionsConfigGroup.NonScenarioVehicles; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.controler.AbstractModule; -import org.matsim.core.controler.Injector; -import org.matsim.core.events.EventsUtils; -import org.matsim.core.events.MatsimEventsReader; -import org.matsim.core.events.algorithms.EventWriterXML; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.core.utils.io.CipherUtils; -import org.matsim.vehicles.EngineInformation; -import org.matsim.vehicles.VehicleType; -import org.matsim.vehicles.VehicleUtils; -import picocli.CommandLine; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.nio.file.Files; -import java.nio.file.Path; -import java.text.NumberFormat; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import static org.matsim.application.ApplicationUtils.globFile; -import static org.matsim.contrib.emissions.Pollutant.*; - - -@CommandLine.Command( - name = "air-pollution-by-vehicle", - description = "Run offline air pollution analysis assuming default vehicles", - mixinStandardHelpOptions = true, - showDefaultValues = true -) -public class AirPollutionByVehicleCategory implements MATSimAppCommand { - - private static final Logger log = LogManager.getLogger(AirPollutionByVehicleCategory.class); - - @CommandLine.Parameters(paramLabel = "INPUT", arity = "1", description = "Path to run directory") - private Path runDirectory; - - @CommandLine.Option(names = "--runId", description = "Pattern to match runId.", defaultValue = "*") - private String runId; - - @CommandLine.Option(names = "--hbefa-warm", required = true) - private Path hbefaWarmFile; - - @CommandLine.Option(names = "--hbefa-cold", required = true) - private Path hbefaColdFile; - - @CommandLine.Option(names = "--hbefa-lookup", description = "Emission detailedVsAverageLookupBehavior", defaultValue = "directlyTryAverageTable") - private DetailedVsAverageLookupBehavior lookupBehavior; - - @CommandLine.Option(names = "-p", description = "Password for encrypted hbefa files", interactive = true, required = false) - private char[] password; - - @CommandLine.Option(names = "--output", description = "Output events file", required = false) - private Path output; - - @CommandLine.Option(names = "--vehicle-type", description = "Map vehicle type to Hbefa category", defaultValue = "defaultVehicleType=PASSENGER_CAR") - private Map vehicleCategories; - - @CommandLine.Option(names = "--use-default-road-types", description = "Add default hbefa_road_type link attributes to the network", defaultValue = "false") - private boolean useDefaultRoadTypes; - - @CommandLine.Mixin - private CrsOptions crs = new CrsOptions(); - - public AirPollutionByVehicleCategory() { - } - - public AirPollutionByVehicleCategory(Path runDirectory, String runId, Path hbefaFileWarm, Path hbefaFileCold, Path output) { - this.runDirectory = runDirectory; - this.runId = runId; - this.hbefaWarmFile = hbefaFileWarm; - this.hbefaColdFile = hbefaFileCold; - this.output = output; - } - - @Override - public Integer call() throws Exception { - - if (password != null) { - System.setProperty(CipherUtils.ENVIRONMENT_VARIABLE, new String(password)); - // null out the arrays when done - Arrays.fill(password, ' '); - } - - Config config = ConfigUtils.createConfig(); - config.vehicles().setVehiclesFile(globFile(runDirectory, runId, "vehicles")); - config.network().setInputFile(globFile(runDirectory, runId, "network")); - config.transit().setTransitScheduleFile(globFile(runDirectory, runId, "transitSchedule")); - config.transit().setVehiclesFile(globFile(runDirectory, runId, "transitVehicles")); - config.global().setCoordinateSystem(crs.getInputCRS()); - config.plans().setInputFile(null); - config.parallelEventHandling().setNumberOfThreads(null); - config.parallelEventHandling().setEstimatedNumberOfEvents(null); - config.global().setNumberOfThreads(1); - - EmissionsConfigGroup eConfig = ConfigUtils.addOrGetModule(config, EmissionsConfigGroup.class); - eConfig.setDetailedVsAverageLookupBehavior(lookupBehavior); - eConfig.setAverageColdEmissionFactorsFile(this.hbefaColdFile.toString()); - eConfig.setAverageWarmEmissionFactorsFile(this.hbefaWarmFile.toString()); - eConfig.setHbefaRoadTypeSource(HbefaRoadTypeSource.fromLinkAttributes); - eConfig.setNonScenarioVehicles(NonScenarioVehicles.ignore); - - final String eventsFile = globFile(runDirectory, runId, "events"); - - Scenario scenario = ScenarioUtils.loadScenario(config); - - if (useDefaultRoadTypes) { - log.info("Using integrated road types"); - // 1 / 0.9, default free speed factor - addDefaultRoadTypes(scenario.getNetwork(), 1.11); - } - - - log.info("Using vehicle category mapping: {}", vehicleCategories); - - for (VehicleType type : Iterables.concat( - scenario.getVehicles().getVehicleTypes().values(), - scenario.getTransitVehicles().getVehicleTypes().values())) { - - HbefaVehicleCategory cat = vehicleCategories.computeIfAbsent(type.getId().toString(), (k) -> { - log.warn("Vehicle type {} not mapped to a category, using {}", k, HbefaVehicleCategory.NON_HBEFA_VEHICLE); - return HbefaVehicleCategory.NON_HBEFA_VEHICLE; - }); - - EngineInformation carEngineInformation = type.getEngineInformation(); - VehicleUtils.setHbefaVehicleCategory(carEngineInformation, cat.toString()); - VehicleUtils.setHbefaTechnology(carEngineInformation, "average"); - VehicleUtils.setHbefaSizeClass(carEngineInformation, "average"); - VehicleUtils.setHbefaEmissionsConcept(carEngineInformation, "average"); - } - - EventsManager eventsManager = EventsUtils.createEventsManager(); - - AbstractModule module = new AbstractModule() { - @Override - public void install() { - bind(Scenario.class).toInstance(scenario); - bind(EventsManager.class).toInstance(eventsManager); - bind(EmissionModule.class); - } - }; - - if (output == null) { - output = Path.of(eventsFile.replace(".xml", ".emissions.xml")); - log.info("Writing to output {}", output); - } - - com.google.inject.Injector injector = Injector.createInjector(config, module); - - EmissionModule emissionModule = injector.getInstance(EmissionModule.class); - - EventWriterXML emissionEventWriter = new EventWriterXML(output.toString()); - - Handler aggrHandler = new Handler(); - EmissionsOnLinkEventHandler emissionsOnLinkEventHandler = new EmissionsOnLinkEventHandler(10.); - emissionModule.getEmissionEventsManager().addHandler(emissionEventWriter); - emissionModule.getEmissionEventsManager().addHandler(aggrHandler); - emissionModule.getEmissionEventsManager().addHandler(emissionsOnLinkEventHandler); - - - eventsManager.initProcessing(); - MatsimEventsReader matsimEventsReader = new MatsimEventsReader(eventsManager); - matsimEventsReader.readFile(eventsFile); - eventsManager.finishProcessing(); - - emissionEventWriter.closeFile(); - - try (CSVPrinter printer = new CSVPrinter(Files.newBufferedWriter(Path.of(output.toString() - .replace(".xml", ".footprint.csv").replace(".gz", ""))), CSVFormat.DEFAULT)) { - printer.printRecord("pollutant", "g"); - for (Object2DoubleMap.Entry e : aggrHandler.pollution.object2DoubleEntrySet()) { - printer.printRecord(e.getKey(), e.getDoubleValue()); - } - } - - - log.info("Emission analysis completed."); - - log.info("Writing output..."); - List pollutants2Output = Arrays.asList(CO2_TOTAL, NOx, PM, PM_non_exhaust); - NumberFormat nf = NumberFormat.getInstance(Locale.US); - nf.setMaximumFractionDigits(4); - nf.setGroupingUsed(false); - - BufferedWriter absolutWriter; - BufferedWriter perMeterWriter; - { - File absolutFile = new File(String.valueOf(Path.of(output.toString().replace(".xml", ".absolute.csv").replace(".gz", "")))); - File perMeterFile = new File(String.valueOf(Path.of(output.toString().replace(".xml", ".perLink.csv").replace(".gz", "")))); - - absolutWriter = new BufferedWriter(new FileWriter(absolutFile)); - perMeterWriter = new BufferedWriter(new FileWriter(perMeterFile)); - - absolutWriter.write("linkId"); - perMeterWriter.write("linkId"); - - for (Pollutant pollutant : pollutants2Output) { - absolutWriter.write(";" + pollutant); - perMeterWriter.write(";" + pollutant + " [g/m]"); - - } - absolutWriter.newLine(); - perMeterWriter.newLine(); - - - Map, Map> link2pollutants = emissionsOnLinkEventHandler.getLink2pollutants(); - - for (Id linkId : link2pollutants.keySet()) { - absolutWriter.write(linkId.toString()); - perMeterWriter.write(linkId.toString()); - - for (Pollutant pollutant : pollutants2Output) { - double emissionValue = 0.; - if (link2pollutants.get(linkId).get(pollutant) != null) { - emissionValue = link2pollutants.get(linkId).get(pollutant); - } - absolutWriter.write(";" + nf.format(emissionValue)); - - double emissionPerM = Double.NaN; - Link link = scenario.getNetwork().getLinks().get(linkId); - if (link != null) { - emissionPerM = emissionValue / link.getLength(); - } - perMeterWriter.write(";" + nf.format(emissionPerM)); - - } - absolutWriter.newLine(); - perMeterWriter.newLine(); - - } - - absolutWriter.close(); - - perMeterWriter.close(); - - } - - absolutWriter.close(); - perMeterWriter.close(); - - - log.info("Done"); - - return 0; - } - - /** - * Default logic to add hbefa road types. - */ - private void addDefaultRoadTypes(Network network, double speedFactor) { - // network - for (Link link : network.getLinks().values()) { - - double freespeed; - - if (link.getFreespeed() <= 13.888889) { - freespeed = link.getFreespeed() * speedFactor; - // for non motorway roads, the free speed level was reduced - } else { - freespeed = link.getFreespeed(); - // for motorways, the original speed levels seems ok. - } - - if (freespeed <= 8.333333333) { //30kmh - link.getAttributes().putAttribute("hbefa_road_type", "URB/Access/30"); - } else if (freespeed <= 11.111111111) { //40kmh - link.getAttributes().putAttribute("hbefa_road_type", "URB/Access/40"); - } else if (freespeed <= 13.888888889) { //50kmh - double lanes = link.getNumberOfLanes(); - if (lanes <= 1.0) { - link.getAttributes().putAttribute("hbefa_road_type", "URB/Local/50"); - } else if (lanes <= 2.0) { - link.getAttributes().putAttribute("hbefa_road_type", "URB/Distr/50"); - } else if (lanes > 2.0) { - link.getAttributes().putAttribute("hbefa_road_type", "URB/Trunk-City/50"); - } else { - throw new RuntimeException("NoOfLanes not properly defined"); - } - } else if (freespeed <= 16.666666667) { //60kmh - double lanes = link.getNumberOfLanes(); - if (lanes <= 1.0) { - link.getAttributes().putAttribute("hbefa_road_type", "URB/Local/60"); - } else if (lanes <= 2.0) { - link.getAttributes().putAttribute("hbefa_road_type", "URB/Trunk-City/60"); - } else if (lanes > 2.0) { - link.getAttributes().putAttribute("hbefa_road_type", "URB/MW-City/60"); - } else { - throw new RuntimeException("NoOfLanes not properly defined"); - } - } else if (freespeed <= 19.444444444) { //70kmh - link.getAttributes().putAttribute("hbefa_road_type", "URB/MW-City/70"); - } else if (freespeed <= 22.222222222) { //80kmh - link.getAttributes().putAttribute("hbefa_road_type", "URB/MW-Nat./80"); - } else if (freespeed > 22.222222222) { //faster - link.getAttributes().putAttribute("hbefa_road_type", "RUR/MW/>130"); - } else { - throw new RuntimeException("Link not considered..."); - } - } - - } - - - private static class Handler implements ColdEmissionEventHandler, WarmEmissionEventHandler { - - private final Object2DoubleMap pollution = new Object2DoubleOpenHashMap<>(); - - @Override - public void handleEvent(ColdEmissionEvent event) { - - for (Map.Entry pollutant : event.getColdEmissions().entrySet()) { - pollution.mergeDouble(pollutant.getKey(), pollutant.getValue(), Double::sum); - } - } - - @Override - public void handleEvent(WarmEmissionEvent event) { - - for (Map.Entry pollutant : event.getWarmEmissions().entrySet()) { - pollution.mergeDouble(pollutant.getKey(), pollutant.getValue(), Double::sum); - } - } - } - -} diff --git a/src/main/java/org/matsim/analysis/EmissionsAnalysis.java b/src/main/java/org/matsim/analysis/EmissionsAnalysis.java deleted file mode 100644 index e2220cb..0000000 --- a/src/main/java/org/matsim/analysis/EmissionsAnalysis.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.matsim.analysis; -import org.matsim.application.MATSimAppCommand; - -public class EmissionsAnalysis { - - public static void main (String[] args) throws Exception { - new AirPollutionByVehicleCategory().execute(args); - } -} diff --git a/src/main/java/org/matsim/analysis/PopAnalysis.java b/src/main/java/org/matsim/analysis/PopAnalysis.java index 62f482d..b436da6 100644 --- a/src/main/java/org/matsim/analysis/PopAnalysis.java +++ b/src/main/java/org/matsim/analysis/PopAnalysis.java @@ -48,7 +48,7 @@ public enum HomeLocationCategory {inside, outside, unknown} public static void main(String[] args) throws IOException { - new PopulationAnalysis().execute(args); + new PopAnalysis().execute(args); } @Override diff --git a/src/main/java/org/matsim/gui/MATSimGUI.java b/src/main/java/org/matsim/gui/MATSimGUI.java index a3bf805..90b0634 100644 --- a/src/main/java/org/matsim/gui/MATSimGUI.java +++ b/src/main/java/org/matsim/gui/MATSimGUI.java @@ -20,7 +20,6 @@ package org.matsim.gui; import org.matsim.run.RunGladbeckScenario; -import org.matsim.run.RunMetropoleRuhrScenario; import org.matsim.run.gui.Gui; public class MATSimGUI { diff --git a/src/main/java/org/matsim/prepare/AssignPersonAttributes.java b/src/main/java/org/matsim/prepare/AssignPersonAttributes.java index 8e73372..99b0298 100644 --- a/src/main/java/org/matsim/prepare/AssignPersonAttributes.java +++ b/src/main/java/org/matsim/prepare/AssignPersonAttributes.java @@ -1,19 +1,12 @@ package org.matsim.prepare; -import org.locationtech.jts.geom.prep.PreparedGeometry; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.population.Person; -import org.matsim.api.core.v01.population.Population; import org.matsim.application.analysis.HomeLocationFilter; import org.matsim.application.options.ShpOptions; import org.matsim.core.gbl.MatsimRandom; -import org.matsim.run.RunGladbeckScenario; -import org.matsim.utils.gis.shp2matsim.ShpGeometryUtils; -import org.opengis.feature.simple.SimpleFeature; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import java.util.Collection; -import java.util.List; public class AssignPersonAttributes { diff --git a/src/main/java/org/matsim/run/RunGladbeckScenario.java b/src/main/java/org/matsim/run/RunGladbeckScenario.java index 4eab6f1..7aedd51 100644 --- a/src/main/java/org/matsim/run/RunGladbeckScenario.java +++ b/src/main/java/org/matsim/run/RunGladbeckScenario.java @@ -11,8 +11,6 @@ import org.matsim.api.core.v01.population.Person; import org.matsim.application.MATSimApplication; import org.matsim.application.analysis.HomeLocationFilter; -import org.matsim.application.analysis.emissions.AirPollutionByVehicleCategory; -import org.matsim.application.analysis.emissions.AirPollutionSpatialAggregation; import org.matsim.application.analysis.noise.NoiseAnalysis; import org.matsim.application.options.ShpOptions; import org.matsim.application.prepare.population.DownSamplePopulation; @@ -20,7 +18,7 @@ import org.matsim.application.prepare.population.FixSubtourModes; import org.matsim.application.prepare.population.XYToLinks; import org.matsim.core.config.Config; -import org.matsim.core.config.groups.PlansCalcRouteConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.core.gbl.MatsimRandom; @@ -30,54 +28,47 @@ import org.matsim.prepare.AssignPersonAttributes; import org.matsim.prepare.BicyclePolicies; import org.matsim.prepare.PrepareOpenPopulation; -import org.matsim.prepare.ScenarioCutOut; import org.matsim.run.policies.KlimaTaler; import org.matsim.run.policies.PtFlatrate; import org.matsim.run.policies.ReduceSpeed; import org.matsim.run.policies.SchoolRoadsClosure; import org.matsim.utils.gis.shp2matsim.ShpGeometryUtils; import picocli.CommandLine; + import javax.annotation.Nullable; import java.io.BufferedWriter; import java.io.IOException; import java.util.*; @CommandLine.Command(header = ":: Gladbeck Scenario ::", version = RunGladbeckScenario.VERSION) -@MATSimApplication.Prepare({ScenarioCutOut.class, DownSamplePopulation.class, FixSubtourModes.class, XYToLinks.class, ExtractHomeCoordinates.class, BicyclePolicies.class, PrepareOpenPopulation.class}) -@MATSimApplication.Analysis({NoiseAnalysis.class, AirPollutionByVehicleCategory.class, AirPollutionSpatialAggregation.class}) -public class RunGladbeckScenario extends RunMetropoleRuhrScenario { - - public static final String VERSION = "v2.0"; - - private static final Logger log = LogManager.getLogger(RunGladbeckScenario.class); - - @CommandLine.Option(names = "--schoolClosure", defaultValue = "false", description = "measures to ban car on certain links") - boolean schoolClosure; - - @CommandLine.Option(names = "--tempo30Zone", defaultValue = "false", description = "measures to reduce car speed to 30 km/h in a zone") - boolean slowSpeedZone; - - @CommandLine.Option(names = "--tempo30Streets", defaultValue = "false", description = "measures to reduce car speed to 30 km/h on links definded by a shape file") - boolean slowSpeedOnDefinedLinks; - - @CommandLine.Mixin - private ShpOptions shp; - - @CommandLine.Option(names = "--simplePtFlat", defaultValue = "false", description = "measures to allow everyone to have free pt") - boolean scenarioWidePtFlat; - - @CommandLine.Option(names = "--ptFlat", defaultValue = "0", description = "measures to allow people in Gladbeck to have free pt, if set to zero no agent will have free pt") - int ptFlat; - - @CommandLine.Option(names = "--cityWidePtFlat", defaultValue = "false", description = "measures to allow every resident in Gladbeck to have free pt") - boolean cityWidePtFlat; - - @CommandLine.Option(names = "--cyclingCourse", defaultValue = "false", description = "measures to increase the ") - boolean cyclingCourse; - - @CommandLine.Option(names = "--klimaTaler", defaultValue = "0.0", description = "amount of money to give to a person to use pt, walk and bike") - double klimaTalerMoneyAmount; - +@MATSimApplication.Prepare({DownSamplePopulation.class, FixSubtourModes.class, XYToLinks.class, ExtractHomeCoordinates.class, BicyclePolicies.class, PrepareOpenPopulation.class}) +@MATSimApplication.Analysis({NoiseAnalysis.class}) +public class RunGladbeckScenario extends MATSimApplication { + + public static final String VERSION = "v2.0"; + + private static final Logger log = LogManager.getLogger(RunGladbeckScenario.class); + + @CommandLine.Option(names = "--schoolClosure", defaultValue = "false", description = "measures to ban car on certain links") + boolean schoolClosure; + + @CommandLine.Option(names = "--tempo30Zone", defaultValue = "false", description = "measures to reduce car speed to 30 km/h in a zone") + boolean slowSpeedZone; + + @CommandLine.Option(names = "--tempo30Streets", defaultValue = "false", description = "measures to reduce car speed to 30 km/h on links definded by a shape file") + boolean slowSpeedOnDefinedLinks; + @CommandLine.Option(names = "--simplePtFlat", defaultValue = "false", description = "measures to allow everyone to have free pt") + boolean scenarioWidePtFlat; + @CommandLine.Option(names = "--ptFlat", defaultValue = "0", description = "measures to allow people in Gladbeck to have free pt, if set to zero no agent will have free pt") + int ptFlat; + @CommandLine.Option(names = "--cityWidePtFlat", defaultValue = "false", description = "measures to allow every resident in Gladbeck to have free pt") + boolean cityWidePtFlat; + @CommandLine.Option(names = "--cyclingCourse", defaultValue = "false", description = "measures to increase the ") + boolean cyclingCourse; + @CommandLine.Option(names = "--klimaTaler", defaultValue = "0.0", description = "amount of money to give to a person to use pt, walk and bike") + double klimaTalerMoneyAmount; + @CommandLine.Mixin + private ShpOptions shp; @CommandLine.Option(names = {"--policy", "--p"}) private Set policies = new HashSet<>(); @@ -89,13 +80,47 @@ public RunGladbeckScenario(@Nullable Config config) { super(config); } - public RunGladbeckScenario() { - super(String.format("./scenarios/gladbeck-v2.0/input/gladbeck-%s-10pct.config.xml", VERSION)); - } + public RunGladbeckScenario() { + super(String.format("./scenarios/gladbeck-v2.0/input/gladbeck-%s-10pct.config.xml", VERSION)); + } + + public static void main(String[] args) { + MATSimApplication.run(RunGladbeckScenario.class, args); + } + + public static void addKlimaTaler(Controler controler, KlimaTaler klimaTaler) { + controler.addOverridingModule(new AbstractModule() { + @Override + public void install() { + addEventHandlerBinding().toInstance(klimaTaler); + addControlerListenerBinding().toInstance(klimaTaler); + new PersonMoneyEventsAnalysisModule(); + } + }); + } + + public static void addPtFlat(Controler controler, PtFlatrate ptFlatrate) { + controler.addOverridingModule(new AbstractModule() { + @Override + public void install() { + addEventHandlerBinding().toInstance(ptFlatrate); + addControlerListenerBinding().toInstance(ptFlatrate); + new PersonMoneyEventsAnalysisModule(); + } + }); + } + + private static void writeOutAgents(List> listOfIds) throws IOException { + BufferedWriter writer = IOUtils.getBufferedWriter("agentsWithFreePt.tsv"); - public static void main(String[] args) { - MATSimApplication.run(RunGladbeckScenario.class, args); - } + writer.write("Id"); + writer.newLine(); + for (Id listOfId : listOfIds) { + writer.write(listOfId.toString()); + writer.newLine(); + } + writer.close(); + } @Override protected Config prepareConfig(Config config) { @@ -104,44 +129,41 @@ protected Config prepareConfig(Config config) { throw new RuntimeException("A geo filter is required to apply policy changes to the network. Please add a path to a shape file by using the --shp option"); } - // Always switch off intermodal - this.intermodal = false; - - // so we don´t use the rvr accessEgressModeToLinkPlusTimeConstant - config.plansCalcRoute().setAccessEgressType(PlansCalcRouteConfigGroup.AccessEgressType.accessEgressModeToLink); - if (scenarioWidePtFlat) { - config.planCalcScore().getModes().get(TransportMode.pt).setDailyMonetaryConstant(0.0); - } + // so we don´t use the rvr accessEgressModeToLinkPlusTimeConstant + config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink); - // this is needed for the school closure case - config.network().setTimeVariantNetwork(true); - return super.prepareConfig(config); - } + if (scenarioWidePtFlat) { + config.scoring().getModes().get(TransportMode.pt).setDailyMonetaryConstant(0.0); + } - @Override - protected void prepareScenario(Scenario scenario) { - super.prepareScenario(scenario); + // this is needed for the school closure case + config.network().setTimeVariantNetwork(true); + return super.prepareConfig(config); + } - if (slowSpeedZone) { - ReduceSpeed.implementPushMeasuresByModifyingNetworkInArea(scenario.getNetwork(), ShpGeometryUtils.loadPreparedGeometries(IOUtils.resolveFileOrResource(shp.getShapeFile().toString()))); - } + @Override + protected void prepareScenario(Scenario scenario) { + super.prepareScenario(scenario); - if (slowSpeedOnDefinedLinks) { - ReduceSpeed.implementPushMeasuresByModifyingNetworkInArea(scenario.getNetwork(), ShpGeometryUtils.loadPreparedGeometries(IOUtils.resolveFileOrResource(shp.getShapeFile().toString()))); - } + if (slowSpeedZone) { + ReduceSpeed.implementPushMeasuresByModifyingNetworkInArea(scenario.getNetwork(), ShpGeometryUtils.loadPreparedGeometries(IOUtils.resolveFileOrResource(shp.getShapeFile().toString()))); + } - if (schoolClosure) { - List> listOfSchoolLinks = new ArrayList<>(); + if (slowSpeedOnDefinedLinks) { + ReduceSpeed.implementPushMeasuresByModifyingNetworkInArea(scenario.getNetwork(), ShpGeometryUtils.loadPreparedGeometries(IOUtils.resolveFileOrResource(shp.getShapeFile().toString()))); + } - // street in front of Mosaikschule - listOfSchoolLinks.add(Id.createLinkId("353353080004r")); - listOfSchoolLinks.add(Id.createLinkId("353353080004f")); + if (schoolClosure) { + List> listOfSchoolLinks = new ArrayList<>(); + // street in front of Mosaikschule + listOfSchoolLinks.add(Id.createLinkId("353353080004r")); + listOfSchoolLinks.add(Id.createLinkId("353353080004f")); - new SchoolRoadsClosure().closeSchoolLinks(listOfSchoolLinks, scenario.getNetwork(), 800, 1700); - } + new SchoolRoadsClosure().closeSchoolLinks(listOfSchoolLinks, scenario.getNetwork(), 800, 1700); + } if (cyclingCourse) { log.info("adding different citizenship's to the agents"); @@ -149,33 +171,33 @@ protected void prepareScenario(Scenario scenario) { } if (!policies.isEmpty()) { - //changing the network for the policy + //changing the network for the policy BicyclePolicies.applyPolicyChanges(scenario.getNetwork(), shp.getGeometry(), policies, bicycleFreedspeed); //delete routes from plans and linkId and facility id from activity - for (var person : scenario.getPopulation().getPersons().values()) { - var plan = person.getSelectedPlan(); - person.getPlans().clear(); - PopulationUtils.resetRoutes(plan); - for (var element : plan.getPlanElements()) { - if (element instanceof Activity act) { - act.setFacilityId(null); - act.setLinkId(null); - } - } - person.addPlan(plan); - } + for (var person : scenario.getPopulation().getPersons().values()) { + var plan = person.getSelectedPlan(); + person.getPlans().clear(); + PopulationUtils.resetRoutes(plan); + for (var element : plan.getPlanElements()) { + if (element instanceof Activity act) { + act.setFacilityId(null); + act.setLinkId(null); + } + } + person.addPlan(plan); + } } } - @Override - protected void prepareControler(Controler controler) { + @Override + protected void prepareControler(Controler controler) { - //controler.getConfig().vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.abort); - if (klimaTalerMoneyAmount != 0.0) { - log.info("add Klima taler with money amount: " + klimaTalerMoneyAmount); - KlimaTaler klimaTaler = new KlimaTaler(controler.getScenario().getConfig().plansCalcRoute().getBeelineDistanceFactors().get(TransportMode.walk), controler.getScenario().getNetwork(), klimaTalerMoneyAmount); - addKlimaTaler(controler, klimaTaler); - } + //controler.getConfig().vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.abort); + if (klimaTalerMoneyAmount != 0.0) { + log.info("add Klima taler with money amount: " + klimaTalerMoneyAmount); + KlimaTaler klimaTaler = new KlimaTaler(controler.getScenario().getConfig().routing().getBeelineDistanceFactors().get(TransportMode.walk), controler.getScenario().getNetwork(), klimaTalerMoneyAmount); + addKlimaTaler(controler, klimaTaler); + } controler.addOverridingModule(new AbstractModule() { @Override @@ -185,73 +207,39 @@ public void install() { }); - if (ptFlat !=0 || cityWidePtFlat) { + if (ptFlat != 0 || cityWidePtFlat) { List> agentsLivingInGladbeck = new ArrayList<>(); - List> agentsWithPtFlat = new ArrayList<>(); - HomeLocationFilter homeLocationFilter = new HomeLocationFilter(shp, controler.getScenario().getConfig().global().getCoordinateSystem(), controler.getScenario().getPopulation()); - - for (Person person: controler.getScenario().getPopulation().getPersons().values()) { - if (homeLocationFilter.test(controler.getScenario().getPopulation().getPersons().get(person.getId()))) { - agentsLivingInGladbeck.add(person.getId()); - } - } - - - if (cityWidePtFlat) { - agentsWithPtFlat.addAll(agentsLivingInGladbeck); - } else { - for (int ii= 0; ii < ptFlat; ii++) { - Random generator = MatsimRandom.getRandom(); - Object[] values = agentsLivingInGladbeck.toArray(); - var randomPerson = (Id) values[generator.nextInt(values.length)]; - agentsWithPtFlat.add(randomPerson); - agentsLivingInGladbeck.remove(randomPerson); - } - } - log.info("adding pt flat." + agentsWithPtFlat.size() +" agents will pay no pt cost"); + List> agentsWithPtFlat = new ArrayList<>(); + HomeLocationFilter homeLocationFilter = new HomeLocationFilter(shp, controler.getScenario().getConfig().global().getCoordinateSystem(), controler.getScenario().getPopulation()); + + for (Person person : controler.getScenario().getPopulation().getPersons().values()) { + if (homeLocationFilter.test(controler.getScenario().getPopulation().getPersons().get(person.getId()))) { + agentsLivingInGladbeck.add(person.getId()); + } + } + + + if (cityWidePtFlat) { + agentsWithPtFlat.addAll(agentsLivingInGladbeck); + } else { + for (int ii = 0; ii < ptFlat; ii++) { + Random generator = MatsimRandom.getRandom(); + Object[] values = agentsLivingInGladbeck.toArray(); + var randomPerson = (Id) values[generator.nextInt(values.length)]; + agentsWithPtFlat.add(randomPerson); + agentsLivingInGladbeck.remove(randomPerson); + } + } + log.info("adding pt flat." + agentsWithPtFlat.size() + " agents will pay no pt cost"); try { writeOutAgents(agentsWithPtFlat); } catch (IOException e) { throw new RuntimeException(e); } - addPtFlat(controler, new PtFlatrate(agentsWithPtFlat, controler.getConfig().planCalcScore().getModes().get(TransportMode.pt).getDailyMonetaryConstant())); - - } - super.prepareControler(controler); - } - - public static void addKlimaTaler(Controler controler, KlimaTaler klimaTaler) { - controler.addOverridingModule(new AbstractModule() { - @Override - public void install() { - addEventHandlerBinding().toInstance(klimaTaler); - addControlerListenerBinding().toInstance(klimaTaler); - new PersonMoneyEventsAnalysisModule(); - } - }); - } - - public static void addPtFlat(Controler controler, PtFlatrate ptFlatrate) { - controler.addOverridingModule(new AbstractModule() { - @Override - public void install() { - addEventHandlerBinding().toInstance(ptFlatrate); - addControlerListenerBinding().toInstance(ptFlatrate); - new PersonMoneyEventsAnalysisModule(); - } - }); - } - - private static void writeOutAgents(List> listOfIds) throws IOException { - BufferedWriter writer = IOUtils.getBufferedWriter("agentsWithFreePt.tsv"); - - writer.write("Id"); - writer.newLine(); - for (Id listOfId : listOfIds) { - writer.write(listOfId.toString()); - writer.newLine(); + addPtFlat(controler, new PtFlatrate(agentsWithPtFlat, controler.getConfig().scoring().getModes().get(TransportMode.pt).getDailyMonetaryConstant())); + } - writer.close(); - } + super.prepareControler(controler); + } } diff --git a/src/test/java/org/matsim/run/GladbeckIntegrationTest.java b/src/test/java/org/matsim/run/GladbeckIntegrationTest.java index 57ef5d7..df979ce 100644 --- a/src/test/java/org/matsim/run/GladbeckIntegrationTest.java +++ b/src/test/java/org/matsim/run/GladbeckIntegrationTest.java @@ -1,8 +1,7 @@ package org.matsim.run; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.TransportMode; @@ -10,19 +9,18 @@ import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.population.*; import org.matsim.application.MATSimApplication; -import org.matsim.application.options.SampleOptions; import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; import org.matsim.core.network.NetworkUtils; +import org.matsim.core.population.PersonUtils; import org.matsim.core.population.PopulationUtils; import org.matsim.testcases.MatsimTestUtils; -import playground.vsp.openberlinscenario.cemdap.output.ActivityTypes; import playground.vsp.scoring.IncomeDependentUtilityOfMoneyPersonScoringParameters; public class GladbeckIntegrationTest { - @Rule + + @RegisterExtension public MatsimTestUtils utils = new MatsimTestUtils(); @Test @@ -40,9 +38,10 @@ private static Population createTestPopulation(Scenario scenario) { Person bikePerson = PopulationUtils.getFactory().createPerson(Id.createPersonId("bikePerson")); Person walkPerson = PopulationUtils.getFactory().createPerson(Id.createPersonId("walkPerson")); - walkPerson.getAttributes().putAttribute(IncomeDependentUtilityOfMoneyPersonScoringParameters.PERSONAL_INCOME_ATTRIBUTE_NAME, 1.0); - carPerson.getAttributes().putAttribute(IncomeDependentUtilityOfMoneyPersonScoringParameters.PERSONAL_INCOME_ATTRIBUTE_NAME, 1.0); - bikePerson.getAttributes().putAttribute(IncomeDependentUtilityOfMoneyPersonScoringParameters.PERSONAL_INCOME_ATTRIBUTE_NAME, 1.0); + + PersonUtils.setIncome(walkPerson, 1.0); + PersonUtils.setIncome(bikePerson, 1.0); + PersonUtils.setIncome(carPerson, 1.0); PopulationFactory factory = population.getFactory(); Leg carLeg = factory.createLeg(TransportMode.car); @@ -90,7 +89,7 @@ public static class TestApplication extends RunGladbeckScenario { @Override protected Config prepareConfig(Config config) { config = super.prepareConfig(config); - config.controler().setLastIteration(1); + config.controller().setLastIteration(1); config.plans().setInputFile(null); return config; } diff --git a/src/test/java/org/matsim/run/IntermodalPtAnalysisModeIdentifierTest.java b/src/test/java/org/matsim/run/IntermodalPtAnalysisModeIdentifierTest.java deleted file mode 100644 index 84b9ecb..0000000 --- a/src/test/java/org/matsim/run/IntermodalPtAnalysisModeIdentifierTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* * - * * - * *********************************************************************** * - * * - * copyright : (C) 2022 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ -package org.matsim.run; - - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.api.core.v01.population.PlanElement; -import org.matsim.api.core.v01.population.PopulationFactory; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.pt.PtConstants; -import org.matsim.testcases.MatsimTestUtils; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author gleich - * - */ -public class IntermodalPtAnalysisModeIdentifierTest { - private static final Logger log = LogManager.getLogger( IntermodalPtAnalysisModeIdentifierTest.class ) ; - - @Rule public MatsimTestUtils utils = new MatsimTestUtils() ; - - @Test - public final void testSingleModeTrips() { - log.info("Running test0..."); - - IntermodalPtAnalysisModeIdentifier mainModeIdentifier = new IntermodalPtAnalysisModeIdentifier(); - - Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); - PopulationFactory factory = scenario.getPopulation().getFactory(); - - { - List planElements = new ArrayList<>(); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.pt)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.pt)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.walk)); - Assert.assertEquals("Wrong mode!", TransportMode.pt, mainModeIdentifier.identifyMainMode(planElements)); - } - - { - List planElements = new ArrayList<>(); - planElements.add(factory.createLeg(TransportMode.car)); - Assert.assertEquals("Wrong mode!", TransportMode.car, mainModeIdentifier.identifyMainMode(planElements)); - } - - { - List planElements = new ArrayList<>(); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId("drt interaction", null)); - planElements.add(factory.createLeg(TransportMode.bike)); - planElements.add(factory.createActivityFromLinkId("drt interaction", null)); - planElements.add(factory.createLeg(TransportMode.walk)); - Assert.assertEquals("Wrong mode!", TransportMode.bike, mainModeIdentifier.identifyMainMode(planElements)); - } - - log.info("Running test0... Done."); - } - - @Test - public final void testIntermodalPtTripWithWalk() { - log.info("Running testIntermodalPtDrtTrip..."); - - IntermodalPtAnalysisModeIdentifier mainModeIdentifier = new IntermodalPtAnalysisModeIdentifier(); - - Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); - PopulationFactory factory = scenario.getPopulation().getFactory(); - - { - List planElements = new ArrayList<>(); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId("bike interaction", null)); - planElements.add(factory.createLeg(TransportMode.bike)); - planElements.add(factory.createActivityFromLinkId("bike interaction", null)); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.pt)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.pt)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.walk)); - Assert.assertEquals("Wrong mode!", IntermodalPtAnalysisModeIdentifier.ANALYSIS_MAIN_MODE_PT_WITH_BIKE_USED_FOR_ACCESS_OR_EGRESS, - mainModeIdentifier.identifyMainMode(planElements)); - } - - { - List planElements = new ArrayList<>(); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId("car interaction", null)); - planElements.add(factory.createLeg(TransportMode.car)); - planElements.add(factory.createActivityFromLinkId("car interaction", null)); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.pt)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.pt)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.walk)); - Assert.assertEquals("Wrong mode!", IntermodalPtAnalysisModeIdentifier.ANALYSIS_MAIN_MODE_PT_WITH_CAR_USED_FOR_ACCESS_OR_EGRESS, - mainModeIdentifier.identifyMainMode(planElements)); - } - - { - List planElements = new ArrayList<>(); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId("bike interaction", null)); - planElements.add(factory.createLeg(TransportMode.bike)); - planElements.add(factory.createActivityFromLinkId("bike interaction", null)); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.pt)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.pt)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.walk)); - planElements.add(factory.createActivityFromLinkId("car interaction", null)); - planElements.add(factory.createLeg(TransportMode.car)); - planElements.add(factory.createActivityFromLinkId("car interaction", null)); - planElements.add(factory.createLeg(TransportMode.walk)); - Assert.assertEquals("Wrong mode!", IntermodalPtAnalysisModeIdentifier.ANALYSIS_MAIN_MODE_PT_WITH_BIKE_AND_CAR_USED_FOR_ACCESS_OR_EGRESS, - mainModeIdentifier.identifyMainMode(planElements)); - } - - log.info("Running testIntermodalPtDrtTrip... Done."); - } - - @Test(expected = RuntimeException.class) - public void testRuntimeExceptionTripWithoutMainMode() { - log.info("Running testRuntimeExceptionTripWithoutMainMode..."); - - IntermodalPtAnalysisModeIdentifier mainModeIdentifier = new IntermodalPtAnalysisModeIdentifier(); - - Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); - PopulationFactory factory = scenario.getPopulation().getFactory(); - - List planElements = new ArrayList<>(); - planElements.add(factory.createLeg(TransportMode.non_network_walk)); - planElements.add(factory.createActivityFromLinkId(PtConstants.TRANSIT_ACTIVITY_TYPE, null)); - planElements.add(factory.createLeg(TransportMode.non_network_walk)); - // should throw an exception, because main mode cannot be identified - mainModeIdentifier.identifyMainMode(planElements); - log.info("Running testRuntimeExceptionTripWithoutMainMode... Done."); - } - - @Test(expected = RuntimeException.class) - public void testRuntimeExceptionOnlyNonNetworkWalk() { - log.info("Running testRuntimeExceptionOnlyNonNetworkWalk..."); - - IntermodalPtAnalysisModeIdentifier mainModeIdentifier = new IntermodalPtAnalysisModeIdentifier(); - - Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); - PopulationFactory factory = scenario.getPopulation().getFactory(); - - List planElements = new ArrayList<>(); - planElements.add(factory.createLeg(TransportMode.non_network_walk)); - // should throw an exception, because non_network_walk is not a main mode - mainModeIdentifier.identifyMainMode(planElements); - } - -} diff --git a/src/test/java/org/matsim/run/TestBicycleRouting.java b/src/test/java/org/matsim/run/TestBicycleRouting.java index 42dc2d2..da67aa7 100644 --- a/src/test/java/org/matsim/run/TestBicycleRouting.java +++ b/src/test/java/org/matsim/run/TestBicycleRouting.java @@ -1,8 +1,8 @@ package org.matsim.run; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.prep.PreparedGeometry; @@ -15,26 +15,27 @@ import org.matsim.contrib.bicycle.BicycleConfigGroup; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.population.PersonUtils; import org.matsim.core.population.io.PopulationReader; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.utils.geometry.geotools.MGC; import org.matsim.testcases.MatsimTestUtils; import picocli.CommandLine; -import playground.vsp.scoring.IncomeDependentUtilityOfMoneyPersonScoringParameters; import java.util.stream.Collectors; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -@Ignore + +@Disabled public class TestBicycleRouting { private static final Id personId = Id.createPersonId("test-person"); private static final String inputNetworkFile = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/metropole-ruhr/metropole-ruhr-v1.0/input/metropole-ruhr-v1.4.network_resolutionHigh-with-pt.xml.gz"; - @Rule + @RegisterExtension public MatsimTestUtils testUtils = new MatsimTestUtils(); @Test @@ -88,8 +89,8 @@ public Config prepareConfig(Config config) { preparedConfig.global().setNumberOfThreads(1); preparedConfig.qsim().setNumberOfThreads(1); preparedConfig.plans().setInputFile(null); - preparedConfig.controler().setLastIteration(0); - preparedConfig.controler().setRunId(RUN_ID); + preparedConfig.controller().setLastIteration(0); + preparedConfig.controller().setRunId(RUN_ID); // Disable PT preparedConfig.transit().setVehiclesFile(null); @@ -124,7 +125,7 @@ public void prepareScenario(Scenario scenario) { plan.addActivity(other); var person = factory.createPerson(personId); person.addPlan(plan); - person.getAttributes().putAttribute(IncomeDependentUtilityOfMoneyPersonScoringParameters.PERSONAL_INCOME_ATTRIBUTE_NAME, 1.0); + PersonUtils.setIncome(person, 1.0); scenario.getPopulation().addPerson(person); // filter the network diff --git a/src/test/java/org/matsim/run/TestKlimaTaler.java b/src/test/java/org/matsim/run/TestKlimaTaler.java index c5c5f82..9296eae 100644 --- a/src/test/java/org/matsim/run/TestKlimaTaler.java +++ b/src/test/java/org/matsim/run/TestKlimaTaler.java @@ -1,9 +1,7 @@ package org.matsim.run; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.matsim.analysis.personMoney.PersonMoneyEventsAnalysisModule; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; @@ -27,29 +25,30 @@ import java.io.IOException; import java.util.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.matsim.run.RunGladbeckScenario.addKlimaTaler; public class TestKlimaTaler { - @Rule + @RegisterExtension public MatsimTestUtils utils = new MatsimTestUtils(); @Test public final void runKlimaTalerBikeTest() throws IOException { String inputPath = String.valueOf(ExamplesUtils.getTestScenarioURL("equil-mixedTraffic")); Config config = ConfigUtils.loadConfig(inputPath + "config-with-mode-vehicles.xml"); - config.controler().setLastIteration(0); - config.controler().setOutputDirectory("output/KlimaTalerBikeTest/"); + config.controller().setLastIteration(0); + config.controller().setOutputDirectory("output/KlimaTalerBikeTest/"); config.global().setNumberOfThreads(1); config.qsim().setNumberOfThreads(1); - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); Scenario scenario = ScenarioUtils.loadScenario(config); Person person = scenario.getPopulation().getPersons().get(Id.createPersonId("10")); scenario.getPopulation().getPersons().clear(); scenario.getPopulation().addPerson(person); Controler controler = new Controler(scenario); - KlimaTaler teleportedModeTravelDistanceEvaluator = new KlimaTaler(config.plansCalcRoute().getBeelineDistanceFactors().get(TransportMode.walk), scenario.getNetwork(), + KlimaTaler teleportedModeTravelDistanceEvaluator = new KlimaTaler(config.routing().getBeelineDistanceFactors().get(TransportMode.walk), scenario.getNetwork(), 10.0); addKlimaTaler(controler, teleportedModeTravelDistanceEvaluator); @@ -63,8 +62,8 @@ public void install() { controler.run(); PersonMoneyEvent event = handler.klimaTalerBikeMoneyEvents.iterator().next(); - Assert.assertEquals("wrong person", "10", event.getPersonId().toString() ); - Assert.assertEquals("wrong amount", 31.679999999999996 , event.getAmount(), 0. ); + assertEquals("10", event.getPersonId().toString(), "wrong person"); + assertEquals(31.679999999999996, event.getAmount(), 0., "wrong amount"); } @@ -72,21 +71,21 @@ public void install() { public final void runKlimaTalerPtTest() throws IOException { String inputPath = String.valueOf(ExamplesUtils.getTestScenarioURL("pt-simple-lineswitch")); Config config = ConfigUtils.loadConfig(inputPath + "config.xml"); - config.controler().setLastIteration(0); - config.controler().setOutputDirectory("output/KlimaTalerPtTest/"); + config.controller().setLastIteration(0); + config.controller().setOutputDirectory("output/KlimaTalerPtTest/"); config.global().setNumberOfThreads(1); config.qsim().setNumberOfThreads(1); - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); Scenario scenario = ScenarioUtils.loadScenario(config); Controler controler = new Controler(scenario); Map> actCoords = new HashMap<>(); - for (ActivityFacility activity: controler.getScenario().getActivityFacilities().getFacilities().values()) { + for (ActivityFacility activity : controler.getScenario().getActivityFacilities().getFacilities().values()) { Queue queue = new LinkedList<>(); queue.add(activity.getCoord()); actCoords.put(activity.getId(), queue); } - KlimaTaler klimaTaler = new KlimaTaler(config.plansCalcRoute().getBeelineDistanceFactors().get(TransportMode.walk), scenario.getNetwork(), + KlimaTaler klimaTaler = new KlimaTaler(config.routing().getBeelineDistanceFactors().get(TransportMode.walk), scenario.getNetwork(), 10.0); addKlimaTaler(controler, klimaTaler); KlimaTalerTestListener handler = new KlimaTalerTestListener(); @@ -101,19 +100,19 @@ public void install() { //Assert that money amount is correct PersonMoneyEvent event = handler.klimaTalerPtMoneyEvents.iterator().next(); - Assert.assertEquals("wrong person", "1", event.getPersonId().toString() ); - Assert.assertEquals("wrong amount", 0.60496 , event.getAmount(), 0. ); + assertEquals( "1", event.getPersonId().toString(), "wrong person"); + assertEquals( 0.60496, event.getAmount(), 0., "wrong amount"); } @Test public final void runKlimaTalerWalkTest() throws IOException { String inputPath = String.valueOf(ExamplesUtils.getTestScenarioURL("chessboard")); Config config = ConfigUtils.loadConfig(inputPath + "config.xml"); - config.controler().setLastIteration(0); - config.controler().setOutputDirectory("output/KlimaTalerWalkTest/"); + config.controller().setLastIteration(0); + config.controller().setOutputDirectory("output/KlimaTalerWalkTest/"); config.global().setNumberOfThreads(1); config.qsim().setNumberOfThreads(1); - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); Scenario scenario = ScenarioUtils.loadScenario(config); Set modes = new HashSet<>(); modes.add(TransportMode.walk); @@ -124,12 +123,12 @@ public final void runKlimaTalerWalkTest() throws IOException { createWalkingAgent(population); Controler controler = new Controler(scenario); Map> actCoords = new HashMap<>(); - for (ActivityFacility activity: controler.getScenario().getActivityFacilities().getFacilities().values()) { + for (ActivityFacility activity : controler.getScenario().getActivityFacilities().getFacilities().values()) { Queue queue = new LinkedList<>(); queue.add(activity.getCoord()); actCoords.put(activity.getId(), queue); } - KlimaTaler teleportedModeTravelDistanceEvaluator = new KlimaTaler(config.plansCalcRoute().getBeelineDistanceFactors().get(TransportMode.walk), + KlimaTaler teleportedModeTravelDistanceEvaluator = new KlimaTaler(config.routing().getBeelineDistanceFactors().get(TransportMode.walk), scenario.getNetwork(), 10.0); addKlimaTaler(controler, teleportedModeTravelDistanceEvaluator); KlimaTalerTestListener handler = new KlimaTalerTestListener(); @@ -141,18 +140,15 @@ public void install() { }); - controler.run(); //Assert that money amount is correct PersonMoneyEvent event = handler.klimaTalerWalkMoneyEvents.iterator().next(); - Assert.assertEquals("wrong person", "walkingAgent", event.getPersonId().toString() ); - Assert.assertEquals("wrong amount", 0.45759999999999995 , event.getAmount(), 0. ); + assertEquals( "walkingAgent", event.getPersonId().toString(), "wrong person"); + assertEquals( 0.45759999999999995, event.getAmount(), 0., "wrong amount"); } - - final void createWalkingAgent(Population population) { population.getPersons().clear(); PopulationFactory factory = population.getFactory(); @@ -179,9 +175,12 @@ class KlimaTalerTestListener implements PersonMoneyEventHandler { @Override public void handleEvent(PersonMoneyEvent event) { - if (event.getPurpose().equals("klimaTalerForBike") && event.getAmount() > 0.) this.klimaTalerBikeMoneyEvents.add(event); - else if (event.getPurpose().equals("klimaTalerForPt") && event.getAmount() > 0.) this.klimaTalerPtMoneyEvents.add(event); - else if (event.getPurpose().equals("klimaTalerForWalk") && event.getAmount() > 0.) this.klimaTalerWalkMoneyEvents.add(event); + if (event.getPurpose().equals("klimaTalerForBike") && event.getAmount() > 0.) + this.klimaTalerBikeMoneyEvents.add(event); + else if (event.getPurpose().equals("klimaTalerForPt") && event.getAmount() > 0.) + this.klimaTalerPtMoneyEvents.add(event); + else if (event.getPurpose().equals("klimaTalerForWalk") && event.getAmount() > 0.) + this.klimaTalerWalkMoneyEvents.add(event); } @Override diff --git a/src/test/java/org/matsim/run/TestParking.java b/src/test/java/org/matsim/run/TestParking.java index feeb9e3..c7424a9 100644 --- a/src/test/java/org/matsim/run/TestParking.java +++ b/src/test/java/org/matsim/run/TestParking.java @@ -1,21 +1,24 @@ package org.matsim.run; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.prep.PreparedGeometry; import org.locationtech.jts.geom.prep.PreparedGeometryFactory; import org.matsim.analysis.personMoney.PersonMoneyEventsAnalysisModule; -import org.matsim.api.core.v01.*; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Identifiable; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.population.Person; import org.matsim.application.MATSimApplication; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlansCalcRouteConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.core.population.io.PopulationReader; @@ -27,17 +30,15 @@ import java.util.stream.Collectors; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; -import static org.matsim.core.config.groups.PlansCalcRouteConfigGroup.AccessEgressType.accessEgressModeToLinkPlusTimeConstant; +import static org.junit.jupiter.api.Assertions.assertTrue; -@Ignore +@Disabled public class TestParking { private static final Id personId = Id.createPersonId("test-person"); private static final String inputNetworkFile = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/metropole-ruhr/metropole-ruhr-v1.0/input/metropole-ruhr-v1.4.network_resolutionHigh-with-pt.xml.gz"; - @Rule + @RegisterExtension public MatsimTestUtils testUtils = new MatsimTestUtils(); @Test @@ -76,14 +77,14 @@ public Config prepareConfig(Config config) { preparedConfig.global().setNumberOfThreads(1); preparedConfig.qsim().setNumberOfThreads(1); preparedConfig.plans().setInputFile(null); - preparedConfig.controler().setLastIteration(0); - preparedConfig.controler().setRunId(RUN_ID); + preparedConfig.controller().setLastIteration(0); + preparedConfig.controller().setRunId(RUN_ID); // Disable PT preparedConfig.transit().setUseTransit(false); if (useParking== false) { - config.plansCalcRoute().setAccessEgressType(PlansCalcRouteConfigGroup.AccessEgressType.accessEgressModeToLink); + config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink); } return preparedConfig; diff --git a/src/test/java/org/matsim/run/TestPersonAttributes.java b/src/test/java/org/matsim/run/TestPersonAttributes.java index e200531..55d7e99 100644 --- a/src/test/java/org/matsim/run/TestPersonAttributes.java +++ b/src/test/java/org/matsim/run/TestPersonAttributes.java @@ -1,7 +1,7 @@ package org.matsim.run; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.locationtech.jts.util.Assert; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.population.Person; @@ -15,18 +15,18 @@ public class TestPersonAttributes { - @Rule + @RegisterExtension public MatsimTestUtils utils = new MatsimTestUtils(); @Test public final void runTestPersonAttributes() { String inputPath = String.valueOf(ExamplesUtils.getTestScenarioURL("equil-mixedTraffic")); Config config = ConfigUtils.loadConfig(inputPath + "config-with-mode-vehicles.xml"); - config.controler().setLastIteration(0); - config.controler().setOutputDirectory("output/TestPersonAttributes/"); + config.controller().setLastIteration(0); + config.controller().setOutputDirectory("output/TestPersonAttributes/"); config.global().setNumberOfThreads(1); config.qsim().setNumberOfThreads(1); - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); Scenario scenario = ScenarioUtils.loadScenario(config); AssignPersonAttributes.assigningDifferentCitizenship(scenario, null); diff --git a/src/test/java/org/matsim/run/TestPtFlat.java b/src/test/java/org/matsim/run/TestPtFlat.java index cf123da..059a4cc 100644 --- a/src/test/java/org/matsim/run/TestPtFlat.java +++ b/src/test/java/org/matsim/run/TestPtFlat.java @@ -1,8 +1,8 @@ package org.matsim.run; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.TransportMode; @@ -11,21 +11,21 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; +import org.matsim.core.population.PersonUtils; import org.matsim.core.population.io.PopulationReader; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.testcases.MatsimTestUtils; -import playground.vsp.scoring.IncomeDependentUtilityOfMoneyPersonScoringParameters; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; //test runs too long... -@Ignore +@Disabled public class TestPtFlat { private static final Id personId = Id.createPersonId("test-person"); private static final String inputNetworkFile = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/gladbeck/glamobi/input/gladbeck-v1.0-10pct.network.xml.gz"; - @Rule + @RegisterExtension public MatsimTestUtils testUtils = new MatsimTestUtils(); @Test @@ -71,8 +71,8 @@ public Config prepareConfig(Config config) { //preparedConfig.global().setNumberOfThreads(1); //preparedConfig.qsim().setNumberOfThreads(1); preparedConfig.plans().setInputFile(null); - preparedConfig.controler().setLastIteration(0); - preparedConfig.controler().setRunId(RUN_ID); + preparedConfig.controller().setLastIteration(0); + preparedConfig.controller().setRunId(RUN_ID); return preparedConfig; } @@ -97,7 +97,8 @@ protected void prepareScenario(Scenario scenario) { var person = factory.createPerson(personId); person.addPlan(plan); person.getAttributes().putAttribute("subpopulation", "person"); - person.getAttributes().putAttribute(IncomeDependentUtilityOfMoneyPersonScoringParameters.PERSONAL_INCOME_ATTRIBUTE_NAME, 1.0); + + PersonUtils.setIncome(person, 1); // add single person with two activities living inside gladbeck var planInsider = factory.createPlan(); @@ -115,7 +116,8 @@ protected void prepareScenario(Scenario scenario) { var personInsider = factory.createPerson(Id.createPersonId(personId+"inside")); personInsider.addPlan(planInsider); personInsider.getAttributes().putAttribute("subpopulation", "person"); - personInsider.getAttributes().putAttribute(IncomeDependentUtilityOfMoneyPersonScoringParameters.PERSONAL_INCOME_ATTRIBUTE_NAME, 1.0); + PersonUtils.setIncome(personInsider, 1); + scenario.getPopulation().addPerson(personInsider); scenario.getPopulation().addPerson(person); super.prepareScenario(scenario); diff --git a/src/test/java/org/matsim/run/TestSchoolClosure.java b/src/test/java/org/matsim/run/TestSchoolClosure.java index 5acd472..68f68ee 100644 --- a/src/test/java/org/matsim/run/TestSchoolClosure.java +++ b/src/test/java/org/matsim/run/TestSchoolClosure.java @@ -1,49 +1,39 @@ package org.matsim.run; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.matsim.api.core.v01.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Population; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.core.network.NetworkChangeEvent; -import org.matsim.core.network.NetworkUtils; -import org.matsim.core.network.io.NetworkChangeEventsWriter; import org.matsim.core.population.PopulationUtils; -import org.matsim.core.population.io.PopulationReader; import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.core.utils.misc.Time; import org.matsim.examples.ExamplesUtils; import org.matsim.run.policies.SchoolRoadsClosure; import org.matsim.testcases.MatsimTestUtils; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.List; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestSchoolClosure { - @Rule + @RegisterExtension public MatsimTestUtils testUtils = new MatsimTestUtils(); @Test public void testSchoolClosure() { String inputPath = String.valueOf(ExamplesUtils.getTestScenarioURL("chessboard")); Config config = ConfigUtils.loadConfig(inputPath + "config.xml"); - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles); - config.controler().setOutputDirectory(testUtils.getOutputDirectory()); - config.controler().setRunId("testSchool"); - config.controler().setLastIteration(0); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles); + config.controller().setOutputDirectory(testUtils.getOutputDirectory()); + config.controller().setRunId("testSchool"); + config.controller().setLastIteration(0); config.network().setTimeVariantNetwork(true); Scenario scenario = ScenarioUtils.loadScenario(config); List> linksToClose = new ArrayList<>(); @@ -54,7 +44,7 @@ public void testSchoolClosure() { controler.run(); // load output - Population population = PopulationUtils.readPopulation(testUtils.getOutputDirectory() + config.controler().getRunId() + ".output_plans.xml.gz"); + Population population = PopulationUtils.readPopulation(testUtils.getOutputDirectory() + config.controller().getRunId() + ".output_plans.xml.gz"); var personWithFreeRoad = population.getPersons().get(Id.createPersonId("4")); var personWithoutFreeRoad = population.getPersons().get(Id.createPersonId("1"));