From c8ef81c9c77d7625a053884102a81fc2c0b9ce0f Mon Sep 17 00:00:00 2001 From: aoles Date: Mon, 30 Sep 2024 16:14:01 +0200 Subject: [PATCH] refactor: remove unused access destination logic from hgv edge filter --- CHANGELOG.md | 1 + .../edgefilters/HeavyVehicleEdgeFilter.java | 99 +------------------ .../HeavyVehicleAttributesGraphStorage.java | 10 +- .../HeavyVehicleGraphStorageBuilder.java | 4 +- .../util/DestinationDependentEdgeFilter.java | 11 --- 5 files changed, 10 insertions(+), 115 deletions(-) delete mode 100644 ors-engine/src/main/java/org/heigit/ors/routing/util/DestinationDependentEdgeFilter.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 4faaa1a9e1..898853f538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ RELEASING: ### Changed - refactor: cleanup routing profile management ([#1850](https://github.com/GIScience/openrouteservice/pull/1850) - improved documentation on the configuration of external storages ([#1811](https://github.com/GIScience/openrouteservice/pull/1811))) +- refactor: remove unused access destination logic from hgv edge filter ([#1854](https://github.com/GIScience/openrouteservice/pull/1854)) ### Deprecated ### Removed ### Fixed diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/HeavyVehicleEdgeFilter.java b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/HeavyVehicleEdgeFilter.java index b6cf2a9dc6..5ed34471b7 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/HeavyVehicleEdgeFilter.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/edgefilters/HeavyVehicleEdgeFilter.java @@ -13,17 +13,8 @@ */ package org.heigit.ors.routing.graphhopper.extensions.edgefilters; -import com.carrotsearch.hppc.IntObjectMap; -import com.carrotsearch.hppc.cursors.IntObjectCursor; -import com.graphhopper.routing.Dijkstra; -import com.graphhopper.routing.SPTEntry; import com.graphhopper.routing.querygraph.EdgeIteratorStateHelper; import com.graphhopper.routing.util.EdgeFilter; -import com.graphhopper.routing.util.FlagEncoder; -import com.graphhopper.routing.util.TraversalMode; -import com.graphhopper.routing.weighting.FastestWeighting; -import com.graphhopper.routing.weighting.Weighting; -import com.graphhopper.storage.Graph; import com.graphhopper.storage.GraphHopperStorage; import com.graphhopper.util.EdgeIteratorState; import org.heigit.ors.routing.graphhopper.extensions.HeavyVehicleAttributes; @@ -32,24 +23,10 @@ import org.heigit.ors.routing.graphhopper.extensions.storages.GraphStorageUtils; import org.heigit.ors.routing.graphhopper.extensions.storages.HeavyVehicleAttributesGraphStorage; import org.heigit.ors.routing.parameters.VehicleParameters; -import org.heigit.ors.routing.util.DestinationDependentEdgeFilter; import java.util.ArrayList; -import java.util.List; - -public class HeavyVehicleEdgeFilter implements DestinationDependentEdgeFilter { - - public static class CustomDijkstra extends Dijkstra { - CustomDijkstra(Graph g, Weighting weighting, TraversalMode tMode) { - super(g, weighting, tMode); - initCollections(1000); - } - - public IntObjectMap getMap() { - return fromMap; - } - } +public class HeavyVehicleEdgeFilter implements EdgeFilter { private final int vehicleType; private final boolean hasHazmat; private final HeavyVehicleAttributesGraphStorage gsHeavyVehicles; @@ -58,13 +35,6 @@ public IntObjectMap getMap() { private final Integer[] indexValues; private final Integer[] indexLocs; private final int restCount; - private int mode = MODE_CLOSEST_EDGE; - private List destinationEdges; - private final byte[] buffer; - - private static final int MODE_DESTINATION_EDGES = -1; - private static final int MODE_CLOSEST_EDGE = -2; - private static final int MODE_ROUTE = 0; public HeavyVehicleEdgeFilter(int vehicleType, VehicleParameters vehicleParams, GraphHopperStorage graphStorage) { this(vehicleType, vehicleParams, GraphStorageUtils.getGraphExtension(graphStorage, HeavyVehicleAttributesGraphStorage.class)); @@ -104,80 +74,19 @@ public HeavyVehicleEdgeFilter(int vehicleType, VehicleParameters vehicleParams, this.restCount = indexValues.length; this.vehicleType = vehicleType; - this.buffer = new byte[2]; this.gsHeavyVehicles = hgvStorage; } - public void setDestinationEdge(EdgeIteratorState edge, Graph graph, FlagEncoder encoder, TraversalMode tMode) { - if (edge != null) { - int nodeId = edge.getBaseNode(); - if (nodeId != -1) { - mode = MODE_DESTINATION_EDGES; - Weighting weighting = new FastestWeighting(encoder); - CustomDijkstra dijkstraAlg = new CustomDijkstra(graph, weighting, tMode); - EdgeFilter edgeFilter = this; - dijkstraAlg.setEdgeFilter(edgeFilter); - dijkstraAlg.calcPath(nodeId, Integer.MIN_VALUE); - - IntObjectMap destination = dijkstraAlg.getMap(); - - destinationEdges = new ArrayList<>(destination.size()); - for (IntObjectCursor ee : destination) { - if (!destinationEdges.contains(ee.value.edge)) // was originalEdge - destinationEdges.add(ee.value.edge); - } - - if (!destinationEdges.contains(EdgeIteratorStateHelper.getOriginalEdge(edge))) { - int vt = gsHeavyVehicles.getEdgeVehicleType(EdgeIteratorStateHelper.getOriginalEdge(edge), buffer); - boolean dstFlag = buffer[1] != 0; - - if (isVehicleType(vt, vehicleType) && (dstFlag)) - destinationEdges.add(EdgeIteratorStateHelper.getOriginalEdge(edge)); - } - - if (destinationEdges.isEmpty()) - destinationEdges = null; - } - } - mode = MODE_ROUTE; - } - @Override public boolean accept(EdgeIteratorState iter) { int edgeId = EdgeIteratorStateHelper.getOriginalEdge(iter); - int vt = gsHeavyVehicles.getEdgeVehicleType(edgeId, buffer); - boolean dstFlag = buffer[1] != 0; + int vt = gsHeavyVehicles.getEdgeVehicleType(edgeId); - // if edge has some restrictions - if (vt != HeavyVehicleAttributes.UNKNOWN) { - if (mode == MODE_CLOSEST_EDGE) { - // current vehicle type is not forbidden - boolean edgeRestricted = isVehicleType(vt, vehicleType); - if ((edgeRestricted || dstFlag) && buffer[1] != vehicleType) + // access restriction for to the given vehicle type + if (vt != HeavyVehicleAttributes.UNKNOWN && isVehicleType(vt, vehicleType)) { return false; - } else if (mode == MODE_DESTINATION_EDGES) { - // Here we are looking for all edges that have destination - return dstFlag && isVehicleType(vt, vehicleType); - } else { - // Check an edge with destination attribute - if (dstFlag) { - if (isVehicleType(vt, vehicleType)) { - if (destinationEdges != null) { - if (!destinationEdges.contains(edgeId)) - return false; - } else - return false; - } else - return false; - } else if (isVehicleType(vt, vehicleType)) - return false; - } - } else { - if (mode == MODE_DESTINATION_EDGES) { - return false; - } } if (hasHazmat && isVehicleType(vt, HeavyVehicleAttributes.HAZMAT)) { diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/HeavyVehicleAttributesGraphStorage.java b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/HeavyVehicleAttributesGraphStorage.java index 7007f3c0c7..b086329bd3 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/HeavyVehicleAttributesGraphStorage.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/HeavyVehicleAttributesGraphStorage.java @@ -92,14 +92,13 @@ private void ensureEdgesIndex(int edgeIndex) { orsEdges.ensureCapacity(((long) edgeIndex + 1) * edgeEntryBytes); } - public void setEdgeValue(int edgeId, int vehicleType, int heavyVehicleDestination, double[] restrictionValues) { + public void setEdgeValue(int edgeId, int vehicleType, double[] restrictionValues) { edgesCount++; ensureEdgesIndex(edgeId); long edgePointer = (long) edgeId * edgeEntryBytes; - byte[] byteValues = {(byte) vehicleType, (byte) heavyVehicleDestination}; - orsEdges.setBytes(edgePointer + efVehicleType, byteValues, 2); + orsEdges.setByte(edgePointer + efVehicleType, (byte) vehicleType); if (efRestrictions == -1) throw new IllegalStateException(MSG_EF_RESTRICTION_IS_NOT_SUPPORTED); @@ -133,11 +132,10 @@ public boolean getEdgeRestrictionValues(int edgeId, double[] retValues) { return true; } - public int getEdgeVehicleType(int edgeId, byte[] buffer) { + public int getEdgeVehicleType(int edgeId) { long edgeBase = (long) edgeId * edgeEntryBytes; - orsEdges.getBytes(edgeBase + efVehicleType, buffer, 1); - int result = buffer[0]; + int result = orsEdges.getByte(edgeBase + efVehicleType); if (result < 0) result = result & 0xFF; diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java index ddb15f8123..6f8e64bc60 100644 --- a/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java +++ b/ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/HeavyVehicleGraphStorageBuilder.java @@ -31,7 +31,6 @@ public class HeavyVehicleGraphStorageBuilder extends AbstractGraphStorageBuilder private boolean includeRestrictions = true; private HeavyVehicleAttributesGraphStorage storage; private int hgvType = 0; - private int hgvDestination = 0; private boolean hasRestrictionValues; private final double[] restrictionValues = new double[VehicleDimensionRestrictions.COUNT]; private final List motorVehicleRestrictions = new ArrayList<>(5); @@ -76,7 +75,6 @@ public GraphExtension init(GraphHopper graphhopper) throws Exception { public void processWay(ReaderWay way) { // reset values hgvType = 0; - hgvDestination = 0; if (hasRestrictionValues) { restrictionValues[0] = 0.0; @@ -193,7 +191,7 @@ public void processWay(ReaderWay way) { } public void processEdge(ReaderWay way, EdgeIteratorState edge) { - storage.setEdgeValue(edge.getEdge(), hgvType, hgvDestination, restrictionValues); + storage.setEdgeValue(edge.getEdge(), hgvType, restrictionValues); } private String getVehicleType(String key, String value) { diff --git a/ors-engine/src/main/java/org/heigit/ors/routing/util/DestinationDependentEdgeFilter.java b/ors-engine/src/main/java/org/heigit/ors/routing/util/DestinationDependentEdgeFilter.java deleted file mode 100644 index c51b681476..0000000000 --- a/ors-engine/src/main/java/org/heigit/ors/routing/util/DestinationDependentEdgeFilter.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.heigit.ors.routing.util; - -import com.graphhopper.routing.util.EdgeFilter; -import com.graphhopper.routing.util.FlagEncoder; -import com.graphhopper.routing.util.TraversalMode; -import com.graphhopper.storage.Graph; -import com.graphhopper.util.EdgeIteratorState; - -public interface DestinationDependentEdgeFilter extends EdgeFilter { - void setDestinationEdge(EdgeIteratorState edge, Graph graph, FlagEncoder encoder, TraversalMode tMode); -} \ No newline at end of file