From bfef3b1c96aaf2447c2c582439dc3738aeecf2ae Mon Sep 17 00:00:00 2001 From: rakow Date: Tue, 28 Nov 2023 15:40:13 +0100 Subject: [PATCH] adding informed mode choice module and config --- input/test.config.xml | 2 +- input/test.with-drt.config.xml | 2 +- input/v3.1/kelheim-v3.1-25pct.kexi.config.xml | 10 ++-- input/v3.1/kelheim-v3.1-config.xml | 6 +- pom.xml | 2 +- .../org/matsim/run/RunKelheimScenario.java | 56 ++++++++++++------- .../matsim/run/RunKelheimIntegrationTest.java | 10 ++-- 7 files changed, 50 insertions(+), 38 deletions(-) diff --git a/input/test.config.xml b/input/test.config.xml index 4d4855c6..603cad59 100644 --- a/input/test.config.xml +++ b/input/test.config.xml @@ -100,7 +100,7 @@ - + diff --git a/input/test.with-drt.config.xml b/input/test.with-drt.config.xml index 20e47754..8fc42b90 100644 --- a/input/test.with-drt.config.xml +++ b/input/test.with-drt.config.xml @@ -99,7 +99,7 @@ - + diff --git a/input/v3.1/kelheim-v3.1-25pct.kexi.config.xml b/input/v3.1/kelheim-v3.1-25pct.kexi.config.xml index c2ea1d77..d82dfa8e 100644 --- a/input/v3.1/kelheim-v3.1-25pct.kexi.config.xml +++ b/input/v3.1/kelheim-v3.1-25pct.kexi.config.xml @@ -130,12 +130,10 @@ - + + + + diff --git a/input/v3.1/kelheim-v3.1-config.xml b/input/v3.1/kelheim-v3.1-config.xml index 14b50330..b9c0c5d7 100644 --- a/input/v3.1/kelheim-v3.1-config.xml +++ b/input/v3.1/kelheim-v3.1-config.xml @@ -100,7 +100,7 @@ - + @@ -131,12 +131,10 @@ - diff --git a/pom.xml b/pom.xml index 94f2729f..b8301e66 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ matsim-all - 16.0-PR2878 + 16.0-PR2968 diff --git a/src/main/java/org/matsim/run/RunKelheimScenario.java b/src/main/java/org/matsim/run/RunKelheimScenario.java index 6a8d4dcd..97bced30 100644 --- a/src/main/java/org/matsim/run/RunKelheimScenario.java +++ b/src/main/java/org/matsim/run/RunKelheimScenario.java @@ -30,6 +30,10 @@ import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup; import org.matsim.contrib.drt.extension.companions.DrtCompanionParams; import org.matsim.contrib.drt.extension.companions.MultiModeDrtCompanionModule; +import org.matsim.contrib.drt.extension.estimator.MultiModalDrtLegEstimator; +import org.matsim.contrib.drt.extension.estimator.run.DrtEstimatorConfigGroup; +import org.matsim.contrib.drt.extension.estimator.run.DrtEstimatorModule; +import org.matsim.contrib.drt.extension.estimator.run.MultiModeDrtEstimatorConfigGroup; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.routing.DrtRouteFactory; import org.matsim.contrib.drt.run.DrtConfigGroup; @@ -52,6 +56,13 @@ import org.matsim.core.scoring.functions.ScoringParametersForPerson; import org.matsim.drtFare.KelheimDrtFareModule; import org.matsim.extensions.pt.routing.ptRoutingModes.PtIntermodalRoutingModesConfigGroup; +import org.matsim.modechoice.InformedModeChoiceConfigGroup; +import org.matsim.modechoice.InformedModeChoiceModule; +import org.matsim.modechoice.ModeOptions; +import org.matsim.modechoice.estimators.DefaultActivityEstimator; +import org.matsim.modechoice.estimators.DefaultLegScoreEstimator; +import org.matsim.modechoice.estimators.FixedCostsEstimator; +import org.matsim.modechoice.pruning.DistanceBasedPruner; import org.matsim.run.prepare.PrepareNetwork; import org.matsim.run.prepare.PreparePopulation; import org.matsim.simwrapper.SimWrapperConfigGroup; @@ -60,6 +71,7 @@ import picocli.CommandLine; import playground.vsp.pt.fare.DistanceBasedPtFareParams; import playground.vsp.pt.fare.PtFareConfigGroup; +import playground.vsp.pt.fare.PtTripWithDistanceBasedFareEstimator; import playground.vsp.scoring.IncomeDependentUtilityOfMoneyPersonScoringParameters; import javax.annotation.Nullable; @@ -166,6 +178,10 @@ protected Config prepareConfig(Config config) { sw.defaultParams().mapZoomLevel = 11d; sw.defaultParams().sampleSize = sample.getSample(); + // Config needs to be loaded at least once + InformedModeChoiceConfigGroup imc = ConfigUtils.addOrGetModule(config, InformedModeChoiceConfigGroup.class); + imc.setTopK(5); + if (intermodal) { ConfigUtils.addOrGetModule(config, PtIntermodalRoutingModesConfigGroup.class); } @@ -278,24 +294,22 @@ public void install() { bind(AnalysisMainModeIdentifier.class).to(KelheimMainModeIdentifier.class); addControlerListenerBinding().to(ModeChoiceCoverageControlerListener.class); - /* - if (strategy.getModeChoice() == StrategyOptions.ModeChoice.randomSubtourMode) { - // Configure mode-choice strategy - install(strategy.applyModule(binder(), config, builder -> - builder.withFixedCosts(FixedCostsEstimator.DailyConstant.class, TransportMode.car) - .withLegEstimator(DefaultLegScoreEstimator.class, ModeOptions.AlwaysAvailable.class, TransportMode.bike, TransportMode.ride, TransportMode.walk) - .withLegEstimator(DefaultLegScoreEstimator.class, ModeOptions.ConsiderIfCarAvailable.class, TransportMode.car) -// .withLegEstimator(MultiModalDrtLegEstimator.class, ModeOptions.AlwaysAvailable.class, "drt", "av") - .withTripEstimator(PtTripWithDistanceBasedFareEstimator.class, ModeOptions.AlwaysAvailable.class, TransportMode.pt) - .withActivityEstimator(DefaultActivityEstimator.class) - // These are with activity estimation enabled - .withPruner("ad999", new DistanceBasedPruner(3.03073657, 0.22950583)) - .withPruner("ad99", new DistanceBasedPruner(2.10630819, 0.0917091)) - .withPruner("ad95", new DistanceBasedPruner(1.72092386, 0.03189323)) - ) - ); + // Configure mode-choice strategy + InformedModeChoiceModule.Builder imc = new InformedModeChoiceModule.Builder() + .withFixedCosts(FixedCostsEstimator.DailyConstant.class, TransportMode.car) + .withLegEstimator(DefaultLegScoreEstimator.class, ModeOptions.AlwaysAvailable.class, TransportMode.bike, TransportMode.ride, TransportMode.walk) + .withLegEstimator(DefaultLegScoreEstimator.class, ModeOptions.ConsiderIfCarAvailable.class, TransportMode.car) + .withTripEstimator(PtTripWithDistanceBasedFareEstimator.class, ModeOptions.AlwaysAvailable.class, TransportMode.pt) + .withActivityEstimator(DefaultActivityEstimator.class) + .withPruner("ad999", new DistanceBasedPruner(3.03073657, 0.22950583)) + .withPruner("ad99", new DistanceBasedPruner(2.10630819, 0.0917091)) + .withPruner("ad95", new DistanceBasedPruner(1.72092386, 0.03189323)); + + if (drt) { + imc.withLegEstimator(MultiModalDrtLegEstimator.class, ModeOptions.AlwaysAvailable.class, TransportMode.drt, "av"); } - */ + + install(imc.build()); //use income-dependent marginal utility of money bind(ScoringParametersForPerson.class).to(IncomeDependentUtilityOfMoneyPersonScoringParameters.class).asEagerSingleton(); @@ -340,11 +354,11 @@ public void handleEvent(PersonDepartureEvent event) { controler.addOverridingModule(new KelheimDrtFareModule(drtCfg, network, avFare)); } - //controler.addOverridingModule(new DrtEstimatorModule()); - - // TODO: when to include AV? - //estimatorConfig.addParameterSet(new DrtEstimatorConfigGroup("av")); + controler.addOverridingModule(new DrtEstimatorModule()); + MultiModeDrtEstimatorConfigGroup estimatorConfig = ConfigUtils.addOrGetModule(config, MultiModeDrtEstimatorConfigGroup.class); + estimatorConfig.addParameterSet(new DrtEstimatorConfigGroup("drt")); + estimatorConfig.addParameterSet(new DrtEstimatorConfigGroup("av")); // if (intermodal){ // controler.addOverridingModule(new IntermodalTripFareCompensatorsModule()); diff --git a/src/test/java/org/matsim/run/RunKelheimIntegrationTest.java b/src/test/java/org/matsim/run/RunKelheimIntegrationTest.java index 60bee285..5035bee4 100644 --- a/src/test/java/org/matsim/run/RunKelheimIntegrationTest.java +++ b/src/test/java/org/matsim/run/RunKelheimIntegrationTest.java @@ -16,9 +16,9 @@ public class RunKelheimIntegrationTest { @Test public final void runExamplePopulationTest() { Config config = ConfigUtils.loadConfig("input/test.config.xml"); - config.controller().setLastIteration(1); - config.global().setNumberOfThreads(1); - config.qsim().setNumberOfThreads(1); + config.controller().setLastIteration(2); + config.global().setNumberOfThreads(2); + config.qsim().setNumberOfThreads(2); config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; @@ -30,7 +30,9 @@ public final void runExamplePopulationTest() { @Test public final void runDrtExamplePopulationTest() { Config config = ConfigUtils.loadConfig("input/test.with-drt.config.xml"); - config.controller().setLastIteration(1); + config.controller().setLastIteration(2); + config.global().setNumberOfThreads(2); + config.qsim().setNumberOfThreads(2); config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;