diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystem.java b/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystem.java
index 9bd5fb6b2b1..3ac817d3613 100644
--- a/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystem.java
+++ b/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystem.java
@@ -15,6 +15,5 @@ public interface ZoneSystem {
List getLinksForZoneId(Id zone);
-
Map, Zone> getZones();
}
diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystemUtils.java b/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystemUtils.java
index 7352cd74278..d679bc2c2bb 100644
--- a/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystemUtils.java
+++ b/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystemUtils.java
@@ -55,16 +55,16 @@ public final class ZoneSystemUtils {
private ZoneSystemUtils() {}
public static ZoneSystem createZoneSystem(Network network, ZoneSystemParams zoneSystemParams) {
- return createZoneSystem(null, network, zoneSystemParams, null);
+ return createZoneSystem(null, network, zoneSystemParams, null, zone -> true);
}
public static ZoneSystem createZoneSystem(URL context, Network network, ZoneSystemParams zoneSystemParams) {
- return createZoneSystem(context, network, zoneSystemParams, null);
+ return createZoneSystem(context, network, zoneSystemParams, null, zone -> true);
}
-
public static ZoneSystem createZoneSystem(@Nullable URL context, @Nonnull Network network,
- @Nonnull ZoneSystemParams zoneSystemParams, @Nullable String crs) {
+ @Nonnull ZoneSystemParams zoneSystemParams, @Nullable String crs,
+ Predicate zoneFilter) {
final ZoneSystem zoneSystem = switch (zoneSystemParams.getName()) {
case GISFileZoneSystemParams.SET_NAME -> {
@@ -72,20 +72,15 @@ public static ZoneSystem createZoneSystem(@Nullable URL context, @Nonnull Networ
Preconditions.checkNotNull(context);
URL url = ConfigGroup.getInputFileURL(context, ((GISFileZoneSystemParams) zoneSystemParams).zonesShapeFile);
Collection features = GeoFileReader.getAllFeatures(url);
- yield ZoneSystemUtils.createFromFeatures(network, features);
+ yield ZoneSystemUtils.createFromFeatures(network, features, zoneFilter);
}
case SquareGridZoneSystemParams.SET_NAME -> {
Preconditions.checkNotNull(((SquareGridZoneSystemParams) zoneSystemParams).cellSize);
-
- Predicate zoneFilter = zone -> true;
- SquareGridZoneSystem squareGridZoneSystem = new SquareGridZoneSystem(network, ((SquareGridZoneSystemParams) zoneSystemParams).cellSize, zoneFilter);
- yield squareGridZoneSystem;
+ yield new SquareGridZoneSystem(network, ((SquareGridZoneSystemParams) zoneSystemParams).cellSize, zoneFilter);
}
case H3GridZoneSystemParams.SET_NAME -> {
Preconditions.checkNotNull(((H3GridZoneSystemParams) zoneSystemParams).h3Resolution);
Preconditions.checkNotNull(crs);
-
- Predicate zoneFilter = zone -> true;
yield new H3ZoneSystem(crs, ((H3GridZoneSystemParams) zoneSystemParams).h3Resolution, network, zoneFilter);
}
default -> throw new IllegalStateException("Unexpected value: " + zoneSystemParams.getName());
@@ -93,7 +88,7 @@ public static ZoneSystem createZoneSystem(@Nullable URL context, @Nonnull Networ
return zoneSystem;
}
- public static ZoneSystem createFromFeatures(Network network, Collection features) {
+ public static ZoneSystem createFromFeatures(Network network, Collection features, Predicate zoneFilter) {
Map featureById = StreamEx.of(features.stream())
.mapToEntry(SimpleFeature::getID, sf -> new PreparedFeature(sf, new PreparedPolygon((Polygonal) sf.getDefaultGeometry())))
@@ -119,9 +114,9 @@ public static ZoneSystem createFromFeatures(Network network, Collection zone));
-
return new ZoneSystemImpl(zones.values(), new ZoneFinderImpl(zones), network);
}
diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtModeZonalSystemModule.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtModeZonalSystemModule.java
index 3c0352b425a..05129ba7faf 100644
--- a/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtModeZonalSystemModule.java
+++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/analysis/zonal/DrtModeZonalSystemModule.java
@@ -20,14 +20,21 @@
package org.matsim.contrib.drt.analysis.zonal;
+import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.matsim.api.core.v01.network.Network;
+import org.matsim.contrib.common.zones.Zone;
import org.matsim.contrib.common.zones.ZoneSystem;
import org.matsim.contrib.common.zones.ZoneSystemParams;
import org.matsim.contrib.common.zones.ZoneSystemUtils;
import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule;
+import org.matsim.core.config.ConfigGroup;
import org.matsim.core.controler.MatsimServices;
+import org.matsim.utils.gis.shp2matsim.ShpGeometryUtils;
+
+import java.util.List;
+import java.util.function.Predicate;
/**
* @author Michal Maciejewski (michalm)
@@ -50,7 +57,16 @@ public void install() {
bindModal(ZoneSystem.class).toProvider(modalProvider(getter -> {
Network network = getter.getModal(Network.class);
- return ZoneSystemUtils.createZoneSystem(getConfig().getContext(), network, zoneSystemParams, crs);
+ Predicate zoneFilter;
+ if(drtCfg.operationalScheme == DrtConfigGroup.OperationalScheme.serviceAreaBased) {
+ List serviceAreaGeoms = ShpGeometryUtils.loadPreparedGeometries(
+ ConfigGroup.getInputFileURL(this.getConfig().getContext(), this.drtCfg.drtServiceAreaShapeFile));
+ zoneFilter = zone -> serviceAreaGeoms.stream()
+ .anyMatch((serviceArea) -> serviceArea.intersects(zone.getPreparedGeometry().getGeometry()));
+ } else {
+ zoneFilter = zone -> true;
+ }
+ return ZoneSystemUtils.createZoneSystem(getConfig().getContext(), network, zoneSystemParams, crs, zoneFilter);
})).asEagerSingleton();
bindModal(DrtZoneTargetLinkSelector.class).toProvider(modalProvider(getter -> {
diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/router/DvrpModeRoutingNetworkModule.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/router/DvrpModeRoutingNetworkModule.java
index 42f9267f7a3..076ce4876ec 100644
--- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/router/DvrpModeRoutingNetworkModule.java
+++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/router/DvrpModeRoutingNetworkModule.java
@@ -85,7 +85,7 @@ public void install() {
Network network = getter.getModal(Network.class);
DvrpTravelTimeMatrixParams matrixParams = dvrpConfigGroup.getTravelTimeMatrixParams();
ZoneSystem zoneSystem = ZoneSystemUtils.createZoneSystem(getConfig().getContext(), network,
- matrixParams.getZoneSystemParams(), getConfig().global().getCoordinateSystem());
+ matrixParams.getZoneSystemParams(), getConfig().global().getCoordinateSystem(), zone -> true);
return FreeSpeedTravelTimeMatrix.createFreeSpeedMatrix(network, zoneSystem,
matrixParams, globalConfigGroup.getNumberOfThreads(),
qSimConfigGroup.getTimeStepSize());
diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpModule.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpModule.java
index 44da59b0388..d31fe11499d 100644
--- a/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpModule.java
+++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/run/DvrpModule.java
@@ -89,7 +89,7 @@ public TravelTimeMatrix get() {
var params = dvrpConfigGroup.getTravelTimeMatrixParams();
DvrpTravelTimeMatrixParams matrixParams = dvrpConfigGroup.getTravelTimeMatrixParams();
ZoneSystem zoneSystem = ZoneSystemUtils.createZoneSystem(getConfig().getContext(), network,
- matrixParams.getZoneSystemParams(), getConfig().global().getCoordinateSystem());
+ matrixParams.getZoneSystemParams(), getConfig().global().getCoordinateSystem(), zone -> true);
return FreeSpeedTravelTimeMatrix.createFreeSpeedMatrix(network, zoneSystem, params, numberOfThreads,
qSimConfigGroup.getTimeStepSize());
}
diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/zone/skims/AdaptiveTravelTimeMatrixModule.java b/contribs/dvrp/src/main/java/org/matsim/contrib/zone/skims/AdaptiveTravelTimeMatrixModule.java
index d0bf361fd40..ec6f908679e 100644
--- a/contribs/dvrp/src/main/java/org/matsim/contrib/zone/skims/AdaptiveTravelTimeMatrixModule.java
+++ b/contribs/dvrp/src/main/java/org/matsim/contrib/zone/skims/AdaptiveTravelTimeMatrixModule.java
@@ -52,7 +52,7 @@ public void install() {
Network network = getter.getModal(Network.class);
DvrpTravelTimeMatrixParams matrixParams = dvrpConfigGroup.getTravelTimeMatrixParams();
ZoneSystem zoneSystem = ZoneSystemUtils.createZoneSystem(getConfig().getContext(), network,
- matrixParams.getZoneSystemParams(), getConfig().global().getCoordinateSystem());
+ matrixParams.getZoneSystemParams(), getConfig().global().getCoordinateSystem(), zone -> true);
return new AdaptiveTravelTimeMatrixImpl(qsimConfig.getEndTime().orElse(ALTERNATIVE_ENDTIME),
network,
zoneSystem,
diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/optimizer/ETaxiOptimizerProvider.java b/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/optimizer/ETaxiOptimizerProvider.java
index 30458550f44..f611e301e36 100644
--- a/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/optimizer/ETaxiOptimizerProvider.java
+++ b/contribs/taxi/src/main/java/org/matsim/contrib/etaxi/optimizer/ETaxiOptimizerProvider.java
@@ -99,7 +99,7 @@ public TaxiOptimizer get() {
private ZonalRegisters createZonalRegisters(RuleBasedTaxiOptimizerParams params, Config config) {
ZoneSystem zoneSystem = ZoneSystemUtils.createZoneSystem(config.getContext(), network,
- params.getZoneSystemParams(), config.global().getCoordinateSystem());
+ params.getZoneSystemParams(), config.global().getCoordinateSystem(), zone -> true);
IdleTaxiZonalRegistry idleTaxiRegistry = new IdleTaxiZonalRegistry(zoneSystem,
eScheduler.getScheduleInquiry());
UnplannedRequestZonalRegistry unplannedRequestRegistry = new UnplannedRequestZonalRegistry(zoneSystem);