Skip to content

Commit

Permalink
Merge branch 'master' into fixedApproachDrtDropoffs
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel authored May 30, 2024
2 parents ff8474b + d5b1700 commit 9960d20
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ public interface ZoneSystem {

List<Link> getLinksForZoneId(Id<Zone> zone);


Map<Id<Zone>, Zone> getZones();
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,40 @@ 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<Zone> zoneFilter) {

final ZoneSystem zoneSystem = switch (zoneSystemParams.getName()) {
case GISFileZoneSystemParams.SET_NAME -> {
Preconditions.checkNotNull(((GISFileZoneSystemParams) zoneSystemParams).zonesShapeFile);
Preconditions.checkNotNull(context);
URL url = ConfigGroup.getInputFileURL(context, ((GISFileZoneSystemParams) zoneSystemParams).zonesShapeFile);
Collection<SimpleFeature> 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<Zone> 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<Zone> zoneFilter = zone -> true;
yield new H3ZoneSystem(crs, ((H3GridZoneSystemParams) zoneSystemParams).h3Resolution, network, zoneFilter);
}
default -> throw new IllegalStateException("Unexpected value: " + zoneSystemParams.getName());
};
return zoneSystem;
}

public static ZoneSystem createFromFeatures(Network network, Collection<SimpleFeature> features) {
public static ZoneSystem createFromFeatures(Network network, Collection<SimpleFeature> features, Predicate<Zone> zoneFilter) {

Map<String, PreparedFeature> featureById = StreamEx.of(features.stream())
.mapToEntry(SimpleFeature::getID, sf -> new PreparedFeature(sf, new PreparedPolygon((Polygonal) sf.getDefaultGeometry())))
Expand All @@ -119,9 +114,9 @@ public static ZoneSystem createFromFeatures(Network network, Collection<SimpleFe
}
return zone;
})
.filter(zoneFilter)
.collect(IdCollectors.toIdMap(Zone.class, Identifiable::getId, zone -> zone));


return new ZoneSystemImpl(zones.values(), new ZoneFinderImpl(zones), network);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<Zone> zoneFilter;
if(drtCfg.operationalScheme == DrtConfigGroup.OperationalScheme.serviceAreaBased) {
List<PreparedGeometry> 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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9960d20

Please sign in to comment.