From 0b914da713ba932b87d1c52265428754795b6042 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 1 Aug 2024 16:14:29 +0200 Subject: [PATCH] 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) + ); + } + } }