diff --git a/Makefile b/Makefile index 264be35..24629ae 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,6 @@ input/sumo.net.xml: input/network.osm input/$V/$N-$V-network.xml.gz: input/sumo.net.xml $(sc) prepare network-from-sumo $< --output $@ --free-speed-factor 0.75 - $(sc) prepare fix-network $@ --output $@ $(sc) prepare clean-network $@ --output $@ --modes car --modes bike @@ -129,7 +128,7 @@ input/$V/$N-$V-100pct.plans.xml.gz: input/plans-longHaulFreight.xml.gz input/$V/ # TODO: set home coordinates attributes - $(sc) prepare extract-home-coordinates $@ --csv input/$V/$N-$V-homes.csv + $(sc) prepare extract-home-coordinates $@ --output $@ --csv input/$V/$N-$V-homes.csv $(sc) prepare downsample-population $@\ --sample-size 1\ diff --git a/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java b/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java new file mode 100644 index 0000000..02b3f9c --- /dev/null +++ b/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java @@ -0,0 +1,23 @@ +package org.matsim.dashboards; + +import org.matsim.core.config.Config; +import org.matsim.simwrapper.Dashboard; +import org.matsim.simwrapper.DashboardProvider; +import org.matsim.simwrapper.SimWrapper; +import org.matsim.simwrapper.dashboard.TripDashboard; + +import java.util.List; + +/** + * Dashboards for the Lausitz scenario. + */ +public class LausitzDashboardProvider implements DashboardProvider { + @Override + public List getDashboards(Config config, SimWrapper simWrapper) { + return List.of(new TripDashboard( + "lausitz_mode_share.csv", + "lausitz_mode_share_per_dist.csv", + "lausitz_mode_users.csv") + ); + } +} diff --git a/src/main/python/calibrate.py b/src/main/python/calibrate.py index ed888ce..e5f7353 100644 --- a/src/main/python/calibrate.py +++ b/src/main/python/calibrate.py @@ -3,15 +3,15 @@ import os -import pandas as pd import geopandas as gpd +import pandas as pd try: from matsim import calibration except: import calibration -#%% +# %% if os.path.exists("mid.csv"): srv = pd.read_csv("mid.csv") @@ -26,7 +26,7 @@ adj.to_csv("mid_adj.csv", index=False) -#%% +# %% modes = ["walk", "car", "ride", "pt", "bike"] fixed_mode = "walk" @@ -37,29 +37,27 @@ "ride": -2.22873502992 } -# FIXME: Adjust +# Based on MiD 2017, filtered on Lausitz region target = { - "walk": 0.1, - "bike": 0.1, - "pt": 0.1, - "car": 0.1, - "ride": 0.1 + "walk": 0.199819, + "bike": 0.116362, + "pt": 0.049501, + "car": 0.496881, + "ride": 0.137437 } -region = gpd.read_file("../scenarios/dilutionArea.shp").set_crs("EPSG:25832") -homes = pd.read_csv("template-v1.0-homes.csv", dtype={"person": "str"}) +region = gpd.read_file("../input/lausitz.shp").to_crs("EPSG:25832") def filter_persons(persons): - persons = pd.merge(persons, homes, how="inner", left_on="person", right_on="person") persons = gpd.GeoDataFrame(persons, geometry=gpd.points_from_xy(persons.home_x, persons.home_y)) - - df = gpd.sjoin(persons.set_crs("EPSG:25832"), city, how="inner", op="intersects") + df = gpd.sjoin(persons.set_crs("EPSG:25832"), region, how="inner", op="intersects") print("Filtered %s persons" % len(df)) return df + def filter_modes(df): df = df[df.main_mode != "freight"] df.loc[df.main_mode.str.startswith("pt_"), "main_mode"] = "pt" @@ -70,15 +68,15 @@ def filter_modes(df): # FIXME: Adjust paths and config study, obj = calibration.create_mode_share_study("calib", "matsim-template-1.0.jar", - "../scenarios/metropole-ruhr-v1.0/input/metropole-ruhr-v1.4-3pct.config.xml", - modes, target, - initial_asc=initial, - args="--10pct", - jvm_args="-Xmx75G -Xmx75G -XX:+AlwaysPreTouch", - lr=calibration.linear_lr_scheduler(start=0.5), - person_filter=filter_persons, map_trips=filter_modes, chain_runs=True) - - -#%% + "../scenarios/metropole-ruhr-v1.0/input/metropole-ruhr-v1.4-3pct.config.xml", + modes, target, + initial_asc=initial, + args="--10pct", + jvm_args="-Xmx75G -Xmx75G -XX:+AlwaysPreTouch", + transform_persons=filter_persons, transform_trips=filter_modes, + lr=calibration.linear_lr_scheduler(start=0.3, interval=8), + chain_runs=calibration.default_chain_scheduler) + +# %% study.optimize(obj, 10) diff --git a/src/main/python/create_ref.py b/src/main/python/create_ref.py new file mode 100644 index 0000000..5306896 --- /dev/null +++ b/src/main/python/create_ref.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import geopandas as gpd + +from matsim.scenariogen.data import run_create_ref_data + + +def person_filter(df): + df = gpd.GeoDataFrame(df, geometry=gpd.GeoSeries.from_wkt(df.geom, crs="EPSG:4326").to_crs("EPSG:25832")) + df = gpd.sjoin(df, region, how="inner", predicate="intersects") + + return df[df.present_on_day & (df.reporting_day <= 5)] + + +def trip_filter(df): + # Other modes are ignored in the total share + return df[df.main_mode != "other"] + + +if __name__ == "__main__": + region = gpd.read_file("../../../../shared-svn/projects/DiTriMo/data/shp/lausitz.shp").to_crs("EPSG:25832") + + persons, trips, share = run_create_ref_data.create("/Volumes/Untitled/B3_Lokal-Datensatzpaket/CSV", + person_filter, trip_filter, + run_create_ref_data.InvalidHandling.REMOVE_TRIPS) + + print("Filtered %s persons" % len(persons)) + print("Filtered %s trips" % len(trips)) + + print(share) diff --git a/src/main/resources/META-INF/services/org.matsim.simwrapper.DashboardProvider b/src/main/resources/META-INF/services/org.matsim.simwrapper.DashboardProvider new file mode 100644 index 0000000..ca65a97 --- /dev/null +++ b/src/main/resources/META-INF/services/org.matsim.simwrapper.DashboardProvider @@ -0,0 +1 @@ +org.matsim.dashboards.LausitzDashboardProvider \ No newline at end of file diff --git a/src/main/resources/lausitz_mode_share.csv b/src/main/resources/lausitz_mode_share.csv new file mode 100644 index 0000000..c024d07 --- /dev/null +++ b/src/main/resources/lausitz_mode_share.csv @@ -0,0 +1,31 @@ +dist_group,main_mode,mean_dist,share +0 - 1000,bike,741.7474152768164,0.05431618817899002 +0 - 1000,car,845.2047065363095,0.031216669310203 +0 - 1000,pt,503.9569413263069,0.0012298417638100443 +0 - 1000,ride,798.8045427222489,0.01929390934129713 +0 - 1000,walk,474.8462693693281,0.14568353330391315 +1000 - 2000,bike,1644.2686306579485,0.01912094472020174 +1000 - 2000,car,1664.6974637289466,0.04206126416523887 +1000 - 2000,pt,1769.9848721595795,0.006125610783078046 +1000 - 2000,ride,1695.6202104840554,0.015018450003780185 +1000 - 2000,walk,1781.56327180136,0.028682645671379056 +2000 - 5000,bike,3415.967452046967,0.025207557865234546 +2000 - 5000,car,3821.2329823444597,0.13695546693420932 +2000 - 5000,pt,3715.77927121702,0.011575801348651667 +2000 - 5000,ride,3336.405564477932,0.03633788006858987 +2000 - 5000,walk,3058.339137223546,0.01911150073233698 +5000 - 10000,bike,6635.65436876184,0.011838556537851376 +5000 - 10000,car,7311.064045237122,0.11269186948089517 +5000 - 10000,pt,6979.744659157714,0.013102503056468777 +5000 - 10000,ride,6898.4939502130765,0.027491496179970917 +5000 - 10000,walk,6657.462194056846,0.006142216096671607 +10000 - 20000,bike,14378.984336238063,0.00281739136837012 +10000 - 20000,car,14576.783406018267,0.0755031637087224 +10000 - 20000,pt,13429.023672194808,0.01383155988361684 +10000 - 20000,ride,14240.788705878334,0.020277335207750966 +10000 - 20000,walk,12940.0,0.0001990871342660644 +20000+,bike,37248.118594095315,0.003061190266223855 +20000+,car,47805.15415602558,0.09845227912097768 +20000+,pt,41088.975762937975,0.0036358034320222465 +20000+,ride,68027.0017296671,0.01901828433527827 +20000+,walk,,0.0 diff --git a/src/main/resources/lausitz_mode_share_per_dist.csv b/src/main/resources/lausitz_mode_share_per_dist.csv new file mode 100644 index 0000000..bfc48ff --- /dev/null +++ b/src/main/resources/lausitz_mode_share_per_dist.csv @@ -0,0 +1,31 @@ +dist_group,main_mode,mean_dist,share +0 - 1000,bike,741.7474152768164,0.2157629203250064 +0 - 1000,car,845.2047065363095,0.12400354220355093 +0 - 1000,pt,503.9569413263069,0.004885362161698109 +0 - 1000,ride,798.8045427222489,0.07664216439942374 +0 - 1000,walk,474.8462693693281,0.5787060109103207 +1000 - 2000,bike,1644.2686306579485,0.17224692864536398 +1000 - 2000,car,1664.6974637289466,0.3788998751588497 +1000 - 2000,pt,1769.9848721595795,0.05518125066003455 +1000 - 2000,ride,1695.6202104840554,0.1352904850685536 +1000 - 2000,walk,1781.56327180136,0.2583814604671981 +2000 - 5000,bike,3415.967452046967,0.10998627809345088 +2000 - 5000,car,3821.2329823444597,0.5975676879599303 +2000 - 5000,pt,3715.77927121702,0.05050784027132093 +2000 - 5000,ride,3336.405564477932,0.15855039206564583 +2000 - 5000,walk,3058.339137223546,0.08338780160965216 +5000 - 10000,bike,6635.65436876184,0.06912354002160712 +5000 - 10000,car,7311.064045237122,0.6579907715325366 +5000 - 10000,pt,6979.744659157714,0.07650353246287123 +5000 - 10000,ride,6898.4939502130765,0.16051868573455097 +5000 - 10000,walk,6657.462194056846,0.03586347024843422 +10000 - 20000,bike,14378.984336238063,0.025014897963181838 +10000 - 20000,car,14576.783406018267,0.6703732954089843 +10000 - 20000,pt,13429.023672194808,0.12280688549155136 +10000 - 20000,ride,14240.788705878334,0.1800372773487143 +10000 - 20000,walk,12940.0,0.0017676437875682608 +20000+,bike,37248.118594095315,0.024653704529394964 +20000+,car,47805.15415602558,0.7928985749351034 +20000+,pt,41088.975762937975,0.029281428380669564 +20000+,ride,68027.0017296671,0.15316629215483207 +20000+,walk,,0.0 diff --git a/src/main/resources/lausitz_mode_users.csv b/src/main/resources/lausitz_mode_users.csv new file mode 100644 index 0000000..3ff0e35 --- /dev/null +++ b/src/main/resources/lausitz_mode_users.csv @@ -0,0 +1,6 @@ +main_mode,user +pt,0.07115467203031302 +ride,0.213768422141053 +car,0.49898396490379887 +bike,0.159641024221889 +walk,0.2741758378287667