Skip to content

Commit

Permalink
extract TaxiDvrpModules from TaxiModule, include TaxiOutputModule int…
Browse files Browse the repository at this point in the history
…o TaxiModule
  • Loading branch information
michalmac committed Mar 2, 2018
1 parent f6cf550 commit 160f080
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
*
*/
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -52,60 +38,23 @@
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<? extends Provider<? extends TaxiOptimizer>> 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());
bind(Fleet.class).toProvider(new FleetProvider(taxiCfg.getTaxisFileUrl(getConfig().getContext())))
.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
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 160f080

Please sign in to comment.