Skip to content

Commit

Permalink
add option to disable/enable parking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Dec 6, 2023
1 parent 5a4e863 commit 4169787
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
32 changes: 16 additions & 16 deletions src/main/java/org/matsim/run/RunLeipzigScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -282,7 +283,6 @@ protected void prepareScenario(Scenario scenario) {
DrtCaseSetup.prepareScenario(scenario, drtCase, new ShpOptions(networkOpt.getDrtArea(), null, null), VERSION);
}


}

@Override
Expand All @@ -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());
}
});

Expand Down
16 changes: 7 additions & 9 deletions src/test/java/org/matsim/run/ParkingLeipzigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
}

0 comments on commit 4169787

Please sign in to comment.