Skip to content

Commit

Permalink
adding informed mode choice module and config
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Nov 28, 2023
1 parent 3b6618e commit bfef3b1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion input/test.config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<param name="weight" value="0.10"/>
</parameterset>
<parameterset type="strategysettings">
<param name="strategyName" value="SubtourModeChoice"/>
<param name="strategyName" value="SelectSubtourMode"/>
<param name="subpopulation" value="person"/>
<param name="weight" value="0.10"/>
</parameterset>
Expand Down
2 changes: 1 addition & 1 deletion input/test.with-drt.config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<param name="weight" value="0.10"/>
</parameterset>
<parameterset type="strategysettings">
<param name="strategyName" value="SubtourModeChoice"/>
<param name="strategyName" value="SelectSubtourMode"/>
<param name="subpopulation" value="person"/>
<param name="weight" value="0.10"/>
</parameterset>
Expand Down
10 changes: 4 additions & 6 deletions input/v3.1/kelheim-v3.1-25pct.kexi.config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,10 @@
<param name="coordDistance" value="100"/>
</module>

<!--
<module name="informedModeChoice">
<param name="modes" value="car,ride,pt,bike,walk"/>
<param name="topK" value="5"/>
</module>
-->
<module name="informedModeChoice">
<param name="modes" value="car,pt,bike,walk,ride,drt"/>
<param name="topK" value="5"/>
</module>

<module name="transitRouter">
<param name="extensionRadius" value="500.0"/>
Expand Down
6 changes: 2 additions & 4 deletions input/v3.1/kelheim-v3.1-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<param name="weight" value="0.10"/>
</parameterset>
<parameterset type="strategysettings">
<param name="strategyName" value="SubtourModeChoice"/>
<param name="strategyName" value="SelectSubtourMode"/>
<param name="subpopulation" value="person"/>
<param name="weight" value="0.10"/>
</parameterset>
Expand Down Expand Up @@ -131,12 +131,10 @@
<param name="coordDistance" value="100"/>
</module>

<!--
<module name="informedModeChoice">
<param name="modes" value="car,ride,pt,bike,walk"/>
<param name="modes" value="car,pt,bike,walk,ride"/>
<param name="topK" value="5"/>
</module>
-->

<module name="transitRouter">
<param name="extensionRadius" value="500.0"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>matsim-all</artifactId>

<!-- PR-labelled release -->
<version>16.0-PR2878</version>
<version>16.0-PR2968</version>

<!-- snapshot == not recommended: rather use PR-labelled release!-->
<!-- <version>16.0-SNAPSHOT</matsim.version>-->
Expand Down
56 changes: 35 additions & 21 deletions src/main/java/org/matsim/run/RunKelheimScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/matsim/run/RunKelheimIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit bfef3b1

Please sign in to comment.