Skip to content

Commit

Permalink
refactor: remove unused destination filter (#1854)
Browse files Browse the repository at this point in the history
  • Loading branch information
aoles authored Oct 1, 2024
2 parents 3f2e4fc + c8ef81c commit 8ac9097
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 115 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SPTEntry> getMap() {
return fromMap;
}
}

public class HeavyVehicleEdgeFilter implements EdgeFilter {
private final int vehicleType;
private final boolean hasHazmat;
private final HeavyVehicleAttributesGraphStorage gsHeavyVehicles;
Expand All @@ -58,13 +35,6 @@ public IntObjectMap<SPTEntry> getMap() {
private final Integer[] indexValues;
private final Integer[] indexLocs;
private final int restCount;
private int mode = MODE_CLOSEST_EDGE;
private List<Integer> 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));
Expand Down Expand Up @@ -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<SPTEntry> destination = dijkstraAlg.getMap();

destinationEdges = new ArrayList<>(destination.size());
for (IntObjectCursor<SPTEntry> 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> motorVehicleRestrictions = new ArrayList<>(5);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

This file was deleted.

0 comments on commit 8ac9097

Please sign in to comment.