forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'transfer-cost-limit' into shared-stops
- Loading branch information
Showing
3 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/test/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/TransferTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.opentripplanner.routing.algorithm.raptoradapter.transit; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.opentripplanner.street.model._data.StreetModelForTest.intersectionVertex; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner._support.geometry.Coordinates; | ||
import org.opentripplanner.raptor.api.model.RaptorTransfer; | ||
import org.opentripplanner.routing.algorithm.raptoradapter.transit.cost.RaptorCostConverter; | ||
import org.opentripplanner.street.model._data.StreetModelForTest; | ||
import org.opentripplanner.street.model.vertex.IntersectionVertex; | ||
import org.opentripplanner.street.search.request.StreetSearchRequest; | ||
|
||
class TransferTest { | ||
|
||
private static final IntersectionVertex BERLIN_V = intersectionVertex(Coordinates.BERLIN); | ||
private static final IntersectionVertex BRANDENBURG_GATE_V = intersectionVertex( | ||
Coordinates.BERLIN_BRANDENBURG_GATE | ||
); | ||
private static final IntersectionVertex BOSTON_V = intersectionVertex(Coordinates.BOSTON); | ||
|
||
@Nested | ||
class WithEdges { | ||
|
||
@Test | ||
void limitMaxCost() { | ||
// very long edge from Berlin to Boston that has of course a huge cost to traverse | ||
var edge = StreetModelForTest.streetEdge(BERLIN_V, BOSTON_V); | ||
|
||
var veryLongTransfer = new Transfer(0, List.of(edge)); | ||
assertTrue(veryLongTransfer.getDistanceMeters() > 1_000_000); | ||
// cost would be too high, so it should not be included in RAPTOR search | ||
assertMaxCost(veryLongTransfer.asRaptorTransfer(StreetSearchRequest.of().build()).get()); | ||
} | ||
|
||
@Test | ||
void allowLowCost() { | ||
var edge = StreetModelForTest.streetEdge(BERLIN_V, BRANDENBURG_GATE_V); | ||
var transfer = new Transfer(0, List.of(edge)); | ||
assertTrue(transfer.getDistanceMeters() < 4000); | ||
final Optional<RaptorTransfer> raptorTransfer = transfer.asRaptorTransfer( | ||
StreetSearchRequest.of().build() | ||
); | ||
// cost is below max limit and should be included in RAPTOR | ||
assertBelowMaxCost(raptorTransfer.get()); | ||
} | ||
} | ||
|
||
@Nested | ||
class WithoutEdges { | ||
|
||
@Test | ||
void overflow() { | ||
var veryLongTransfer = new Transfer(0, Integer.MAX_VALUE); | ||
assertMaxCost(veryLongTransfer.asRaptorTransfer(StreetSearchRequest.of().build()).get()); | ||
} | ||
|
||
@Test | ||
void negativeCost() { | ||
var veryLongTransfer = new Transfer(0, -5); | ||
assertMaxCost(veryLongTransfer.asRaptorTransfer(StreetSearchRequest.of().build()).get()); | ||
} | ||
|
||
@Test | ||
void limitMaxCost() { | ||
var veryLongTransfer = new Transfer(0, 8_000_000); | ||
// cost would be too high, so it should not be included in RAPTOR search | ||
assertMaxCost(veryLongTransfer.asRaptorTransfer(StreetSearchRequest.of().build()).get()); | ||
} | ||
|
||
@Test | ||
void allowLowCost() { | ||
var transfer = new Transfer(0, 200); | ||
final Optional<RaptorTransfer> raptorTransfer = transfer.asRaptorTransfer( | ||
StreetSearchRequest.of().build() | ||
); | ||
// cost is below max limit and should be included in RAPTOR | ||
assertBelowMaxCost(raptorTransfer.get()); | ||
} | ||
} | ||
|
||
private static void assertMaxCost(RaptorTransfer transfer) { | ||
assertEquals( | ||
RaptorCostConverter.toRaptorCost(Transfer.MAX_TRANSFER_COST), | ||
transfer.generalizedCost() | ||
); | ||
} | ||
|
||
private static void assertBelowMaxCost(RaptorTransfer transfer) { | ||
assertTrue( | ||
RaptorCostConverter.toRaptorCost(Transfer.MAX_TRANSFER_COST) > transfer.generalizedCost() | ||
); | ||
} | ||
} |