|
| 1 | +package org.opentripplanner.raptor.moduletests; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.opentripplanner.raptor._data.transit.TestRoute.route; |
| 5 | +import static org.opentripplanner.raptor._data.transit.TestTripSchedule.schedule; |
| 6 | +import static org.opentripplanner.raptor.moduletests.support.RaptorModuleTestConfig.multiCriteria; |
| 7 | + |
| 8 | +import java.util.List; |
| 9 | +import org.junit.jupiter.api.BeforeEach; |
| 10 | +import org.junit.jupiter.params.ParameterizedTest; |
| 11 | +import org.junit.jupiter.params.provider.MethodSource; |
| 12 | +import org.opentripplanner.raptor.RaptorService; |
| 13 | +import org.opentripplanner.raptor._data.RaptorTestConstants; |
| 14 | +import org.opentripplanner.raptor._data.transit.TestAccessEgress; |
| 15 | +import org.opentripplanner.raptor._data.transit.TestTransitData; |
| 16 | +import org.opentripplanner.raptor._data.transit.TestTripSchedule; |
| 17 | +import org.opentripplanner.raptor.api.request.RaptorRequestBuilder; |
| 18 | +import org.opentripplanner.raptor.configure.RaptorConfig; |
| 19 | +import org.opentripplanner.raptor.moduletests.support.ModuleTestDebugLogging; |
| 20 | +import org.opentripplanner.raptor.moduletests.support.RaptorModuleTestCase; |
| 21 | + |
| 22 | +/** |
| 23 | + * FEATURE UNDER TEST |
| 24 | + * <p> |
| 25 | + * This verifies that the stopTransferCost is not applied for egress legs. If this is not correctly |
| 26 | + * handled by the heuristics optimization, the cheapest journey could be discarded. |
| 27 | + */ |
| 28 | +public class B05_EgressStopTransferCostTest implements RaptorTestConstants { |
| 29 | + |
| 30 | + private final TestTransitData data = new TestTransitData(); |
| 31 | + private final RaptorRequestBuilder<TestTripSchedule> requestBuilder = new RaptorRequestBuilder<>(); |
| 32 | + private final RaptorService<TestTripSchedule> raptorService = new RaptorService<>( |
| 33 | + RaptorConfig.defaultConfigForTest() |
| 34 | + ); |
| 35 | + |
| 36 | + @BeforeEach |
| 37 | + void setup() { |
| 38 | + data |
| 39 | + .withRoute(route("R1", STOP_B, STOP_C).withTimetable(schedule("0:10, 0:14"))) |
| 40 | + .withRoute(route("R2", STOP_C, STOP_D).withTimetable(schedule("0:18, 0:20"))); |
| 41 | + |
| 42 | + data.mcCostParamsBuilder().transferCost(0).boardCost(0); |
| 43 | + data.withStopBoardAlightCost(STOP_D, 60000); |
| 44 | + |
| 45 | + requestBuilder |
| 46 | + .searchParams() |
| 47 | + .addAccessPaths(TestAccessEgress.free(STOP_B)) |
| 48 | + .addEgressPaths( |
| 49 | + TestAccessEgress.walk(STOP_C, D5m), // This will be the fastest |
| 50 | + TestAccessEgress.walk(STOP_D, D20s) // This will be the cheapest |
| 51 | + ) |
| 52 | + .earliestDepartureTime(T00_00) |
| 53 | + .latestArrivalTime(T00_30); |
| 54 | + |
| 55 | + ModuleTestDebugLogging.setupDebugLogging(data, requestBuilder); |
| 56 | + } |
| 57 | + |
| 58 | + static List<RaptorModuleTestCase> testCases() { |
| 59 | + return RaptorModuleTestCase |
| 60 | + .of() |
| 61 | + .add( |
| 62 | + multiCriteria(), |
| 63 | + // We should get both the fastest and the c1-cheapest results |
| 64 | + // The stopTransferCost should not be applied to the egress leg from STOP_D |
| 65 | + "B ~ BUS R1 0:10 0:14 ~ C ~ Walk 5m [0:10 0:19 9m Tₓ0 C₁840]", |
| 66 | + "B ~ BUS R1 0:10 0:14 ~ C ~ BUS R2 0:18 0:20 ~ D ~ Walk 20s [0:10 0:20:20 10m20s Tₓ1 C₁640]" |
| 67 | + ) |
| 68 | + .build(); |
| 69 | + } |
| 70 | + |
| 71 | + @ParameterizedTest |
| 72 | + @MethodSource("testCases") |
| 73 | + void testRaptor(RaptorModuleTestCase testCase) { |
| 74 | + assertEquals(testCase.expected(), testCase.run(raptorService, data, requestBuilder)); |
| 75 | + } |
| 76 | +} |
0 commit comments