From 2a6bc4dfb212fcdb21c0ce6561ff65743531b321 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Thu, 16 Nov 2023 23:08:51 +0100 Subject: [PATCH] Also check for overflow --- .../algorithm/raptoradapter/transit/Transfer.java | 7 ++++--- .../raptoradapter/transit/TransferTest.java | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/Transfer.java b/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/Transfer.java index 743b7552c6e..72b0c9fe73b 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/Transfer.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/Transfer.java @@ -17,7 +17,7 @@ public class Transfer { /** - * Since transfers costs are not computed through a full A* with pruning they can incur an + * Since transfer costs are not computed through a full A* with pruning they can incur an * absurdly high cost that overflows the integer cost inside RAPTOR * (https://github.com/opentripplanner/OpenTripPlanner/issues/5509). *

@@ -31,8 +31,8 @@ public class Transfer { *

* The unit is in RAPTOR cost, so it's centiseconds. * - * @see RaptorCostConverter * @see EdgeTraverser + * @see RaptorCostConverter */ private static final int MAX_TRANSFER_RAPTOR_COST = Integer.MAX_VALUE / 30; @@ -80,7 +80,8 @@ public List getEdges() { } public Optional asRaptorTransfer(StreetSearchRequest request) { - return toRaptor(request).filter(s -> s.generalizedCost() < MAX_TRANSFER_RAPTOR_COST); + return toRaptor(request) + .filter(s -> s.generalizedCost() < MAX_TRANSFER_RAPTOR_COST && s.generalizedCost() >= 0); } private Optional toRaptor(StreetSearchRequest request) { diff --git a/src/test/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/TransferTest.java b/src/test/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/TransferTest.java index 204cae8eac6..59f419bf589 100644 --- a/src/test/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/TransferTest.java +++ b/src/test/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/TransferTest.java @@ -53,6 +53,18 @@ void allowLowCost() { @Nested class WithoutEdges { + @Test + void overflow() { + var veryLongTransfer = new Transfer(0, Integer.MAX_VALUE); + assertTrue(veryLongTransfer.asRaptorTransfer(StreetSearchRequest.of().build()).isEmpty()); + } + + @Test + void negativeCost() { + var veryLongTransfer = new Transfer(0, -5); + assertTrue(veryLongTransfer.asRaptorTransfer(StreetSearchRequest.of().build()).isEmpty()); + } + @Test void limitMaxCost() { var veryLongTransfer = new Transfer(0, 800_000);