diff --git a/contribs/av/src/main/java/org/matsim/contrib/av/intermodal/RunTaxiPTIntermodalExample.java b/contribs/av/src/main/java/org/matsim/contrib/av/intermodal/RunTaxiPTIntermodalExample.java index c541c052e8f..0d85dac7a76 100644 --- a/contribs/av/src/main/java/org/matsim/contrib/av/intermodal/RunTaxiPTIntermodalExample.java +++ b/contribs/av/src/main/java/org/matsim/contrib/av/intermodal/RunTaxiPTIntermodalExample.java @@ -24,17 +24,21 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.contrib.av.intermodal.router.VariableAccessTransitRouterModule; -import org.matsim.contrib.av.intermodal.router.config.*; +import org.matsim.contrib.av.intermodal.router.config.VariableAccessConfigGroup; +import org.matsim.contrib.av.intermodal.router.config.VariableAccessModeConfigGroup; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.otfvis.OTFVisLiveModule; -import org.matsim.contrib.taxi.run.*; -import org.matsim.core.config.*; +import org.matsim.contrib.taxi.run.TaxiConfigConsistencyChecker; +import org.matsim.contrib.taxi.run.TaxiConfigGroup; +import org.matsim.contrib.taxi.run.TaxiModule; +import org.matsim.contrib.taxi.run.examples.TaxiDvrpModules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.vis.otfvis.OTFVisConfigGroup; - /** * @author jbischoff * @@ -48,14 +52,12 @@ public static void main(String[] args) { } public void run(boolean OTFVis) { - Config config = ConfigUtils.loadConfig( - "intermodal/config.xml", - new TaxiConfigGroup(), new DvrpConfigGroup()); + Config config = ConfigUtils.loadConfig("intermodal/config.xml", new TaxiConfigGroup(), new DvrpConfigGroup()); config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); - // yyyy Could you please javadoc the following? EmissionsConfigGroup has an example how the explanatory strings - // can be kept consistent between config file dump and javadoc. Thx. kai, jan'17 + // yyyy Could you please javadoc the following? EmissionsConfigGroup has an example how the explanatory strings + // can be kept consistent between config file dump and javadoc. Thx. kai, jan'17 VariableAccessConfigGroup vacfg = new VariableAccessConfigGroup(); { VariableAccessModeConfigGroup taxi = new VariableAccessModeConfigGroup(); @@ -84,13 +86,13 @@ public void run(boolean OTFVis) { config.checkConsistency(); // --- Scenario scenario = ScenarioUtils.loadScenario(config); - + Controler controler = new Controler(scenario); - controler.addOverridingModule(new TaxiOutputModule()); + controler.addOverridingModule(TaxiDvrpModules.create()); + + controler.addOverridingModule(new TaxiModule()); - controler.addOverridingModule(new TaxiModule()); - controler.addOverridingModule(new VariableAccessTransitRouterModule()); if (OTFVis) { controler.addOverridingModule(new OTFVisLiveModule()); diff --git a/contribs/av/src/main/java/org/matsim/contrib/av/robotaxi/run/RunRobotaxiExample.java b/contribs/av/src/main/java/org/matsim/contrib/av/robotaxi/run/RunRobotaxiExample.java index 4e23d892f10..94386e31ef9 100644 --- a/contribs/av/src/main/java/org/matsim/contrib/av/robotaxi/run/RunRobotaxiExample.java +++ b/contribs/av/src/main/java/org/matsim/contrib/av/robotaxi/run/RunRobotaxiExample.java @@ -20,24 +20,28 @@ package org.matsim.contrib.av.robotaxi.run; import org.matsim.api.core.v01.Scenario; -import org.matsim.contrib.av.robotaxi.scoring.*; +import org.matsim.contrib.av.robotaxi.scoring.TaxiFareConfigGroup; +import org.matsim.contrib.av.robotaxi.scoring.TaxiFareHandler; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.otfvis.OTFVisLiveModule; -import org.matsim.contrib.taxi.run.*; -import org.matsim.core.config.*; -import org.matsim.core.controler.*; +import org.matsim.contrib.taxi.run.TaxiConfigConsistencyChecker; +import org.matsim.contrib.taxi.run.TaxiConfigGroup; +import org.matsim.contrib.taxi.run.TaxiModule; +import org.matsim.contrib.taxi.run.examples.TaxiDvrpModules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.controler.AbstractModule; +import org.matsim.core.controler.Controler; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.vis.otfvis.OTFVisConfigGroup; /** - * This class runs an example robotaxi scenario including scoring. The - * simulation runs for 10 iterations, this takes quite a bit time (25 minutes or - * so). You may switch on OTFVis visualisation in the main method below. - * The scenario should run out of the box without any additional files. - * If required, you may find all input files in the resource path - * or in the jar maven has downloaded). - * There are two vehicle files: 2000 vehicles and 5000, which may be set in the config. - * Different fleet sizes can be created using {@link org.matsim.contrib.robotaxi.vehicles.CreateTaxiVehicles} + * This class runs an example robotaxi scenario including scoring. The simulation runs for 10 iterations, this takes + * quite a bit time (25 minutes or so). You may switch on OTFVis visualisation in the main method below. The scenario + * should run out of the box without any additional files. If required, you may find all input files in the resource + * path or in the jar maven has downloaded). There are two vehicle files: 2000 vehicles and 5000, which may be set in + * the config. Different fleet sizes can be created using + * {@link org.matsim.contrib.robotaxi.vehicles.CreateTaxiVehicles} * * */ @@ -67,7 +71,7 @@ public void install() { addEventHandlerBinding().to(TaxiFareHandler.class).asEagerSingleton(); } }); - controler.addOverridingModule(new TaxiOutputModule()); + controler.addOverridingModule(TaxiDvrpModules.create()); controler.addOverridingModule(new TaxiModule()); if (otfvis) { diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtControlerCreator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtControlerCreator.java index c0233f9ad77..83032fcff92 100644 --- a/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtControlerCreator.java +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtControlerCreator.java @@ -67,17 +67,17 @@ public final class DrtControlerCreator { public static Controler createControler(Config config, boolean otfvis) { adjustConfig(config); Scenario scenario = ScenarioUtils.loadScenario(config); - return adjustControler(otfvis, scenario); + return createControlerImpl(otfvis, scenario); } public static Controler createControler(Scenario scenario, boolean otfvis) { // yy I know that this one breaks the sequential loading of the building blocks, but I would like to be able // to modify the scenario before I pass it to the controler. kai, oct'17 adjustConfig(scenario.getConfig()); - return adjustControler(otfvis, scenario); + return createControlerImpl(otfvis, scenario); } - private static Controler adjustControler(boolean otfvis, Scenario scenario) { + private static Controler createControlerImpl(boolean otfvis, Scenario scenario) { Controler controler = new Controler(scenario); controler.addOverridingModule(new DvrpModule(DrtControlerCreator::createModuleForQSimPlugin, DrtOptimizer.class, DefaultUnplannedRequestInserter.class, ParallelPathDataProvider.class)); diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/benchmark/RunTaxiBenchmark.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/benchmark/RunTaxiBenchmark.java index 8f21fe034d2..95663744440 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/benchmark/RunTaxiBenchmark.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/benchmark/RunTaxiBenchmark.java @@ -24,7 +24,7 @@ import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.taxi.run.TaxiConfigGroup; import org.matsim.contrib.taxi.run.TaxiModule; -import org.matsim.contrib.taxi.run.TaxiOutputModule; +import org.matsim.contrib.taxi.run.examples.TaxiDvrpModules; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.AbstractModule; @@ -59,7 +59,7 @@ public static Controler createControler(Config config, int runs) { Controler controler = new Controler(scenario); controler.setModules(new DvrpBenchmarkControlerModule()); - controler.addOverridingModule(new TaxiOutputModule()); + controler.addOverridingModule(TaxiDvrpModules.create()); controler.addOverridingModule(new TaxiModule()); controler.addOverridingModule(new AbstractModule() { diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/RunTaxiScenario.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/RunTaxiScenario.java index 9af31a7f912..1b37dc3e935 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/RunTaxiScenario.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/RunTaxiScenario.java @@ -22,7 +22,9 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.otfvis.OTFVisLiveModule; -import org.matsim.core.config.*; +import org.matsim.contrib.taxi.run.examples.TaxiDvrpModules; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.vis.otfvis.OTFVisConfigGroup; @@ -41,7 +43,7 @@ public static Controler createControler(Config config, boolean otfvis) { Scenario scenario = ScenarioUtils.loadScenario(config); Controler controler = new Controler(scenario); - controler.addOverridingModule(new TaxiOutputModule()); + controler.addOverridingModule(TaxiDvrpModules.create()); controler.addOverridingModule(new TaxiModule()); if (otfvis) { diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiConfigGroup.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiConfigGroup.java index 51b8549b11a..ce74db92e11 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiConfigGroup.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiConfigGroup.java @@ -26,7 +26,9 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.PositiveOrZero; -import org.matsim.core.config.*; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigGroup; +import org.matsim.core.config.ReflectiveConfigGroup; public class TaxiConfigGroup extends ReflectiveConfigGroup { public static final String GROUP_NAME = "taxi"; diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiModule.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiModule.java index 750fbdefd4c..311665bc3c4 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiModule.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiModule.java @@ -21,29 +21,15 @@ import org.matsim.contrib.dvrp.data.Fleet; import org.matsim.contrib.dvrp.data.file.FleetProvider; -import org.matsim.contrib.dvrp.optimizer.VrpOptimizer; -import org.matsim.contrib.dvrp.passenger.PassengerRequestCreator; import org.matsim.contrib.dvrp.router.TimeAsTravelDisutility; -import org.matsim.contrib.dvrp.run.DvrpModule; -import org.matsim.contrib.dvrp.trafficmonitoring.DvrpTravelTimeModule; -import org.matsim.contrib.dvrp.vrpagent.VrpAgentLogic.DynActionCreator; import org.matsim.contrib.taxi.optimizer.DefaultTaxiOptimizerProvider; -import org.matsim.contrib.taxi.optimizer.TaxiOptimizer; -import org.matsim.contrib.taxi.passenger.TaxiRequestCreator; -import org.matsim.contrib.taxi.scheduler.TaxiScheduler; -import org.matsim.contrib.taxi.vrpagent.TaxiActionCreator; +import org.matsim.contrib.taxi.passenger.SubmittedTaxiRequestsCollector; +import org.matsim.contrib.taxi.util.TaxiSimulationConsistencyChecker; +import org.matsim.contrib.taxi.util.stats.TaxiStatsDumper; +import org.matsim.contrib.taxi.util.stats.TaxiStatusTimeProfileCollectorProvider; import org.matsim.core.controler.AbstractModule; -import org.matsim.core.mobsim.framework.MobsimTimer; -import org.matsim.core.mobsim.qsim.QSim; import org.matsim.core.router.costcalculators.TravelDisutilityFactory; -import org.matsim.core.router.util.TravelDisutility; -import org.matsim.core.router.util.TravelTime; -import com.google.inject.Module; -import com.google.inject.Provider; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import com.google.inject.name.Named; import com.google.inject.name.Names; /** @@ -52,52 +38,6 @@ public final class TaxiModule extends AbstractModule { public static final String TAXI_MODE = "taxi"; - private final DvrpModule dvrpModule; - - public TaxiModule() { - this(DefaultTaxiOptimizerProvider.class); - } - - public TaxiModule(Class> providerClass) { - this(new com.google.inject.AbstractModule() { - @Override - protected void configure() { - bind(TaxiOptimizer.class).toProvider(providerClass).asEagerSingleton(); - } - }); - } - - public TaxiModule(Module taxiOptimizerModule) { - dvrpModule = new DvrpModule(createModuleForQSimPlugin(taxiOptimizerModule), TaxiOptimizer.class); - } - - public static Module createModuleForQSimPlugin(Module taxiOptimizerModule) { - return new com.google.inject.AbstractModule() { - @Override - protected void configure() { - bind(VrpOptimizer.class).to(TaxiOptimizer.class); - bind(TaxiScheduler.class).asEagerSingleton(); - bind(DynActionCreator.class).to(TaxiActionCreator.class).asEagerSingleton(); - bind(PassengerRequestCreator.class).to(TaxiRequestCreator.class).asEagerSingleton(); - install(taxiOptimizerModule); - } - - @Provides - @Singleton - private MobsimTimer provideTimer(QSim qSim) { - return qSim.getSimTimer(); - } - - @Provides - @Named(DefaultTaxiOptimizerProvider.TAXI_OPTIMIZER) - private TravelDisutility provideTravelDisutility( - @Named(DvrpTravelTimeModule.DVRP_ESTIMATED) TravelTime travelTime, - @Named(DefaultTaxiOptimizerProvider.TAXI_OPTIMIZER) TravelDisutilityFactory travelDisutilityFactory) { - return travelDisutilityFactory.createTravelDisutility(travelTime); - } - }; - } - @Override public void install() { TaxiConfigGroup taxiCfg = TaxiConfigGroup.get(getConfig()); @@ -105,7 +45,16 @@ public void install() { .asEagerSingleton(); bind(TravelDisutilityFactory.class).annotatedWith(Names.named(DefaultTaxiOptimizerProvider.TAXI_OPTIMIZER)) .toInstance(travelTime -> new TimeAsTravelDisutility(travelTime)); + + bind(SubmittedTaxiRequestsCollector.class).toInstance(new SubmittedTaxiRequestsCollector()); + addControlerListenerBinding().to(SubmittedTaxiRequestsCollector.class); + + addControlerListenerBinding().to(TaxiSimulationConsistencyChecker.class); + addControlerListenerBinding().to(TaxiStatsDumper.class); - install(dvrpModule); + if (taxiCfg.getTimeProfiles()) { + addMobsimListenerBinding().toProvider(TaxiStatusTimeProfileCollectorProvider.class); + // add more time profiles if necessary + } } } diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiOutputModule.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiOutputModule.java deleted file mode 100644 index a3433622cc0..00000000000 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/TaxiOutputModule.java +++ /dev/null @@ -1,47 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2016 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.taxi.run; - -import org.matsim.contrib.taxi.passenger.SubmittedTaxiRequestsCollector; -import org.matsim.contrib.taxi.util.TaxiSimulationConsistencyChecker; -import org.matsim.contrib.taxi.util.stats.TaxiStatsDumper; -import org.matsim.contrib.taxi.util.stats.TaxiStatusTimeProfileCollectorProvider; -import org.matsim.core.controler.AbstractModule; - -import com.google.inject.Inject; - -public class TaxiOutputModule extends AbstractModule { - @Inject - private TaxiConfigGroup taxiCfg; - - @Override - public void install() { - bind(SubmittedTaxiRequestsCollector.class).toInstance(new SubmittedTaxiRequestsCollector()); - addControlerListenerBinding().to(SubmittedTaxiRequestsCollector.class); - - addControlerListenerBinding().to(TaxiSimulationConsistencyChecker.class); - addControlerListenerBinding().to(TaxiStatsDumper.class); - - if (taxiCfg.getTimeProfiles()) { - addMobsimListenerBinding().toProvider(TaxiStatusTimeProfileCollectorProvider.class); - // add more time profiles if necessary - } - } -} diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/examples/RunTaxiExample.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/examples/RunTaxiExample.java index bce01477841..b51b48dcaec 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/examples/RunTaxiExample.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/examples/RunTaxiExample.java @@ -54,14 +54,14 @@ public static void run(boolean otfvis, int lastIteration) { final boolean ownTaxiOptimizer = false; if (!ownTaxiOptimizer) { - controler.addOverridingModule(new TaxiModule()); + controler.addOverridingModule(TaxiDvrpModules.create()); // (default taxi optimizer) } else { - controler.addOverridingModule(new TaxiModule(MyTaxiOptimizerProvider.class)); + controler.addOverridingModule(TaxiDvrpModules.create(MyTaxiOptimizerProvider.class)); // (implement your own taxi optimizer) } - controler.addOverridingModule(new TaxiOutputModule()); // taxi output (can be commented out) + controler.addOverridingModule(new TaxiModule()); // taxi output (can be commented out) if (otfvis) { controler.addOverridingModule(new OTFVisLiveModule()); // OTFVis visualisation diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/examples/TaxiDvrpModules.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/examples/TaxiDvrpModules.java new file mode 100644 index 00000000000..495c16c2efc --- /dev/null +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/run/examples/TaxiDvrpModules.java @@ -0,0 +1,90 @@ +/* *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) 2018 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.contrib.taxi.run.examples; + +import org.matsim.contrib.dvrp.optimizer.VrpOptimizer; +import org.matsim.contrib.dvrp.passenger.PassengerRequestCreator; +import org.matsim.contrib.dvrp.run.DvrpModule; +import org.matsim.contrib.dvrp.trafficmonitoring.DvrpTravelTimeModule; +import org.matsim.contrib.dvrp.vrpagent.VrpAgentLogic.DynActionCreator; +import org.matsim.contrib.taxi.optimizer.DefaultTaxiOptimizerProvider; +import org.matsim.contrib.taxi.optimizer.TaxiOptimizer; +import org.matsim.contrib.taxi.passenger.TaxiRequestCreator; +import org.matsim.contrib.taxi.scheduler.TaxiScheduler; +import org.matsim.contrib.taxi.vrpagent.TaxiActionCreator; +import org.matsim.core.mobsim.framework.MobsimTimer; +import org.matsim.core.mobsim.qsim.QSim; +import org.matsim.core.router.costcalculators.TravelDisutilityFactory; +import org.matsim.core.router.util.TravelDisutility; +import org.matsim.core.router.util.TravelTime; + +import com.google.inject.Module; +import com.google.inject.Provider; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.name.Named; + +/** + * @author michalm + */ +public class TaxiDvrpModules { + public static DvrpModule create() { + return create(DefaultTaxiOptimizerProvider.class); + } + + public static DvrpModule create(Class> providerClass) { + return create(new com.google.inject.AbstractModule() { + @Override + protected void configure() { + bind(TaxiOptimizer.class).toProvider(providerClass).asEagerSingleton(); + } + }); + } + + public static DvrpModule create(Module taxiOptimizerModule) { + return new DvrpModule(createModuleForQSimPlugin(taxiOptimizerModule), TaxiOptimizer.class); + } + + public static Module createModuleForQSimPlugin(Module taxiOptimizerModule) { + return new com.google.inject.AbstractModule() { + @Override + protected void configure() { + bind(VrpOptimizer.class).to(TaxiOptimizer.class); + bind(TaxiScheduler.class).asEagerSingleton(); + bind(DynActionCreator.class).to(TaxiActionCreator.class).asEagerSingleton(); + bind(PassengerRequestCreator.class).to(TaxiRequestCreator.class).asEagerSingleton(); + install(taxiOptimizerModule); + } + + @Provides + @Singleton + private MobsimTimer provideTimer(QSim qSim) { + return qSim.getSimTimer(); + } + + @Provides + @Named(DefaultTaxiOptimizerProvider.TAXI_OPTIMIZER) + private TravelDisutility provideTravelDisutility( + @Named(DvrpTravelTimeModule.DVRP_ESTIMATED) TravelTime travelTime, + @Named(DefaultTaxiOptimizerProvider.TAXI_OPTIMIZER) TravelDisutilityFactory travelDisutilityFactory) { + return travelDisutilityFactory.createTravelDisutility(travelTime); + } + }; + } +}