From 4169787dcf8eb8c2f6c6eb7faf4dd9fa6da38bb0 Mon Sep 17 00:00:00 2001 From: rakow Date: Wed, 6 Dec 2023 15:33:01 +0100 Subject: [PATCH] add option to disable/enable parking logic --- .../org/matsim/run/RunLeipzigScenario.java | 32 +++++++++---------- .../org/matsim/run/ParkingLeipzigTest.java | 16 ++++------ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/matsim/run/RunLeipzigScenario.java b/src/main/java/org/matsim/run/RunLeipzigScenario.java index 7c442f3c..4ab5bc5e 100644 --- a/src/main/java/org/matsim/run/RunLeipzigScenario.java +++ b/src/main/java/org/matsim/run/RunLeipzigScenario.java @@ -84,6 +84,9 @@ public class RunLeipzigScenario extends MATSimApplication { @CommandLine.Option(names = "--bikes", defaultValue = "onNetworkWithStandardMatsim", description = "Define how bicycles are handled") private BicycleHandling bike; + @CommandLine.Option(names = "--parking", defaultValue = "false", description = "Define if parking logic should be enabled.") + private boolean parking = false; + //TODO: define adequate values for the following doubles @CommandLine.Option(names = "--parking-cost-time-period-start", defaultValue = "0", description = "Start of time period for which parking cost will be charged.") private Double parkingCostTimePeriodStart; @@ -261,12 +264,10 @@ protected Config prepareConfig(Config config) { default -> throw new IllegalStateException("Unexpected value: " + bike); } - if (networkOpt.hasParkingCostArea()) { + if (parking) { ConfigUtils.addOrGetModule(config, ParkingCostConfigGroup.class); config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams(TripStructureUtils.createStageActivityType("parking")).setScoringThisActivityAtAll(false)); - adjustStrategiesForParking(config); - } return config; @@ -282,7 +283,6 @@ protected void prepareScenario(Scenario scenario) { DrtCaseSetup.prepareScenario(scenario, drtCase, new ShpOptions(networkOpt.getDrtArea(), null, null), VERSION); } - } @Override @@ -306,24 +306,24 @@ public void install() { // Plots how many different modes agents tried out addControlerListenerBinding().to(ModeChoiceCoverageControlerListener.class); - // Leipzig specific planning strategies - this.addPersonPrepareForSimAlgorithm().to(LeipzigRouterPlanAlgorithm.class); - this.addPlanStrategyBinding(LeipzigRoutingStrategyProvider.STRATEGY_NAME).toProvider(LeipzigRoutingStrategyProvider.class); - this.addPlanStrategyBinding(LeipzigSubtourModeChoice.STRATEGY_NAME).toProvider(LeipzigSubtourModeChoice.class); + // Leipzig parking specific planning strategies + if (parking) { + this.addPersonPrepareForSimAlgorithm().to(LeipzigRouterPlanAlgorithm.class); + this.addPlanStrategyBinding(LeipzigRoutingStrategyProvider.STRATEGY_NAME).toProvider(LeipzigRoutingStrategyProvider.class); + this.addPlanStrategyBinding(LeipzigSubtourModeChoice.STRATEGY_NAME).toProvider(LeipzigSubtourModeChoice.class); - // Normally this is bound with the default subtour mode choice, because we use our own variant this is bound again here - bind(PermissibleModesCalculator.class).to(PermissibleModesCalculatorImpl.class); + // Normally this is bound with the default subtour mode choice, because we use our own variant this is bound again here + bind(PermissibleModesCalculator.class).to(PermissibleModesCalculatorImpl.class); - if (networkOpt.hasCarFreeArea()) { - bind(MultimodalLinkChooser.class).to(CarfreeMultimodalLinkChooser.class); + this.addEventHandlerBinding().toInstance(new TimeRestrictedParkingCostHandler(parkingCostTimePeriodStart, parkingCostTimePeriodEnd)); } - if (networkOpt.hasParkingCostArea()) { - - this.addEventHandlerBinding().toInstance(new TimeRestrictedParkingCostHandler(parkingCostTimePeriodStart, parkingCostTimePeriodEnd)); - install(new PersonMoneyEventsAnalysisModule()); + if (networkOpt.hasCarFreeArea()) { + bind(MultimodalLinkChooser.class).to(CarfreeMultimodalLinkChooser.class); } + + install(new PersonMoneyEventsAnalysisModule()); } }); diff --git a/src/test/java/org/matsim/run/ParkingLeipzigTest.java b/src/test/java/org/matsim/run/ParkingLeipzigTest.java index 9e4fd243..648d4abb 100644 --- a/src/test/java/org/matsim/run/ParkingLeipzigTest.java +++ b/src/test/java/org/matsim/run/ParkingLeipzigTest.java @@ -2,17 +2,15 @@ import org.junit.Test; import org.matsim.analysis.ParkingLocation; -import org.matsim.api.core.v01.population.PlanElement; -import org.matsim.api.core.v01.population.Population; import org.matsim.application.MATSimApplication; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.core.population.PopulationUtils; import org.matsim.simwrapper.SimWrapperConfigGroup; + import java.nio.file.Path; + import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; public class ParkingLeipzigTest { @@ -32,13 +30,13 @@ public final void runPoint1pctIntegrationTest() { ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; config.plans().setInputFile(URL + "leipzig-v1.2-0.1pct.plans-initial.xml.gz"); - MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct","--drt-area", exampleShp, "--post-processing", "disabled", - "--parking-cost-area", "input/v" + RunLeipzigScenario.VERSION + "/parkingCostArea/Bewohnerparken_2020.shp", - "--intermodality", "drtAsAccessEgressForPt"); + MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--drt-area", exampleShp, "--post-processing", "disabled", + "--parking-cost-area", "input/v" + RunLeipzigScenario.VERSION + "/parkingCostArea/Bewohnerparken_2020.shp", + "--parking", "--intermodality", "drtAsAccessEgressForPt"); assertThat(output) - .exists() - .isNotEmptyDirectory(); + .exists() + .isNotEmptyDirectory(); new ParkingLocation().execute("--directory", output.toString()); } }