diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystemImpl.java b/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystemImpl.java index fdd34c24c79..a52c53af6e1 100644 --- a/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystemImpl.java +++ b/contribs/common/src/main/java/org/matsim/contrib/common/zones/ZoneSystemImpl.java @@ -1,19 +1,14 @@ package org.matsim.contrib.common.zones; import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.IdCollectors; import org.matsim.api.core.v01.IdMap; -import org.matsim.api.core.v01.Identifiable; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.network.Node; -import org.matsim.contrib.common.zones.util.NetworkWithZonesUtils; import org.matsim.contrib.common.zones.util.ZoneFinder; import javax.annotation.Nullable; import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; public class ZoneSystemImpl implements ZoneSystem { @@ -31,8 +26,8 @@ public ZoneSystemImpl(Collection zones) { public ZoneSystemImpl(Collection zones, ZoneFinder zoneFinder, Network network) { zones.forEach(zone -> this.zones.put(zone.getId(), zone)); - IdMap nodeToZoneMap = NetworkWithZonesUtils.createNodeToZoneMap(network, zoneFinder); - IdMap linkToZoneMap = NetworkWithZonesUtils.createLinkToZoneMap(network, zoneFinder); + IdMap nodeToZoneMap = ZoneSystemUtils.createNodeToZoneMap(network, zoneFinder); + IdMap linkToZoneMap = ZoneSystemUtils.createLinkToZoneMap(network, zoneFinder); this.nodeToZoneMap.putAll(nodeToZoneMap); this.link2zone.putAll(linkToZoneMap); 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 b1785497ff5..662c830dbd8 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 @@ -6,11 +6,14 @@ import org.locationtech.jts.geom.prep.PreparedPolygon; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.IdCollectors; +import org.matsim.api.core.v01.IdMap; import org.matsim.api.core.v01.Identifiable; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; +import org.matsim.api.core.v01.network.Node; import org.matsim.contrib.common.zones.io.ZoneShpReader; import org.matsim.contrib.common.zones.io.ZoneXmlReader; +import org.matsim.contrib.common.zones.util.ZoneFinder; import org.matsim.contrib.common.zones.util.ZoneFinderImpl; import org.matsim.core.utils.geometry.geotools.MGC; @@ -89,4 +92,20 @@ public static Map, Zone> readZones(URL zonesXmlUrl, URL zonesShpUrl) { shpReader.readZones(zonesShpUrl); return zones; } + + // if CRSs of the network and zones are different, zoneFinder should convert between CRSs + public static IdMap createLinkToZoneMap(Network network, ZoneFinder zoneFinder) { + return EntryStream.of(network.getLinks()) + .mapValues(link -> zoneFinder.findZone(link.getToNode().getCoord())) + .filterValues(Objects::nonNull) + .collect(IdCollectors.toIdMap(Link.class, Map.Entry::getKey, Map.Entry::getValue)); + } + + public static IdMap createNodeToZoneMap(Network network, ZoneFinder zoneFinder) { + return EntryStream.of(network.getNodes()) + .mapValues(node -> zoneFinder.findZone(node.getCoord())) + .filterValues(Objects::nonNull) + .collect(IdCollectors.toIdMap(Node.class, Map.Entry::getKey, Map.Entry::getValue)); + + } } diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/zones/util/NetworkWithZonesUtils.java b/contribs/common/src/main/java/org/matsim/contrib/common/zones/util/NetworkWithZonesUtils.java deleted file mode 100644 index a3d79ab1a1b..00000000000 --- a/contribs/common/src/main/java/org/matsim/contrib/common/zones/util/NetworkWithZonesUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2015 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.common.zones.util; - -import one.util.streamex.EntryStream; -import one.util.streamex.StreamEx; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.IdCollectors; -import org.matsim.api.core.v01.IdMap; -import org.matsim.api.core.v01.Identifiable; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.network.Node; -import org.matsim.contrib.common.zones.Zone; - -import java.util.Map; -import java.util.Objects; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class NetworkWithZonesUtils { - // if CRSs of the network and zones are different, zoneFinder should convert between CRSs - public static IdMap createLinkToZoneMap(Network network, ZoneFinder zoneFinder) { - return EntryStream.of(network.getLinks()) - .mapValues(link -> zoneFinder.findZone(link.getToNode().getCoord())) - .filterValues(Objects::nonNull) - .collect(IdCollectors.toIdMap(Link.class, Map.Entry::getKey, Map.Entry::getValue)); - } - - public static IdMap createNodeToZoneMap(Network network, ZoneFinder zoneFinder) { - return EntryStream.of(network.getNodes()) - .mapValues(node -> zoneFinder.findZone(node.getCoord())) - .filterValues(Objects::nonNull) - .collect(IdCollectors.toIdMap(Node.class, Map.Entry::getKey, Map.Entry::getValue)); - - } -} diff --git a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/optimizer/zonal/ZonalRequestInserter.java b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/optimizer/zonal/ZonalRequestInserter.java index 467b495b20f..cdba2fc9b00 100644 --- a/contribs/taxi/src/main/java/org/matsim/contrib/taxi/optimizer/zonal/ZonalRequestInserter.java +++ b/contribs/taxi/src/main/java/org/matsim/contrib/taxi/optimizer/zonal/ZonalRequestInserter.java @@ -42,7 +42,6 @@ import org.matsim.contrib.taxi.optimizer.rules.ZonalRegisters; import org.matsim.contrib.taxi.scheduler.TaxiScheduler; import org.matsim.contrib.zone.ZonalSystemParams; -import org.matsim.contrib.common.zones.util.NetworkWithZonesUtils; import org.matsim.contrib.common.zones.util.ZoneFinderImpl; import org.matsim.core.config.ConfigGroup; import org.matsim.core.mobsim.framework.MobsimTimer; @@ -78,7 +77,7 @@ public ZonalRequestInserter(Fleet fleet, TaxiScheduler scheduler, MobsimTimer ti ConfigGroup.getInputFileURL(context, zonalSystemParams.zonesShpFile)); // TODO No conversion of SRS is done - this.linkToZone = NetworkWithZonesUtils.createLinkToZoneMap(network, new ZoneFinderImpl(zones, zonalSystemParams.expansionDistance)); + this.linkToZone = ZoneSystemUtils.createLinkToZoneMap(network, new ZoneFinderImpl(zones, zonalSystemParams.expansionDistance)); // FIXME zonal system used in RuleBasedTaxiOptim (for registers) should be equivalent to // the zones used in ZonalTaxiOptim (for dispatching)