diff --git a/.github/workflows/cd-release.yaml b/.github/workflows/disabled/cd-release.yaml similarity index 100% rename from .github/workflows/cd-release.yaml rename to .github/workflows/disabled/cd-release.yaml diff --git a/.github/workflows/cd-snapshot.yaml b/.github/workflows/disabled/cd-snapshot.yaml similarity index 100% rename from .github/workflows/cd-snapshot.yaml rename to .github/workflows/disabled/cd-snapshot.yaml diff --git a/core/src/main/java/com/graphhopper/routing/matrix/DistanceMatrix.java b/core/src/main/java/com/graphhopper/routing/matrix/DistanceMatrix.java index 1fe253f27cc..4a813050a78 100644 --- a/core/src/main/java/com/graphhopper/routing/matrix/DistanceMatrix.java +++ b/core/src/main/java/com/graphhopper/routing/matrix/DistanceMatrix.java @@ -20,6 +20,11 @@ public final class DistanceMatrix { public static final double DISTANCE_SNAP_ERROR_VALUE = 1e7; public static final long TIME_SNAP_ERROR_VALUE = 10000000; + /** Sentinel value (meters) returned when two snapped points have no route between them. */ + public static final double DISTANCE_NO_ROUTE_VALUE = (double) Integer.MAX_VALUE; + /** Sentinel value (milliseconds) returned when two snapped points have no route between them. */ + public static final long TIME_NO_ROUTE_VALUE = (long) Integer.MAX_VALUE; + private final int numberOfOrigins; private final int numberOfDestinations; @@ -52,6 +57,9 @@ public DistanceMatrix(int numberOfOrigins, int numberOfDestinations, IntArrayLis distances = new double[numberOfOrigins][numberOfDestinations]; times = new long[numberOfOrigins][numberOfDestinations]; + for (double[] row : distances) Arrays.fill(row, DISTANCE_NO_ROUTE_VALUE); + for (long[] row : times) Arrays.fill(row, TIME_NO_ROUTE_VALUE); + this.snapOriginsErrors = originsErrors; this.snapDestinationErrors = destinationsErros; diff --git a/core/src/test/java/com/graphhopper/GraphHopperMatrixTest.java b/core/src/test/java/com/graphhopper/GraphHopperMatrixTest.java index ebce47b225b..e48c0342c28 100644 --- a/core/src/test/java/com/graphhopper/GraphHopperMatrixTest.java +++ b/core/src/test/java/com/graphhopper/GraphHopperMatrixTest.java @@ -17,6 +17,7 @@ */ package com.graphhopper; +import com.carrotsearch.hppc.IntArrayList; import com.graphhopper.config.CHProfile; import com.graphhopper.config.Profile; import com.graphhopper.routing.MultiplePointsNotFoundException; @@ -38,7 +39,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.graphhopper.routing.matrix.DistanceMatrix.DISTANCE_NO_ROUTE_VALUE; import static com.graphhopper.routing.matrix.DistanceMatrix.DISTANCE_SNAP_ERROR_VALUE; +import static com.graphhopper.routing.matrix.DistanceMatrix.TIME_NO_ROUTE_VALUE; import static com.graphhopper.routing.matrix.DistanceMatrix.TIME_SNAP_ERROR_VALUE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -437,4 +440,19 @@ void testMatrixCarProfile(){ assertTrue(result.getTime(0, 0) == 530105); } + + @Test + void testNoRouteDefaultCellValue() { + IntArrayList noErrors = new IntArrayList(); + DistanceMatrix matrix = new DistanceMatrix(2, 2, noErrors, noErrors); + + // Cells never written by setCell must return the no-route sentinel + assertEquals(DISTANCE_NO_ROUTE_VALUE, matrix.getDistance(0, 1)); + assertEquals(TIME_NO_ROUTE_VALUE, matrix.getTime(0, 1)); + + // setCell must overwrite the sentinel with real values + matrix.setCell(0, 1, 1500.0, 90000L); + assertEquals(1500.0, matrix.getDistance(0, 1)); + assertEquals(90000L, matrix.getTime(0, 1)); + } }