Skip to content

Commit

Permalink
Merge pull request #3173 from moia-oss/extractZonalSystemModule
Browse files Browse the repository at this point in the history
install the drt zonalsystem module independently of the rebalancing module
  • Loading branch information
nkuehnel authored Mar 18, 2024
2 parents fd6f562 + 34b30a4 commit a507598
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,55 @@ public DrtModeZonalSystemModule(DrtConfigGroup drtCfg) {

@Override
public void install() {
DrtZonalSystemParams params = drtCfg.getZonalSystemParams().orElseThrow();

bindModal(DrtZonalSystem.class).toProvider(modalProvider(getter -> {
Network network = getter.getModal(Network.class);
switch (params.zonesGeneration) {
case ShapeFile:
final List<PreparedGeometry> preparedGeometries = loadPreparedGeometries(
if (drtCfg.getZonalSystemParams().isPresent()) {
DrtZonalSystemParams params = drtCfg.getZonalSystemParams().get();

bindModal(DrtZonalSystem.class).toProvider(modalProvider(getter -> {
Network network = getter.getModal(Network.class);
switch (params.zonesGeneration) {
case ShapeFile:
final List<PreparedGeometry> preparedGeometries = loadPreparedGeometries(
ConfigGroup.getInputFileURL(getConfig().getContext(), params.zonesShapeFile));
return DrtZonalSystem.createFromPreparedGeometries(network,
return DrtZonalSystem.createFromPreparedGeometries(network,
EntryStream.of(preparedGeometries).mapKeys(i -> (i + 1) + "").toMap());

case GridFromNetwork:
Preconditions.checkNotNull(params.cellSize);
var gridZones = drtCfg.operationalScheme == OperationalScheme.serviceAreaBased ?
case GridFromNetwork:
Preconditions.checkNotNull(params.cellSize);
var gridZones = drtCfg.operationalScheme == OperationalScheme.serviceAreaBased ?
createGridFromNetworkWithinServiceArea(network, params.cellSize,
loadPreparedGeometries(ConfigGroup.getInputFileURL(getConfig().getContext(),
drtCfg.drtServiceAreaShapeFile))) :
loadPreparedGeometries(ConfigGroup.getInputFileURL(getConfig().getContext(),
drtCfg.drtServiceAreaShapeFile))) :
createGridFromNetwork(network, params.cellSize);
return DrtZonalSystem.createFromPreparedGeometries(network, gridZones);

default:
throw new RuntimeException("Unsupported zone generation");
}
})).asEagerSingleton();

bindModal(DrtZoneTargetLinkSelector.class).toProvider(modalProvider(getter -> {
switch (params.targetLinkSelection) {
case mostCentral:
return new MostCentralDrtZoneTargetLinkSelector(getter.getModal(DrtZonalSystem.class));
case random:
return new RandomDrtZoneTargetLinkSelector();
default:
throw new RuntimeException(
return DrtZonalSystem.createFromPreparedGeometries(network, gridZones);

default:
throw new RuntimeException("Unsupported zone generation");
}
})).asEagerSingleton();

bindModal(DrtZoneTargetLinkSelector.class).toProvider(modalProvider(getter -> {
switch (params.targetLinkSelection) {
case mostCentral:
return new MostCentralDrtZoneTargetLinkSelector(getter.getModal(DrtZonalSystem.class));
case random:
return new RandomDrtZoneTargetLinkSelector();
default:
throw new RuntimeException(
"Unsupported target link selection = " + params.targetLinkSelection);
}
})).asEagerSingleton();
}
})).asEagerSingleton();

//zonal analysis
bindModal(ZonalIdleVehicleXYVisualiser.class).toProvider(modalProvider(
//zonal analysis
bindModal(ZonalIdleVehicleXYVisualiser.class).toProvider(modalProvider(
getter -> new ZonalIdleVehicleXYVisualiser(getter.get(MatsimServices.class), drtCfg.getMode(),
getter.getModal(DrtZonalSystem.class)))).asEagerSingleton();
addControlerListenerBinding().to(modalKey(ZonalIdleVehicleXYVisualiser.class));
addEventHandlerBinding().to(modalKey(ZonalIdleVehicleXYVisualiser.class));
getter.getModal(DrtZonalSystem.class)))).asEagerSingleton();
addControlerListenerBinding().to(modalKey(ZonalIdleVehicleXYVisualiser.class));
addEventHandlerBinding().to(modalKey(ZonalIdleVehicleXYVisualiser.class));

bindModal(DrtZonalWaitTimesAnalyzer.class).toProvider(modalProvider(
bindModal(DrtZonalWaitTimesAnalyzer.class).toProvider(modalProvider(
getter -> new DrtZonalWaitTimesAnalyzer(drtCfg, getter.getModal(DrtEventSequenceCollector.class),
getter.getModal(DrtZonalSystem.class)))).asEagerSingleton();
addControlerListenerBinding().to(modalKey(DrtZonalWaitTimesAnalyzer.class));
getter.getModal(DrtZonalSystem.class)))).asEagerSingleton();
addControlerListenerBinding().to(modalKey(DrtZonalWaitTimesAnalyzer.class));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public RebalancingModule(DrtConfigGroup drtCfg) {
public void install() {
if (drtCfg.getRebalancingParams().isPresent()) {
RebalancingParams rebalancingParams = drtCfg.getRebalancingParams().get();
install(new DrtModeZonalSystemModule(drtCfg));

if (rebalancingParams.getRebalancingStrategyParams() instanceof MinCostFlowRebalancingStrategyParams) {
install(new DrtModeMinCostFlowRebalancingModule(drtCfg));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.inject.name.Names;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector;
import org.matsim.contrib.drt.analysis.zonal.DrtModeZonalSystemModule;
import org.matsim.contrib.drt.fare.DrtFareHandler;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingModule;
import org.matsim.contrib.drt.prebooking.analysis.PrebookingModeAnalysisModule;
Expand Down Expand Up @@ -65,6 +66,7 @@ public void install() {
null :
ConfigGroup.getInputFileURL(getConfig().getContext(), drtCfg.vehiclesFile),
drtCfg.changeStartLinkToLastLinkInSchedule));
install(new DrtModeZonalSystemModule(drtCfg));
install(new RebalancingModule(drtCfg));
install(new DrtModeRoutingModule(drtCfg));

Expand Down

0 comments on commit a507598

Please sign in to comment.