From 0b914da713ba932b87d1c52265428754795b6042 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 1 Aug 2024 16:14:29 +0200 Subject: [PATCH 1/2] add first inputs for adding small-scale commercial traffic --- Makefile | 38 ++++++++++++- input/commercialTrafficAreaData.csv | 16 ++++++ .../java/org/matsim/run/LausitzScenario.java | 57 +++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 input/commercialTrafficAreaData.csv diff --git a/Makefile b/Makefile index 92e47ef..a9f3e29 100644 --- a/Makefile +++ b/Makefile @@ -94,6 +94,42 @@ input/plans-longHaulFreight.xml.gz: input/$V/$N-$V-network.xml.gz --shp input/shp/lausitz.shp --shp-crs $(CRS)\ --cut-on-boundary\ --output $@ +# create facilities for commercial traffic +input/commercialFacilities.xml.gz: + $(sc) prepare create-data-distribution-of-structure-data\ + --outputFacilityFile $@\ + --outputDataDistributionFile input/dataDistributionPerZone.csv\ + --landuseConfiguration useOSMBuildingsAndLanduse\ + --regionsShapeFileName input/shp/commercialTraffic/lausitz_regions_25832.shp\ + --regionsShapeRegionColumn "GEN"\ + --zoneShapeFileName input/shp/commercialTraffic/lausitz_zones_25832.shp\ + --zoneShapeFileNameColumn "GEN"\ + --buildingsShapeFileName $(berlin)/input/shp/commercialTraffic/lausitz_buildings_25832.shp\ + --shapeFileBuildingTypeColumn "building"\ + --landuseShapeFileName $(berlin)/input/shp/commercialTraffic/lausitz_landuse_25832.shp\ + --shapeFileLanduseTypeColumn "landuse"\ + --shapeCRS "EPSG:25832"\ + --pathToInvestigationAreaData input/commercialTrafficAreaData.csv +# generate small scale commercial traffic +input/lausitz-small-scale-commercialTraffic-$V-100pct.plans.xml.gz: input/$V/$N-$V-network.xml.gz input/commercialFacilities.xml.gz + $(sc) prepare generate-small-scale-commercial-traffic\ + input/$V/berlin-$V.config.xml\ + --pathToDataDistributionToZones input/dataDistributionPerZone.csv\ + --pathToCommercialFacilities $(notdir $(word 2,$^))\ + --sample 1.0\ + --jspritIterations 10\ + --creationOption createNewCarrierFile\ + --network $(notdir $<)\ + --smallScaleCommercialTrafficType completeSmallScaleCommercialTraffic\ + --zoneShapeFileName input/shp/commercialTraffic/lausitz_zones_25832.shp\ + --zoneShapeFileNameColumn "GEN"\ + --shapeCRS "EPSG:25832"\ + --numberOfPlanVariantsPerAgent 5\ + --nameOutputPopulation $(notdir $@)\ + --pathOutput output/commercialPersonTraffic + + mv output/commercialPersonTraffic/$(notdir $@) $@ + # trajectory-to-plans formerly was a collection of methods to prepare a given population # now, most of the functions of this class do have their own class (downsample, splitduration types...) @@ -113,7 +149,7 @@ input/$V/prepare-100pct.plans.xml.gz: --landuse $(germany)/landuse/landuse.shp\ --output $@ -input/$V/$N-$V-100pct.plans-initial.xml.gz: input/plans-longHaulFreight.xml.gz input/$V/prepare-100pct.plans.xml.gz +input/$V/$N-$V-100pct.plans-initial.xml.gz: input/plans-longHaulFreight.xml.gz input/$V/prepare-100pct.plans.xml.gz input/lausitz-small-scale-commercialTraffic-$V-100pct.plans.xml.gz # generate some short distance trips, which in senozon data generally are missing # trip range 700m because: diff --git a/input/commercialTrafficAreaData.csv b/input/commercialTrafficAreaData.csv new file mode 100644 index 0000000..3f504a8 --- /dev/null +++ b/input/commercialTrafficAreaData.csv @@ -0,0 +1,16 @@ +Region Inhabitants Employee Employee Primary Sector Employee Construction Employee Secondary Sector Rest Employee Retail Employee Traffic/Parcels Employee Tertiary Sector Rest +Bautzen 299758 145078 2701 12463 36673 15557 7815 69868 +Cottbus 99678 62019 187 3075 3634 6942 3488 44693 +Dahme-Spreewald 170791 78060 2194 6992 9308 13425 6744 39396 +Dresden 556780 340806 586 15705 40528 39574 19880 224533 +Elbe-Elster 101827 44717 1985 4203 9319 4345 2183 22682 +Frankfurt-Oder 57751 38509 310 2283 1603 3507 1762 29045 +Görlitz 252725 115613 2238 9505 26917 10710 5380 60862 +Meißen 241717 115169 2928 10486 27393 13440 6752 54171 +Nordsachsen 197741 93857 2965 9733 17189 13723 6894 43353 +Oberspreewald-Lausitz 109371 49738 1001 5564 9568 5435 2731 25439 +Oder-Spree 178803 73039 1539 8110 12055 8685 4363 38288 +Sächsische Schweiz-Osterzgebirge 245586 103594 2754 11101 24413 10499 5274 49553 +Spree-Neiße 113720 45390 1904 5592 11473 4768 2395 19257 +Teltow-Fläming 169997 80279 1922 6596 17450 12224 6141 35946 +Wittenberg 124953 53522 1884 4927 13011 5727 2877 25096 \ No newline at end of file diff --git a/src/main/java/org/matsim/run/LausitzScenario.java b/src/main/java/org/matsim/run/LausitzScenario.java index 074c72c..15e2771 100644 --- a/src/main/java/org/matsim/run/LausitzScenario.java +++ b/src/main/java/org/matsim/run/LausitzScenario.java @@ -1,6 +1,8 @@ package org.matsim.run; import com.google.common.collect.Sets; +import com.google.inject.Key; +import com.google.inject.name.Names; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; @@ -18,10 +20,14 @@ import org.matsim.contrib.vsp.scenario.SnzActivities; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.ReplanningConfigGroup; import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; +import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule; +import org.matsim.core.router.costcalculators.TravelDisutilityFactory; +import org.matsim.core.router.util.TravelTime; import org.matsim.core.scoring.functions.ScoringParametersForPerson; import org.matsim.run.analysis.CommuterAnalysis; import org.matsim.run.prepare.PreparePopulation; @@ -31,6 +37,8 @@ import playground.vsp.scoring.IncomeDependentUtilityOfMoneyPersonScoringParameters; import javax.annotation.Nullable; +import java.util.HashSet; +import java.util.List; import java.util.Set; @CommandLine.Command(header = ":: Open Lausitz Scenario ::", version = LausitzScenario.VERSION, mixinStandardHelpOptions = true) @@ -109,6 +117,7 @@ protected Config prepareConfig(Config config) { config.qsim().setUsePersonIdForMissingVehicleId(false); config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink); + prepareCommercialTrafficConfig(config); // TODO: Config options // TODO: recreate counts format with car and trucks @@ -126,6 +135,7 @@ protected void prepareScenario(Scenario scenario) { if (modes.contains("car")) { Set newModes = Sets.newHashSet(modes); newModes.add("freight"); + newModes.add("truck"); link.setAllowedModes(newModes); } @@ -146,9 +156,56 @@ public void install() { addTravelTimeBinding(TransportMode.ride).to(networkTravelTime()); addTravelDisutilityFactoryBinding(TransportMode.ride).to(carTravelDisutilityFactoryKey()); + + addTravelTimeBinding("freight").to(Key.get(TravelTime.class, Names.named(TransportMode.truck))); + addTravelDisutilityFactoryBinding("freight").to(Key.get(TravelDisutilityFactory.class, Names.named(TransportMode.truck))); // we do not need to add SwissRailRaptor explicitely! this is done in core } }); } + + /** + * Prepare the config for commercial traffic. + */ + public static void prepareCommercialTrafficConfig(Config config) { + + Set modes = Set.of("freight", "truck"); + + modes.forEach(mode -> { + ScoringConfigGroup.ModeParams thisModeParams = new ScoringConfigGroup.ModeParams(mode); + config.scoring().addModeParams(thisModeParams); + }); + + Set qsimModes = new HashSet<>(config.qsim().getMainModes()); + config.qsim().setMainModes(Sets.union(qsimModes, modes)); + + Set networkModes = new HashSet<>(config.routing().getNetworkModes()); + config.routing().setNetworkModes(Sets.union(networkModes, modes)); + + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("commercial_start").setTypicalDuration(30 * 60)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("commercial_end").setTypicalDuration(30 * 60)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("service").setTypicalDuration(30 * 60)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("start").setTypicalDuration(30 * 60)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("end").setTypicalDuration(30 * 60)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("freight_start").setTypicalDuration(30 * 60)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("freight_end").setTypicalDuration(30 * 60)); + + //TODO: add freight and remove from config or change freight subpopulation and mode for long distance freight + for (String subpopulation : List.of("commercialPersonTraffic", "commercialPersonTraffic_service", "goodsTraffic")) { + config.replanning().addStrategySettings( + new ReplanningConfigGroup.StrategySettings() + .setStrategyName(DefaultPlanStrategiesModule.DefaultSelector.ChangeExpBeta) + .setWeight(0.85) + .setSubpopulation(subpopulation) + ); + + config.replanning().addStrategySettings( + new ReplanningConfigGroup.StrategySettings() + .setStrategyName(DefaultPlanStrategiesModule.DefaultStrategy.ReRoute) + .setWeight(0.1) + .setSubpopulation(subpopulation) + ); + } + } } From 059303f4ee5fd575b2061a54756c3ab659c5b787 Mon Sep 17 00:00:00 2001 From: sime94 Date: Mon, 19 Aug 2024 15:27:21 +0200 Subject: [PATCH 2/2] finalize small scale commercial traffic impl and creation --- Makefile | 34 +++++++++---------- input/commercialTrafficAreaData.csv | 16 --------- .../java/org/matsim/run/LausitzScenario.java | 27 ++++++++------- 3 files changed, 31 insertions(+), 46 deletions(-) delete mode 100644 input/commercialTrafficAreaData.csv diff --git a/Makefile b/Makefile index a9f3e29..186b54b 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ JAR := matsim-$(N)-*.jar osmosis := osmosis/bin/osmosis germany := ../shared-svn/projects/matsim-germany shared := ../shared-svn/projects/DiTriMo -lausitz := ../public-svn/matsim/scenarios/countries/de/lausitz/lausitz-$V +lausitz := ../public-svn/matsim/scenarios/countries/de/lausitz/input/$V MEMORY ?= 20G SUMO_HOME ?= $(abspath ../../sumo-1.18.0/) @@ -98,37 +98,37 @@ input/plans-longHaulFreight.xml.gz: input/$V/$N-$V-network.xml.gz input/commercialFacilities.xml.gz: $(sc) prepare create-data-distribution-of-structure-data\ --outputFacilityFile $@\ - --outputDataDistributionFile input/dataDistributionPerZone.csv\ + --outputDataDistributionFile $(shared)/data/commercial_traffic/input/commercialTraffic/dataDistributionPerZone.csv\ --landuseConfiguration useOSMBuildingsAndLanduse\ - --regionsShapeFileName input/shp/commercialTraffic/lausitz_regions_25832.shp\ + --regionsShapeFileName $(shared)/data/commercial_traffic/input/commercialTraffic/lausitz_regions_25832.shp\ --regionsShapeRegionColumn "GEN"\ - --zoneShapeFileName input/shp/commercialTraffic/lausitz_zones_25832.shp\ + --zoneShapeFileName $(shared)/data/commercial_traffic/input/commercialTraffic/lausitz_zones_25832.shp\ --zoneShapeFileNameColumn "GEN"\ - --buildingsShapeFileName $(berlin)/input/shp/commercialTraffic/lausitz_buildings_25832.shp\ + --buildingsShapeFileName $(shared)/data/commercial_traffic/input/commercialTraffic/lausitz_buildings_25832.shp\ --shapeFileBuildingTypeColumn "building"\ - --landuseShapeFileName $(berlin)/input/shp/commercialTraffic/lausitz_landuse_25832.shp\ + --landuseShapeFileName $(shared)/data/commercial_traffic/input/commercialTraffic/lausitz_landuse_25832.shp\ --shapeFileLanduseTypeColumn "landuse"\ --shapeCRS "EPSG:25832"\ - --pathToInvestigationAreaData input/commercialTrafficAreaData.csv + --pathToInvestigationAreaData $(shared)/data/commercial_traffic/input/commercialTraffic/commercialTrafficAreaData.csv # generate small scale commercial traffic input/lausitz-small-scale-commercialTraffic-$V-100pct.plans.xml.gz: input/$V/$N-$V-network.xml.gz input/commercialFacilities.xml.gz $(sc) prepare generate-small-scale-commercial-traffic\ - input/$V/berlin-$V.config.xml\ - --pathToDataDistributionToZones input/dataDistributionPerZone.csv\ - --pathToCommercialFacilities $(notdir $(word 2,$^))\ + input/$V/lausitz-$V-100pct.config.xml\ + --pathToDataDistributionToZones $(shared)/data/commercial_traffic/input/commercialTraffic/dataDistributionPerZone.csv\ + --pathToCommercialFacilities $(word 2,$^)\ --sample 1.0\ --jspritIterations 10\ --creationOption createNewCarrierFile\ - --network $(notdir $<)\ + --network $<\ --smallScaleCommercialTrafficType completeSmallScaleCommercialTraffic\ - --zoneShapeFileName input/shp/commercialTraffic/lausitz_zones_25832.shp\ + --zoneShapeFileName $(shared)/data/commercial_traffic/input/commercialTraffic/lausitz_zones_25832.shp\ --zoneShapeFileNameColumn "GEN"\ --shapeCRS "EPSG:25832"\ --numberOfPlanVariantsPerAgent 5\ - --nameOutputPopulation $(notdir $@)\ + --nameOutputPopulation $@\ --pathOutput output/commercialPersonTraffic - mv output/commercialPersonTraffic/$(notdir $@) $@ + mv output/commercialPersonTraffic/$@ $@ # trajectory-to-plans formerly was a collection of methods to prepare a given population @@ -162,7 +162,7 @@ input/$V/$N-$V-100pct.plans-initial.xml.gz: input/plans-longHaulFreight.xml.gz i --range 700\ --num-trips 324430 -# adapt coords of activitzies in the wider network such that they are closer to a link +# adapt coords of activities in the wider network such that they are closer to a link # such that agents do not have to walk as far as before $(sc) prepare adjust-activity-to-link-distances input/$V/prepare-100pct.plans-with-trips.xml.gz\ --shp input/shp/lausitz.shp --shp-crs $(CRS)\ @@ -180,11 +180,11 @@ input/$V/$N-$V-100pct.plans-initial.xml.gz: input/plans-longHaulFreight.xml.gz i # split activity types to type_duration for the scoring to take into account the typical duration $(sc) prepare split-activity-types-duration\ --input $@\ - --exclude commercial_start,commercial_end,freight_start,freight_end\ + --exclude commercial_start,commercial_end,freight_start,freight_end,service\ --output $@ # merge person and freight pops - $(sc) prepare merge-populations $@ $< --output $@ + $(sc) prepare merge-populations $@ $< $(word 3,$^) --output $@ $(sc) prepare downsample-population $@\ --sample-size 1\ diff --git a/input/commercialTrafficAreaData.csv b/input/commercialTrafficAreaData.csv deleted file mode 100644 index 3f504a8..0000000 --- a/input/commercialTrafficAreaData.csv +++ /dev/null @@ -1,16 +0,0 @@ -Region Inhabitants Employee Employee Primary Sector Employee Construction Employee Secondary Sector Rest Employee Retail Employee Traffic/Parcels Employee Tertiary Sector Rest -Bautzen 299758 145078 2701 12463 36673 15557 7815 69868 -Cottbus 99678 62019 187 3075 3634 6942 3488 44693 -Dahme-Spreewald 170791 78060 2194 6992 9308 13425 6744 39396 -Dresden 556780 340806 586 15705 40528 39574 19880 224533 -Elbe-Elster 101827 44717 1985 4203 9319 4345 2183 22682 -Frankfurt-Oder 57751 38509 310 2283 1603 3507 1762 29045 -Görlitz 252725 115613 2238 9505 26917 10710 5380 60862 -Meißen 241717 115169 2928 10486 27393 13440 6752 54171 -Nordsachsen 197741 93857 2965 9733 17189 13723 6894 43353 -Oberspreewald-Lausitz 109371 49738 1001 5564 9568 5435 2731 25439 -Oder-Spree 178803 73039 1539 8110 12055 8685 4363 38288 -Sächsische Schweiz-Osterzgebirge 245586 103594 2754 11101 24413 10499 5274 49553 -Spree-Neiße 113720 45390 1904 5592 11473 4768 2395 19257 -Teltow-Fläming 169997 80279 1922 6596 17450 12224 6141 35946 -Wittenberg 124953 53522 1884 4927 13011 5727 2877 25096 \ No newline at end of file diff --git a/src/main/java/org/matsim/run/LausitzScenario.java b/src/main/java/org/matsim/run/LausitzScenario.java index 15e2771..f461f69 100644 --- a/src/main/java/org/matsim/run/LausitzScenario.java +++ b/src/main/java/org/matsim/run/LausitzScenario.java @@ -54,6 +54,7 @@ public class LausitzScenario extends MATSimApplication { public static final String VERSION = "1.1"; + private static final String FREIGHT = "freight"; @CommandLine.Mixin private final SampleOptions sample = new SampleOptions( 100, 25, 10, 1); @@ -132,10 +133,10 @@ protected void prepareScenario(Scenario scenario) { Set modes = link.getAllowedModes(); // allow freight traffic together with cars - if (modes.contains("car")) { + if (modes.contains(TransportMode.car)) { Set newModes = Sets.newHashSet(modes); - newModes.add("freight"); - newModes.add("truck"); + newModes.add(FREIGHT); + newModes.add(TransportMode.truck); link.setAllowedModes(newModes); } @@ -157,8 +158,8 @@ public void install() { addTravelTimeBinding(TransportMode.ride).to(networkTravelTime()); addTravelDisutilityFactoryBinding(TransportMode.ride).to(carTravelDisutilityFactoryKey()); - addTravelTimeBinding("freight").to(Key.get(TravelTime.class, Names.named(TransportMode.truck))); - addTravelDisutilityFactoryBinding("freight").to(Key.get(TravelDisutilityFactory.class, Names.named(TransportMode.truck))); + addTravelTimeBinding(FREIGHT).to(Key.get(TravelTime.class, Names.named(TransportMode.truck))); + addTravelDisutilityFactoryBinding(FREIGHT).to(Key.get(TravelDisutilityFactory.class, Names.named(TransportMode.truck))); // we do not need to add SwissRailRaptor explicitely! this is done in core } @@ -170,7 +171,7 @@ public void install() { */ public static void prepareCommercialTrafficConfig(Config config) { - Set modes = Set.of("freight", "truck"); + Set modes = Set.of(FREIGHT, TransportMode.truck); modes.forEach(mode -> { ScoringConfigGroup.ModeParams thisModeParams = new ScoringConfigGroup.ModeParams(mode); @@ -183,13 +184,13 @@ public static void prepareCommercialTrafficConfig(Config config) { Set networkModes = new HashSet<>(config.routing().getNetworkModes()); config.routing().setNetworkModes(Sets.union(networkModes, modes)); - config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("commercial_start").setTypicalDuration(30 * 60)); - config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("commercial_end").setTypicalDuration(30 * 60)); - config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("service").setTypicalDuration(30 * 60)); - config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("start").setTypicalDuration(30 * 60)); - config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("end").setTypicalDuration(30 * 60)); - config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("freight_start").setTypicalDuration(30 * 60)); - config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("freight_end").setTypicalDuration(30 * 60)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("commercial_start").setTypicalDuration(30 * 60.)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("commercial_end").setTypicalDuration(30 * 60.)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("service").setTypicalDuration(30 * 60.)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("start").setTypicalDuration(30 * 60.)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("end").setTypicalDuration(30 * 60.)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("freight_start").setTypicalDuration(30 * 60.)); + config.scoring().addActivityParams(new ScoringConfigGroup.ActivityParams("freight_end").setTypicalDuration(30 * 60.)); //TODO: add freight and remove from config or change freight subpopulation and mode for long distance freight for (String subpopulation : List.of("commercialPersonTraffic", "commercialPersonTraffic_service", "goodsTraffic")) {